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
name: Build and Deploy Spring Boot to AWS EC2 | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- main | |
env: | |
PROJECT_NAME: Yeungnam-Nyang-BE2 | |
BUCKET_NAME: ynn-cicd-bucket | |
CODE_DEPLOY_APP_NAME: ynn_cicd | |
DEPLOYMENT_GROUP_NAME: YNN-Server | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# (1) GitHub Actions 체크아웃 | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: make application-secret.properties | |
run: | | |
cd ./src/main/resources | |
touch ./application-secret.properties | |
echo "${{ secrets.SECURITY_PROPERTIES }}" > ./application-secret.properties | |
shell: bash | |
# (2) JDK 설치 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'corretto' | |
- name: Permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build Application | |
run: ./gradlew build -x test | |
- name: Make Zip File | |
run: zip -qq -r ./$GITHUB_SHA.zip . | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy To EC2 instance | |
run: aws deploy create-deployment | |
--application-name $CODE_DEPLOY_APP_NAME | |
--deployment-config-name CodeDeployDefault.AllAtOnce | |
--deployment-group-name $DEPLOYMENT_GROUP_NAME | |
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip | |
# --------------------------추가 |