Merge pull request #75 from sw-security-web-app/SCRUM-83 #37
This file contains hidden or 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 to EC2 | |
on: | |
push: | |
branches: [ "main" ] | |
env: | |
AWS_REGION: ap-northeast-2 | |
BUCKET_NAME: vero-cicd-bucket | |
CODE_DEPLOY_APP_NAME: vero_cicd | |
DEPLOYMENT_GROUP_NAME: vero_instance | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: make application-secret.yml | |
run: | | |
mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
echo "${{ secrets.YML_SECRET }}" | base64 --decode > ./application-secret.yml | |
cat ./application-secret.yml | |
chmod 644 ./application-secret.yml | |
pwd | |
shell: bash | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build and Test | |
run: ./gradlew clean build -x test | |
- name: Make Zip File | |
run: | | |
mkdir ./build/zip | |
cp appspec.yml ./build/zip/ | |
cp -r scripts ./build/zip/ | |
zip -qq -r ./build/zip/$GITHUB_SHA.zip . | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Upload to AWS S3 | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.CODE_DEPLOY_APP_NAME }} \ | |
--ignore-hidden-files \ | |
--s3-location s3://$BUCKET_NAME/$GITHUB_SHA.zip \ | |
--source ./build/zip | |
- name: Deploy to AWS EC2 from S3 | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODE_DEPLOY_APP_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ env.DEPLOYMENT_GROUP_NAME }} \ | |
--s3-location bucket=$BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip |