Merge pull request #394 from GSM-MSG/develop #25
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: sms-production-CD | |
on: | |
push: | |
branches: [ "master" ] | |
jobs: | |
cd: | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: SMS-Backend-CD Discord Notification | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
title: ℹ️ SMS-Backend-CD 시작! ℹ️ | |
webhook: ${{ secrets.SMS_DISCORD_WEBHOOK }} | |
color: 00FF00 | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
cache: gradle | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v2 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Create application.yml | |
run: | | |
touch ./sms-infrastructure/src/main/resources/application.yml | |
echo "${{ secrets.SMS_BACKEND_ENV }}" > ./sms-infrastructure/src/main/resources/application.yml | |
shell: bash | |
- name: Run build with Gradle wrapper | |
run: ./gradlew clean build | |
- 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: ap-northeast-2 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
run: | | |
docker build -t ${{ secrets.ECR_REPOSITORY }}:${{ secrets.IMAGE_TAG }} . | |
docker tag ${{ secrets.ECR_REPOSITORY }}:${{ secrets.IMAGE_TAG }} ${{ secrets.REPO_URL }}:${{ secrets.IMAGE_TAG }} | |
docker push ${{ secrets.REPO_URL }}:${{ secrets.IMAGE_TAG }} | |
- name: Execute remote SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.REMOTE_SSH_HOST }} | |
username: ${{ secrets.REMOTE_SSH_USERNAME }} | |
key: ${{ secrets.REMOTE_SSH_KEY }} | |
port: ${{ secrets.REMOTE_SSH_PORT }} | |
script: | | |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{secrets.ECR_REPO_PATH}} | |
docker pull ${{ secrets.REPO_URL }}:${{ secrets.IMAGE_TAG }} | |
docker compose restart | |
- name: SMS-Backend-CD Discord Notification (Success) | |
uses: sarisia/actions-status-discord@v1 | |
if: success() | |
with: | |
title: ✅ SMS-Backend-CD 성공! ✅ | |
webhook: ${{ secrets.SMS_DISCORD_WEBHOOK }} | |
status: ${{ job.status }} | |
image: ${{ secrets.CD_SUCCESS_IMAGE }} | |
description: 프로덕션 CD 성공 | |
color: 00FF00 | |
username: SMS CD 봇 | |
url: https://github.com/GSM-MSG/SMS-BackEnd | |
- name: SMS-Backend-CD Discord Notification (Failure) | |
uses: sarisia/actions-status-discord@v1 | |
if: failure() | |
with: | |
title: ❗️ SMS-Backend-CD 실패! ❗️ | |
webhook: ${{ secrets.SMS_DISCORD_WEBHOOK }} | |
status: ${{ job.status }} | |
image: ${{ secrets.CD_FAIL_IMAGE }} | |
description: 무례하긴, 실패다. | |
color: FF0000 | |
username: SMS CD 봇 | |
url: https://github.com/GSM-MSG/SMS-BackEnd |