deploy production by tag #55
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: deploy production by tag | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: '배포할 Version Tag' | |
required: true | |
type: string | |
permissions: | |
contents: read | |
jobs: | |
build-backend: | |
runs-on: ubuntu-22.04 | |
defaults: | |
run: | |
working-directory: backend | |
steps: | |
- name: Set up Repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.version }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: Give permission for Gradle | |
run: chmod +x gradlew | |
- name: Cache Gradle | |
id: cache-gradle | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Upload jar file artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: BackendApplicationJar | |
path: backend/build/libs/*.jar | |
build-frontend: | |
runs-on: ubuntu-22.04 | |
defaults: | |
run: | |
working-directory: frontend | |
steps: | |
- name: Set up Repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.version }} | |
- name: Setup node with cache | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
cache-dependency-path: '**/package-lock.json' | |
- name: Setup environment variables | |
run: | | |
echo "REACT_APP_BASE_URL=${{ secrets.REACT_APP_PROD_BASE_URL }}" >> .env | |
- name: Install dependencies | |
run: npm ci | |
- name: Build App | |
run: npm run build:prod | |
- name: Upload frontend build file to artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: FrontendApplication | |
path: frontend/dist | |
deploy: | |
needs: [build-frontend, build-backend] | |
runs-on: self-hosted | |
env: | |
BACK_PROD_PROPERTY: ${{ secrets.PROD_BACK_PROPERTY }} | |
BACK_DEPLOY_SCRIPT: ${{ secrets.PROD_BACK_DEPLOY_SCRIPT }} | |
CLOUD_FRONT_DISTRIBUTION_ID: ${{ secrets.CLOUD_FRONT_PROD_DISTRIBUTION_ID}} | |
steps: | |
- name: Remove previous version FRONT app | |
working-directory: frontend/prod/ | |
run: rm -rf dist | |
- name: Download FRONT build file from artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: FrontendApplication | |
path: frontend/prod/dist | |
- name: Remove previous version BACK jar | |
working-directory: backend/prod/ | |
run: rm -f team-by-team-*.jar | |
- name: Download BACK jar file from artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: BackendApplicationJar | |
path: backend/prod/ | |
- name : Make BACK prod application.yml | |
working-directory: backend/prod/ | |
run: echo "$BACK_PROD_PROPERTY" > application-prod.yml | |
- name: Deploy BACK to production server | |
working-directory: backend/prod/ | |
run: | | |
echo "$BACK_DEPLOY_SCRIPT" > prod-deploy.sh | |
chmod 700 prod-deploy.sh | |
./prod-deploy.sh | |
- name: Deploy FRONT to production server | |
working-directory: frontend/prod/ | |
run: | | |
aws s3 sync ./dist/ s3://team-by-team-static-resource/prod/front --delete | |
aws cloudfront create-invalidation --distribution-id "$CLOUD_FRONT_DISTRIBUTION_ID" --paths "/*" | |