Update deploy.sh #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
# 워크플로우의 이름 지정 | |
name: CD | |
# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 | |
on: | |
push: | |
branches: [ main ] # main branch로 push 될 때 실행됩니다. | |
env: | |
S3_BUCKET_NAME: now-sopt-nykoh | |
jobs: | |
build: | |
name: Code deployment | |
# 실행 환경 | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: make application.yml | |
run: | | |
## create application.yml | |
mkdir ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.CD_APPLICATION }}" >> ./application.yml | |
cat ./application.yml | |
shell: bash | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) | |
run: ./gradlew build -x test | |
- name: Make Directory | |
run: mkdir -p deploy | |
- name: Copy Jar | |
run: cp ./build/libs/*.jar ./deploy | |
- name: Copy appspec.yml | |
run: cp appspec.yml ./deploy | |
- name: Copy script | |
run: cp ./scripts/*.sh ./deploy | |
- name: Make zip file | |
run: zip -r ./now-sopt.zip ./deploy | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./now-sopt.zip s3://$S3_BUCKET_NAME/ | |
- name: Deploy | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} | |
run: | |
aws deploy create-deployment | |
--application-name now-sopt-deploy | |
--deployment-group-name now-sopt-deploy | |
--file-exists-behavior OVERWRITE | |
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=now-sopt.zip | |
--region ap-northeast-2 |