Merge pull request #13 from team-nabi/NABI-111--beommo--refactor--cod… #7
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: CICD | |
# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 | |
on: | |
push: | |
branches: [ "main" ] # master branch로 push 될 때 실행 | |
pull_request: | |
branches: [ "main" ] # master branch로 pull request될 때 실행 | |
# workflow는 한개 이상의 job을 가지며, 각 job은 여러 step에 따라 단계를 나눌 수 있음 | |
jobs: | |
build: | |
name: CI | |
# 해당 jobs에서 아래의 steps들이 어떠한 환경에서 실행될 것인지를 지정 | |
runs-on: ubuntu-20.04 | |
# 해당 yml 내에서 사용할 key - value | |
env: | |
S3_BUCKET_NAME: team-01-bucket | |
PROJECT_NAME: cicd | |
steps: | |
# 작업에서 액세스할 수 있도록 $GITHUB_WORKSPACE에서 저장소를 체크아웃 | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'oracle' | |
java-version: '17' | |
# application.properties를 프로젝트에 포함 | |
- name: add Application.yml | |
run: touch ./src/main/resources/application.yml | |
shell: bash | |
- name: copy Application.yml | |
run: | |
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml | |
shell: bash | |
# gradle 권한 설정 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Test with Gradle | |
run: ./gradlew test | |
# 빌드 | |
- name: Build with Gradle | |
run: ./gradlew build | |
shell: bash | |
# gradle 권한 설정 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Make zip file | |
run: zip -r ./$GITHUB_SHA.zip . | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
# script files 복사 | |
- name: Copy script | |
run: cp ./scripts/*.sh ./deploy | |
# S3에 빌드 결과 업로드 | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip | |
# Deploy 실행 | |
- name: Deploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name today-deploy \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name today-deploy-group \ | |
--file-exists-behavior OVERWRITE \ | |
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip \ | |
--region ap-northeast-2 \ |