Skip to content

Commit

Permalink
chore/#100 Github Actions, Docker를 이용한 CD (#102)
Browse files Browse the repository at this point in the history
* chore: Dockerfile 및 CD 설정 추가

* chore: gitignore에 docker-compose 추가

* fix: actions 중복 제거

* refactor: 도커 이미지 태깅

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* refactor: 수동 트리거로 변경

* refactor: 일부 네이밍 수정

---------

Co-authored-by: 이한음 <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: LeeHanEum <[email protected]>
  • Loading branch information
4 people authored Nov 18, 2024
1 parent 1d4fd47 commit c866ded
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/dev-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Deploy to Dev Server

on:
workflow_dispatch:

jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- name: get repo from github
uses: actions/checkout@v3

# JDK setting
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# gradle 빌드
- name: Setup Gradle
run: chmod +x gradlew

- name: Build with Gradle Wrapper
run: ./gradlew clean build -p aics-api -x test

# DockerHub 로그인
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Docker 이미지 빌드
- name: Docker image build
env:
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG .
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest
# Docker Hub 이미지 푸시
- name: docker Hub push
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest
deploy-to-dev:
runs-on: ubuntu-latest
needs: build-docker-image
steps:
- name: Deploy to dev
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
script: |
sudo docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest
sudo docker-compose up -d
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### Docker ###
docker-compose.yml
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dockerfile
# Java 17 사용
FROM openjdk:17-jdk-slim

# 작업 디렉토리 설정
WORKDIR /app

# 빌드된 JAR 파일을 이미지에 복사
COPY aics-api/build/libs/*.jar app.jar

# 실행
ENTRYPOINT ["java", "-jar", "app.jar"]

0 comments on commit c866ded

Please sign in to comment.