Skip to content

Merge pull request #35 from EnergyChaCha/develop #40

Merge pull request #35 from EnergyChaCha/develop

Merge pull request #35 from EnergyChaCha/develop #40

Workflow file for this run

name: deploy
on:
push:
branches:
- main
# pull_request:
# branches:
# - main
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
required: false
env:
S3_BUCKET_NAME: energy-springboot-deploy
CODE_DEPLOY_APPLICATION_NAME: energy-springboot-deploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: energy-springboot-prod
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: πŸš€ μ €μž₯μ†Œ Checkout
uses: actions/checkout@v3
- name: πŸš€ Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- 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: πŸš€ Print GitHub Ref
run: |
echo "GitHub Ref: ${{ github.ref }}"
- name: πŸš€ Make application-secrets.properties
run: |
cd ./Backend/src/main/resources
touch ./application-secrets.properties
echo "${{ secrets.APPLICATION_SECRETS }}" > ./application-secrets.properties
# 파일 μ—†μœΌλ©΄ λΉŒλ“œ μ—λŸ¬
- uses: actions/upload-artifact@v3
with:
name: application-secrets.properties
path: ./Backend/src/main/resources/application-secrets.properties
if-no-files-found: 'error'
- name: πŸš€ Grant execute permission for gradlew
run: chmod +x ./Backend/gradlew
- name: πŸš€ Build with Gradle
run: |
cd ./Backend
./gradlew clean build -x test
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.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: πŸš€ Upload to AWS S3
run: |
cd ./Backend
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/build/$GITHUB_SHA.zip \
--source .
# S3 버킷에 μžˆλŠ” νŒŒμΌμ„ λŒ€μƒμœΌλ‘œ CodeDeploy μ‹€ν–‰
- name: πŸš€ Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=build/$GITHUB_SHA.zip,bundleType=zip