github-action-alarm-cd #2
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
# workflow의 이름 | |
name: github-action-alarm-cd | |
# 해당 workflow가 언제 실행될 것인지에 대한 트리거 지정 | |
# workflow 수동 실행 | |
on: | |
workflow_dispatch: | |
inputs: | |
name: | |
description: 'CD를 수행하기 위하여 승인을 해주세요.' | |
required: true | |
default: 'CD를 수행하기 위한 Github Action 입니다.' | |
# 해당 yml 내에서 사용할 key - value | |
env: | |
PROJECT_NAME: alarm | |
# workflow는 한개 이상의 job을 가지며, 각 job은 여러 step에 따라 단계를 나눌 수 있습니다. | |
jobs: | |
build: | |
name: github-action-owner-cd | |
runs-on: ubuntu-latest | |
steps: | |
# 작업에서 액세스 할 수 있도록 저장소를 체크아웃 해줌. | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
# ./gradlew 명령어를 수행 할 수 있도록 실행 권한 부여 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
# ./gradlew build 수행 | |
- name: Build with Gradle | |
run: ./gradlew :alarm:clean :alarm:build | |
shell: bash | |
# user의 jar 파일과 appspec을압축 | |
- name: Make zip file | |
run: | | |
files_to_compress="alarm/build/libs/* appspec.yml scripts/deploy.sh" | |
archive_name="$GITHUB_SHA.zip" | |
zip -r "$archive_name" $files_to_compress | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-action/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} | |
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} | |
aws-region: ${{secrets.AWS_REGION}} | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{secrets.S3_BUCKET_NAME}}/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{secrets.CODE_DEPLOY_NAME}} \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--deployment-group-name ${{secrets.CODE_DEPLOY_GROUP_ALARM}} \ | |
--file-exists-behavior OVERWRITE \ | |
--s3-location bucket=${{secrets.S3_BUCKET_NAME}},bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip \ | |
--region ${{secrets.AWS_REGION}} |