-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: prod-cd | ||
|
||
on: | ||
push: | ||
branches: | ||
- prod | ||
- feat/prod-cd | ||
- feat/prod-cd-test | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 # set this to your preferred AWS region, e.g. us-west-1 | ||
ECR_REPOSITORY: showpot-application | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'liberica' | ||
cache: gradle | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v3 | ||
|
||
- name: Copy Secrets | ||
uses: microsoft/variable-substitution@v1 | ||
with: | ||
files: './app/src/main/resources/application-prod.yml, ./app/src/main/resources/application-cloud-prod.yml, ./app/domain/common-domain/src/main/resources/application-domain-prod.yml' | ||
env: | ||
token.secret-key: ${{ secrets.TOKEN_SECRET_KEY }} | ||
cloud.aws.credentials.accessKey: ${{ secrets.AWS_ACCESS_KEY }} | ||
cloud.aws.credentials.secretKey: ${{ secrets.AWS_SECRET_KEY }} | ||
cloud.aws.region: ${{ secrets.AWS_REGION }} | ||
cloud.aws.s3.bucket: ${{ secrets.AWS_BUCKET }} | ||
spring.datasource.url: ${{ secrets.APPLICATION_DATASOURCE_URL_PROD }} | ||
spring.datasource.username: ${{ secrets.APPLICATION_DATASOURCE_USERNAME }} | ||
spring.datasource.password: ${{ secrets.APPLICATION_DATASOURCE_PASSWORD }} | ||
spring.data.redis.host: ${{ secrets.REDIS_HOST_PROD }} | ||
spring.data.redis.port: ${{ secrets.REDIS_PORT_PROD }} | ||
|
||
- name: Build with Gradle Wrapper | ||
run: ./gradlew clean build -Dspring.profiles.active=prod | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Set image tag | ||
id: set-tag | ||
run: | | ||
DATE_TAG=$(TZ='Asia/Seoul' date +'%Y%m%d_%H%M') | ||
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-8) | ||
echo "IMAGE_TAG=${DATE_TAG}_${SHORT_SHA}" >> $GITHUB_ENV | ||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build and Push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ env.IMAGE_TAG }} | ||
run: | | ||
docker build --no-cache -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f dockerfile-prod . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
# - name: Fill in the new image ID in the Amazon ECS task definition | ||
# id: task-def | ||
# uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
# with: | ||
# task-definition: ${{ env.ECS_TASK_DEFINITION }} | ||
# container-name: ${{ env.CONTAINER_NAME }} | ||
# image: ${{ steps.build-image.outputs.image }} | ||
|
||
# - name: Deploy Amazon ECS task definition | ||
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
# with: | ||
# task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
# service: ${{ env.ECS_SERVICE }} | ||
# cluster: ${{ env.ECS_CLUSTER }} | ||
# wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters