Skip to content

Commit b9b5d2c

Browse files
authored
chore: CI/CD 파이프라인 구축 (#36)
* chore: plain jar 파일 생성 비활성화 * chore: Dockerfile 생성 * chore: docker compose 파일 생성 * chore: cd workflow 생성 * chore: 테스트 트리거 추가
1 parent c6d667b commit b9b5d2c

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Deploy to Develop
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
push:
8+
branches:
9+
- develop
10+
11+
env:
12+
DOCKERHUB_USERNAME: ht3064
13+
DOCKERHUB_IMAGE_NAME: syncfit-server
14+
15+
jobs:
16+
build-deploy:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: '17'
27+
distribution: 'temurin'
28+
29+
- name: Grant execute permission for gradlew
30+
run: chmod +x ./gradlew
31+
32+
- name: Build with Gradle
33+
run: ./gradlew clean build -x test
34+
35+
- name: Login to DockerHub
36+
uses: docker/login-action@v2
37+
with:
38+
username: ${{ env.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
40+
41+
- name: Extract metadata for Docker
42+
id: metadata
43+
uses: docker/metadata-action@v4
44+
with:
45+
images: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
46+
tags: |
47+
type=sha,prefix=
48+
49+
- name: Build and Push Docker image
50+
uses: docker/build-push-action@v4.1.1
51+
with:
52+
context: .
53+
push: true
54+
tags: ${{ steps.metadata.outputs.tags }}
55+
56+
- name: Copy docker-compose.yml to EC2
57+
uses: appleboy/scp-action@v0.1.4
58+
with:
59+
host: ${{ secrets.EC2_HOST }}
60+
username: ${{ secrets.EC2_USERNAME }}
61+
key: ${{ secrets.EC2_SSH_KEY }}
62+
source: docker-compose.yml
63+
target: /home/ubuntu/
64+
65+
- name: Deploy to EC2
66+
uses: appleboy/ssh-action@master
67+
env:
68+
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
69+
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }}
70+
with:
71+
host: ${{ secrets.EC2_HOST }}
72+
username: ${{ secrets.EC2_USERNAME }}
73+
key: ${{ secrets.EC2_SSH_KEY }}
74+
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME
75+
script: |
76+
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin
77+
docker compose up -d
78+
docker image prune -a -f

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM openjdk:17
2+
ARG JAR_FILE=build/libs/*.jar
3+
COPY ${JAR_FILE} app.jar
4+
ENTRYPOINT ["java", "-jar", "/app.jar"]

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ dependencies {
6060
tasks.named('test') {
6161
useJUnitPlatform()
6262
}
63+
64+
jar.enabled = true

docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "3.8"
2+
3+
services:
4+
backend:
5+
image: ${IMAGE_FULL_URL}
6+
container_name: ${DOCKERHUB_IMAGE_NAME}
7+
restart: always
8+
network_mode: host
9+
environment:
10+
- TZ=Asia/Seoul
11+
env_file:
12+
- .env
13+
redis:
14+
image: "redis:alpine"
15+
container_name: redis
16+
ports:
17+
- "6379:6379"
18+
network_mode: host
19+
environment:
20+
- TZ=Asia/Seoul

0 commit comments

Comments
 (0)