Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEPLOY]: 운영 ECR 배포 23/12/18 #31

Merged
merged 7 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ECR-prd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Docker image push to AWS ECR

on:
pull_request:
types: [closed]
branches: [release]

jobs:
build:
name: Build image
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean :bootstrap:bootJar

- name: Config AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: notification-prd
IMAGE_TAG: latest
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
20 changes: 4 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
FROM openjdk:17.0-slim AS BUILDER
FROM openjdk:17.0-slim

RUN mkdir /app_source
COPY . /app_source

WORKDIR /app_source

RUN chmod +x ./gradlew
RUN ./gradlew :bootstrap:bootJar

FROM openjdk:17.0-slim AS RUNNER

RUN mkdir /app
COPY --from=BUILDER /app_source/bootstrap/build/libs /app

WORKDIR /app
WORKDIR build
COPY /bootstrap/build/libs/bootstrap-0.0.1-SNAPSHOT.jar app.jar

ENV TZ=Asia/Seoul

EXPOSE 8080

ENTRYPOINT java -jar /app/*.jar
ENTRYPOINT java -jar app.jar
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,47 @@ import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
import com.amazonaws.services.dynamodbv2.datamodeling.ConversionSchemas
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverterFactory
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary

@Configuration
@EnableDynamoDBRepositories(basePackages = ["gloddy.dynamodb.notification", "gloddy.dynamodb.fcmToken"])
@EnableDynamoDBRepositories(basePackages = ["gloddy.dynamodb.notification", "gloddy.dynamodb.fcmToken"], dynamoDBMapperConfigRef = "dynamoDBMapperConfig")
class DynamoDBConfig(
@Value("\${amazon.dynamodb.endpoint}") private val endpoint: String,
@Value("\${amazon.aws.accessKey}") private val accessKey: String,
@Value("\${amazon.aws.secretKey}") private val secretKey: String,
@Value("\${amazon.aws.region}") private val region: String
@Value("\${amazon.aws.region}") private val region: String,
@Value("\${stage}") private val stage: String
) {

@Primary
@Bean
fun dynamoDBMapper(amazonDynamoDB: AmazonDynamoDB): DynamoDBMapper {
return DynamoDBMapper(amazonDynamoDB, DynamoDBMapperConfig.DEFAULT)
return DynamoDBMapper(
amazonDynamoDB,
dynamoDBMapperConfig()
)
}

@Bean
fun dynamoDBMapperConfig(): DynamoDBMapperConfig {
return DynamoDBMapperConfig.builder()
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.UPDATE)
.withConsistentReads(DynamoDBMapperConfig.ConsistentReads.EVENTUAL)
.withPaginationLoadingStrategy(DynamoDBMapperConfig.PaginationLoadingStrategy.LAZY_LOADING)
.withTableNameResolver(tableNameResolver())
.withBatchWriteRetryStrategy(DynamoDBMapperConfig.DefaultBatchWriteRetryStrategy.INSTANCE)
.withBatchLoadRetryStrategy(DynamoDBMapperConfig.DefaultBatchLoadRetryStrategy.INSTANCE)
.withTypeConverterFactory(DynamoDBTypeConverterFactory.standard())
.withConversionSchema(ConversionSchemas.V2_COMPATIBLE)
.build()
}

@Bean
Expand All @@ -41,4 +61,8 @@ class DynamoDBConfig(

@Bean
fun awsCredentials() = BasicAWSCredentials(accessKey, secretKey)

@Bean
@Primary
fun tableNameResolver() = TableNameResolver(stage)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gloddy.dynamodb.config

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable

class TableNameResolver(
private val stage: String
) : DynamoDBMapperConfig.TableNameResolver {

companion object {
const val STG: String = "stg"
const val PRD: String = "prd"
}

override fun getTableName(clazz: Class<*>?, config: DynamoDBMapperConfig?): String {

val tableNameOverride = config?.tableNameOverride
if (tableNameOverride != null) {
val tableName = tableNameOverride.tableName
if (tableName != null)
return tableName
}

val rawTableName = clazz?.getAnnotation(DynamoDBTable::class.java)?.tableName
?: throw DynamoDBMappingException("$clazz not annotated with @DynamoDBTable")

return when (stage) {
STG -> rawTableName
PRD -> "${rawTableName}_$stage"
else -> throw RuntimeException("Invalid stage: $stage")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
stage: ${DYNAMODB_STAGE}

amazon:
dynamodb:
endpoint: ${DYNAMODB_END_POINT}
Expand Down
Loading