Skip to content

๐Ÿ”จrefactor: ์ด๋ฉ”์ผ ์ธ์ฆ์„œ๋น„์Šค ์ˆ˜์ • #88

๐Ÿ”จrefactor: ์ด๋ฉ”์ผ ์ธ์ฆ์„œ๋น„์Šค ์ˆ˜์ •

๐Ÿ”จrefactor: ์ด๋ฉ”์ผ ์ธ์ฆ์„œ๋น„์Šค ์ˆ˜์ • #88

Workflow file for this run

name: dev - CI/CD to Amazon ECS
on:
push:
branches: [ "dev" ]
permissions:
contents: read
checks: write
issues: write
jobs:
build:
runs-on: ubuntu-latest
environment: dev
if: github.event_name == 'push'
env: # Vault ๊ฐ’๋“ค์„ ์ „์—ญ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์„ค์ •
VAULT_URI: ${{ secrets.VAULT_URI }}
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
VAULT_BACKEND: ${{ secrets.VAULT_BACKEND }}
VAULT_DEFAULT_CONTEXT: ${{ secrets.VAULT_DEFAULT_CONTEXT }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- 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: Grant Execute Permission For Gradlew
run: chmod +x gradlew
- name: Build With Gradle
run: ./gradlew build -x test --info
- name: List All Files for Debugging
run: ls -laR # ๋ชจ๋“  ๋””๋ ‰ํ† ๋ฆฌ์˜ ํŒŒ์ผ ๋‚˜์—ด
- name: Upload JAR Artifact
uses: actions/upload-artifact@v3
with:
name: jar-file
path: build/libs/Chekirout-0.0.1-SNAPSHOT.jar
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: dev
if: github.event_name == 'push'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download JAR Artifact
uses: actions/download-artifact@v3
with:
name: jar-file
path: build/libs/
- name: List Files for Debugging
run: ls -la ./ # ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋ชจ๋“  ํŒŒ์ผ ๋‚˜์—ด
- name: Show docker-compose.yml Content
run: cat docker-compose.yml # docker-compose.yml ํŒŒ์ผ ๋‚ด์šฉ ํ™•์ธ
- name: Send docker-compose.yml to Home Directory
uses: appleboy/scp-action@master
with:
username: ubuntu
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
source: "./docker-compose.yml"
target: "/home/ubuntu/"
strip_components: 1 #๊ฒฝ๋กœ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ํŒŒ์ผ๋งŒ ์ „์†ก
debug: true
## Docker login
- name: Docker Login
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
## Nginx ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ ๋„์ปคํ—ˆ๋ธŒ์— push
- name: Docker build & Push for Nginx
run: |
docker build -f Dockerfile-nginx -t ${{ secrets.DOCKER_REPOSITORY_NGINX }} .
docker push ${{ secrets.DOCKER_REPOSITORY_NGINX }}
- name: Check JAR file existence
run: ls -la build/libs/
## Spring Boot ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ ๋„์ปคํ—ˆ๋ธŒ์— push
- name: Docker build & Push for Spring Boot
run: |
docker build -t ${{ secrets.DOCKER_REPOSITORY }} .
docker push ${{ secrets.DOCKER_REPOSITORY }}
- name: Check Files on AWS Ubuntu
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
script: |
ls -la /home/ubuntu/ # AWS ์„œ๋ฒ„์—์„œ ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ํ™•์ธ
cat /home/ubuntu/docker-compose.yml # AWS ์„œ๋ฒ„์—์„œ ํŒŒ์ผ ๋‚ด์šฉ ํ™•์ธ
# SSH๋กœ ์„œ๋ฒ„์— ์—ฐ๊ฒฐ ๋ฐ Docker compose ์‹คํ–‰
- name: Deploy and Run Docker Compose on Server
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
script: | # SSH ์—ฐ๊ฒฐ ํ›„ ์‹คํ–‰ํ•  ๋ช…๋ น์–ด๋“ค
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
export DOCKER_REPOSITORY=${{ secrets.DOCKER_REPOSITORY }}
export DOCKER_REPOSITORY_NGINX=${{ secrets.DOCKER_REPOSITORY_NGINX }}
# Pull ์ตœ์‹  ์ด๋ฏธ์ง€
docker-compose -f /home/ubuntu/docker-compose.yml pull
# ์ƒˆ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker-compose -f /home/ubuntu/docker-compose.yml up -d --build
discord-notify:
name: Discord Notify
runs-on: ubuntu-latest
environment: dev
needs: [ build, deploy ]
if: always()
steps:
- name: Send Discord Notification
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: ${{ job.status }}
title: "CI/CD Pipeline Status"
description: |
${{ format(
'The CI/CD pipeline has completed.\n- **Build Job Status**: {0}\n- **Deploy Job Status**: {1}\n- **Branch**: {2}\n- **Commit**: {3}\n- **Author**: {4}',
needs.build.result,
needs.deploy.result,
github.ref,
github.sha,
github.actor
) }}
url: "https://github.com/sarisia/actions-status-discord"
username: GitHub Actions Bot