rasPi .sh update #68
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: CI/CD | |
# 워크플로우가 시작될 조건 지정 | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
env: | |
KEY_DIR: src/main/resources | |
KEY_DIR_FILE_NAME: application-key.yml | |
AWS_REGION: ap-northeast-2 | |
S3_BUCKET_NAME: blog-deploy | |
CODE_DEPLOY_APPLICATION_NAME: spring-boot-3-blog-app | |
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: spring-boot-3-blog-deploy-group | |
# OIDC에 쓰이는 ID 토큰 발급을 위해 정의 | |
permissions: | |
id-token: write | |
contents: read # This is required for actions/checkout | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest # 실행 환경 지정 | |
# 실행 스탭 지정 | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
- name: Make Key yml file | |
run: | |
echo ${{ secrets.KEY_YML }} | base64 --decode > ${{ env.KEY_DIR }}/${{ env.KEY_DIR_FILE_NAME }} | |
- name: Setup MySQL | |
uses: mirromutth/[email protected] | |
with: | |
host port: 3306 | |
container port: 3306 | |
mysql database: 'blog' | |
mysql user: ${{ secrets.DB_USERNAME }} | |
mysql password: ${{ secrets.DB_PASSWORD }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
# 현재 시간 가져오기 | |
# - name: Get Current Time | |
# uses: josStorer/[email protected] | |
# id: current-time | |
# with: | |
# format: YYYY-MM-DDHH-mm-ss | |
# utcOffset: "+09:00" | |
# 배포용 패키지 경로 저장 | |
- name: Set JAR_FILE_NAME EV | |
run: echo "JAR_FILE_NAME=$(ls ./build/libs)" >> $GITHUB_ENV | |
# build한 파일 모두 압축 | |
- name: Make zip file | |
run: zip -r ./$GITHUB_SHA.zip . | |
# AWS OIDC | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
aws-region: ${{ env.AWS_REGION }} | |
# script files 복사 | |
# - name: Copy script | |
# run: cp ./scripts/*.sh ./deploy | |
- name: Upload to AWS S3 | |
run: aws s3 cp --region $AWS_REGION ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip | |
- 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 }} \ | |
--file-exists-behavior OVERWRITE \ | |
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip |