Execute Manual CD #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: Execute Manual CD | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
env: | |
BUCKET_NAME: space-club-be-bucket | |
DIRECTORY_NAME: space-club-be-directory | |
CODE_DEPLOY_APP_NAME: space-club-be-deploy | |
DEPLOYMENT_GROUP_NAME: space-club-be-deploy-group | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Repo code With Submodules | |
uses: actions/checkout@v3 | |
with: | |
submodules: 'true' | |
token: ${{secrets.GH_ACCESS_TOKEN}} | |
- name: Set encrypt Secret key | |
run: echo ${{ secrets.encrypt }} > scripts/properties.sh | |
shell: bash | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache Gradle packages # gradle cache를 통한 workflow 속도 개선 | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Gradle Build Action | |
run: ./gradlew bootJar | |
- name: Make Zip File # appspec.yml, scripts 폴더, jar 파일만 압축 | |
run: zip -qq -r ./$GITHUB_SHA.zip ./appspec.yml ./scripts/ ${{ env.JAR_PATH }} | |
shell: bash | |
env: | |
JAR_PATH: ./build/libs/*SNAPSHOT.jar | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-access-key-id: ${{ secrets.ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.PRIVATE_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$DIRECTORY_NAME/$GITHUB_SHA.zip | |
- name: Deploy to EC2 Instance | |
run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-group-name $DEPLOYMENT_GROUP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$DIRECTORY_NAME/$GITHUB_SHA.zip |