🔧 Refactor: save test and code refactor #28
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: Build and Deploy Spring Boot to AWS EC2 | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
env: | |
PROJECT_NAME: streaming-service | |
BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET }} | |
CODE_DEPLOY_APP_NAME: ${{ secrets.AWS_CODE_DEPLOY_APP }} | |
DEPLOYMENT_GROUP_NAME: ${{ secrets.AWS_CODE_DEPLOY_GROUP }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
jobs: | |
build: | |
name: CI-CD | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout java with gradle | |
uses: actions/checkout@v2 | |
- name: Set up JDK 11 ver | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
# Gradle Cache | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
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: Build and Test | |
run: ./gradlew build -x test | |
- name: Make Zip File | |
run: zip -qq -r ./$GITHUB_SHA.zip . | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Upload to S3 | |
run: aws s3 cp --region ${{ env.AWS_REGION }} ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy To EC2 instance | |
run: aws deploy create-deployment | |
--application-name $CODE_DEPLOY_APP_NAME | |
--deployment-config-name CodeDeployDefault.AllAtOnce | |
--deployment-group-name $DEPLOYMENT_GROUP_NAME | |
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip |