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/#100 Github Actions, Docker를 이용한 CD #102

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 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: CD using github actions & docker

on:
pull_request:
branches: [ "main", "develop" ]

permissions:
contents: read

LeeHanEum marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Docker 작업을 위한 권한 설정이 불충분합니다

워크플로우가 Docker Hub와 상호작용하기 위해서는 추가적인 권한이 필요합니다.

다음과 같이 수정하세요:

permissions:
  contents: read
+ packages: write
+ actions: write
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
permissions:
contents: read
permissions:
contents: read
packages: write
actions: write

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 build -p aics-api -x test
LeeHanEum marked this conversation as resolved.
Show resolved Hide resolved

LeeHanEum marked this conversation as resolved.
Show resolved Hide resolved
# DockerHub 로그인
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Docker 이미지 빌드
- name: Docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest .

# Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest
LeeHanEum marked this conversation as resolved.
Show resolved Hide resolved

deploy-to-dev:
runs-on: ubuntu-latest
needs: build-docker-image
steps:
- name: Deploy to dev
uses: appleboy/[email protected]
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
sudo docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest
sudo docker-compose up -d
LeeHanEum marked this conversation as resolved.
Show resolved Hide resolved
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"]
Loading