Merge pull request #26 from nunsongCookie/main #3
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Deploy WAS | |
on: | |
push: | |
branches: [ "develop" ] | |
pull_request: | |
branches: [ "develop" ] | |
env: | |
IMAGE_TAG: ${{ github.sha }} | |
AWS_REGION: ap-northeast-2 # set this to your preferred AWS region | |
ECR_REPOSITORY: ${{ secrets.ECR_REPO }} # set this to your Amazon ECR repository name | |
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET }} | |
CODE_DEPLOY_APPLICATION_NAME: ${{ secrets.CODE_DEPLOY_APPLICATION_NAME }} | |
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME : ${{ secrets.DEPLOYMENT_GROUP_NAME }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
# Gradlew 실행 허용 | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
# JDK 17 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# 환경 변수 설정 | |
- name: Make application.yml | |
run: | | |
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build | |
# AWS credentials | |
- name: AWS IAM 사용자 설정 | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.IAMARN }} | |
aws-region: ${{ env.AWS_REGION }} | |
# ECR login | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
# Docker build | |
- name: Docker build & push | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
#code deploy용 env file 생성 | |
- name: Create env file | |
run: | | |
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" > scripts/env.sh | |
echo "ECR_REPOSITORY=${{ secrets.ECR_REPO }}" >> scripts/env.sh | |
echo "IMAGE_TAG=${{ github.sha }}" >> scripts/env.sh | |
# S3에 스크립트 업로드(code deploy) | |
- name: upload to s3 | |
run: | | |
zip -r deploy-$IMAGE_TAG.zip ./scripts appspec.yml | |
aws s3 cp --region ap-northeast-2 --acl private ./deploy-$IMAGE_TAG.zip s3://$S3_BUCKET_NAME/$ECR_REPOSITORY | |
# Deploy | |
# S3에 업로드 했던 내용을 가지고 와서, code deploy 실행 | |
- name: Deploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | |
--s3-location bucket=$S3_BUCKET_NAME,key=$ECR_REPOSITORY/deploy-$IMAGE_TAG.zip,bundleType=zip |