Skip to content

Commit 516e9b6

Browse files
committed
chore: develop push build deploy 워크플로우 설정
1 parent e4bb58d commit 516e9b6

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: develop push Build and Deploy
2+
3+
on:
4+
push:
5+
branches: [ "develop" ]
6+
7+
env:
8+
DOCKERHUB_USERNAME: fittheman
9+
DOCKERHUB_IMAGE_NAME: fittheman-server
10+
11+
jobs:
12+
build-deploy:
13+
runs-on: ubuntu-latest
14+
environment: DEV
15+
16+
steps:
17+
# 체크아웃
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
# JDK 17 세팅
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: '17'
26+
distribution: 'temurin'
27+
28+
# Gradlew 생행 권한 허용
29+
- name: Grant Execute Permission for Gradlew
30+
run: chmod +x ./gradlew
31+
32+
# Gradle 빌드
33+
- name: Build with Gradle
34+
id: gradle
35+
uses: gradle/gradle-build-action@v2
36+
with:
37+
arguments: |
38+
build
39+
--scan
40+
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
41+
42+
# Dockerhub 로그인
43+
- name: Login to Dockerhub
44+
uses: docker/login-action@v3
45+
with:
46+
username: ${{ env.DOCKERHUB_USERNAME }}
47+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
48+
49+
# Docker 메타데이터
50+
- name: Extract Docker metadata
51+
id: metadata
52+
uses: docker/[email protected]
53+
env:
54+
DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
55+
with:
56+
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }}
57+
tags: |
58+
type=sha,prefix=
59+
60+
# Docker 이미지 빌드, 도커허브 푸시
61+
- name: Build and Push Docker image
62+
uses: docker/build-push-action@v3
63+
with:
64+
context: .
65+
push: true
66+
tags: ${{ steps.metadata.outputs.tags }} # 추출된 도커 메타데이터 tags -> "${DOCKERHUB_USERNAME}/${DOCKERHUB_IMAGE_NAME}:{TAG}
67+
68+
# EC2 서버로 docker-compose.yml 파일 복사
69+
- name: Copy docker-compose file to EC2
70+
uses: burnett01/[email protected]
71+
with:
72+
switches: -avzr --delete
73+
path: docker-compose.yml
74+
remote_host: ${{ secrets.EC2_HOST }}
75+
remote_user: ${{ secrets.EC2_USER }}
76+
remote_key: ${{ secrets.SSH_PRIVATE_KEY }}
77+
remote_path: /home/ubuntu/
78+
79+
# EC2 서버로 nginx 파일 복사
80+
# docker-compose.yml 에서 nginx 컨테이너 실행 시 파일을 마운트하기 위함
81+
- name: Copy default.conf file to EC2
82+
uses: burnett01/[email protected]
83+
with:
84+
switches: -avzr --delete
85+
path: ./nginx
86+
remote_host: ${{ secrets.EC2_HOST }}
87+
remote_user: ${{ secrets.EC2_USER }}
88+
remote_key: ${{ secrets.SSH_PRIVATE_KEY }}
89+
remote_path: /home/ubuntu
90+
91+
# EC2 배포
92+
- name: Deploy to EC2 Server
93+
uses: appleboy/[email protected]
94+
env:
95+
IMAGE_FULL_PATH: ${{ steps.metadata.outputs.tags }}
96+
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }}
97+
with:
98+
host: ${{ secrets.EC2_HOST }}
99+
username: ${{ secrets.EC2_USER }}
100+
key: ${{ secrets.SSH_PRIVATE_KEY }}
101+
envs: IMAGE_FULL_PATH, DOCKERHUB_IMAGE_NAME # docker-compose.yml 에서 사용할 환경 변수
102+
debug: true
103+
script: |
104+
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
105+
docker compose up -d
106+
docker image prune -a -f

src/test/java/com/ftm/server/ServerApplicationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
class ServerApplicationTests {
88

99
@Test
10-
void contextLoads() {
11-
}
12-
10+
void contextLoads() {}
1311
}

0 commit comments

Comments
 (0)