Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Docker 기반 CI/CD 환경 구축 #329

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .github/workflows/cd-prod.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: deploy-dev

on:
push:
branches: [ develop ] #TODO: change trigger
release:
types: [ published ]

jobs:
build:
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: deploy-prod

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle

- name: Create application-secret.yml
run: |
pwd
cd ./smeem-bootstrap/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml
cat ./application-secret.yml

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_PROD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set FCM_JSON_PATH
run: echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_prod.json" >> $GITHUB_ENV

- name: Create FireBase JSON file From AWS
run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_PROD }} ${{ env.FCM_JSON_PATH }}

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
shell: bash

- name: Set docker
uses: docker/[email protected]

- name: Login docker
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME_PROD }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN_PROD }}

- name: Build docker image
run: |
docker build --platform linux/amd64 -t smeemprod/smeem-prod:latest -f Dockerfile-prod .
docker push smeemprod/smeem-prod:latest

deploy-cd:
needs: build
runs-on: ubuntu-20.04

steps:
- name: SSH로 서버 접속
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP_PROD }}
username: ${{ secrets.RELEASE_SERVER_USER_PROD }}
key: ${{ secrets.RELEASE_SERVER_KEY_PROD }}
script: |
cd ~

# deploy.sh 파일 다운로드
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/main/script/deploy.sh -O deploy.sh
chmod +x deploy.sh

# .env 파일 추가
if ! grep -q "REGISTRY_URL=" .env; then
echo "REGISTRY_URL=${{ secrets.REGISTRY_URL_PROD }}" >> .env
fi
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env
fi

# 배포 스크립트 실행
sudo ./deploy.sh
4 changes: 4 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM bellsoft/liberica-openjdk-alpine:17
ARG JAR_FILE=/smeem-bootstrap/build/libs/smeem-bootstrap-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} smeem.jar
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/smeem.jar"]
Loading