Merge pull request #422 from Namo-log/refactor/421 #141
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: 🚀 CD Pipeline for Dev on SSM | |
on: | |
push: | |
branches: [ "dev" ] | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
permissions: | |
contents: read | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_DEV_ACCESS_KEY }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_DEV_SECRET_KEY }} | |
AWS_INSTANCE_ID: ${{ secrets.AWS_DEV_INSTANCE_ID }} | |
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
jobs: | |
deployment: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.push.base_ref }} | |
# 2. Set up JDK 17 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# 3. Cache Gradle dependencies | |
- 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- | |
# 4. Build with Gradle | |
- name: Build with Gradle | |
run: | | |
chmod +x gradlew | |
./gradlew clean build --stacktrace --info -x test | |
shell: bash | |
# 5. Docker 로그인 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
# 6. Docker 이미지 빌드 및 푸시 | |
- name: Docker Image Build & Push | |
env: | |
NAME: namongdev # 계정 명 | |
REPO: springboot-dev-v2 # 레포 이름 | |
run: | | |
docker build -t $REPO . | |
docker tag $REPO:latest $NAME/$REPO:latest | |
docker push $NAME/$REPO:latest | |
# 6. AWS SSM을 통한 Run-Command 실행 | |
- name: AWS SSM Send-Command | |
uses: peterkimzz/aws-ssm-send-command@master | |
id: ssm | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-region: ${{ env.AWS_REGION }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
instance-ids: ${{ env.AWS_INSTANCE_ID }} | |
working-directory: /home/ssm-user | |
command: | | |
docker system prune -a -f | |
docker compose pull | |
docker compose up -d |