Skip to content

Commit 0627a92

Browse files
authored
[chore] 프로덕션 서버 배포 준비 (#248)
* #247 [refactor] 메일 from 주소 이름 추가 * #247 [chore] application prod yml 파일 생성 * #247 [chore] swagger 설정 local, dev에서만 활성화 * #247 [feat] 예시 이미지 타입 enum 구현 * #247 [refactor] 폴더 타입 enum 폴더 이름 추가 * #247 [refactor] s3 서비스 enum 적용 * #247 [chore] folder name 제거 * #247 [chore] 디스커션 알림 워크플로우 삭제 * #247 [chore] 이슈 템플릿 삭제 * #247 [chore] 필요없는 파일 삭제 * #247 [chore] test 필요없는 파일 삭제 * #247 [chore] prod dockerfile 구현 * #247 [chore] docker image build push 워크플로우 구현 * #247 [chore] prod 배포 워크플로우 구현 * #247 [chore] prod docker compose 구현 * #247 [chore] env gitignore에 추가 * #247 [chore] docker image 추가
1 parent 4eede06 commit 0627a92

File tree

21 files changed

+229
-448
lines changed

21 files changed

+229
-448
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/build-prod.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: build-prod
2+
3+
on:
4+
push:
5+
tags:
6+
- v*.*.*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version: ${{ steps.get_version.outputs.VERSION }}
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: 'temurin'
21+
java-version: '17'
22+
23+
- name: Get the version
24+
id: get_version
25+
run: |
26+
RELEASE_VERSION_WITHOUT_V="$(cut -d'v' -f2 <<< ${GITHUB_REF#refs/*/})"
27+
echo ::set-output name=VERSION::$RELEASE_VERSION_WITHOUT_V
28+
29+
- name: Start docker containers
30+
run: docker compose up -d
31+
32+
- name: Set up Gradle
33+
uses: gradle/actions/setup-gradle@v4
34+
35+
- name: Grant Execute Permission for Gradlew
36+
run: chmod +x gradlew
37+
38+
- name: Build with Gradle
39+
run: ./gradlew build --no-daemon
40+
41+
- name: Login to Docker Hub
42+
uses: docker/login-action@v3
43+
with:
44+
username: ${{ secrets.DOCKERHUB_USERNAME }}
45+
password: ${{ secrets.DOCKERHUB_TOKEN }}
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
50+
- name: Build and push
51+
uses: docker/build-push-action@v6
52+
with:
53+
context: .
54+
file: ./docker/prod/Dockerfile
55+
push: true
56+
tags: yugyeong390/photi-server:${{ steps.get_version.outputs.VERSION }}

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
1314

1415
- name: Set up JDK 17
1516
uses: actions/setup-java@v4

.github/workflows/deploy-prod.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: deploy-prod
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy-production:
8+
runs-on: ubuntu-latest
9+
environment: photi-prod
10+
steps:
11+
- name: Checkout Repository
12+
uses: actions/checkout@v4
13+
14+
- name: Create env file
15+
run: |
16+
echo "${{ secrets.ENV_VARS }}" >> ./docker/prod/.env
17+
18+
- name: Create remote directory
19+
uses: appleboy/ssh-action@v1
20+
with:
21+
host: ${{ secrets.DEPLOY_HOST }}
22+
username: ubuntu
23+
key: ${{ secrets.DEPLOY_KEY }}
24+
script: mkdir -p ~/srv/ubuntu
25+
26+
- name: Copy source via ssh key
27+
uses: burnett01/rsync-deployments@7.0.2
28+
with:
29+
switches: -avzr --delete
30+
remote_path: ~/srv/ubuntu/
31+
remote_host: ${{ secrets.DEPLOY_HOST }}
32+
remote_user: ubuntu
33+
remote_key: ${{ secrets.DEPLOY_KEY }}
34+
35+
- name: Execute remote SSH commands using password
36+
uses: appleboy/ssh-action@v1
37+
with:
38+
host: ${{ secrets.DEPLOY_HOST }}
39+
username: ubuntu
40+
key: ${{ secrets.DEPLOY_KEY }}
41+
script: |
42+
echo "start docker compose up: ubuntu"
43+
sudo docker compose -v
44+
sudo docker compose -f ~/srv/ubuntu/docker/prod/docker-compose.yml pull
45+
sudo docker compose -f ~/srv/ubuntu/docker/prod/docker-compose.yml --env-file ~/srv/ubuntu/docker/prod/.env up --build -d
46+
echo "prune images"
47+
sudo docker system prune --all -f

.github/workflows/discussion-notification.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/master-ci.yaml

Lines changed: 0 additions & 75 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ out/
4242
*log*.gz
4343

4444
### env ###
45-
docker/.env
46-
docker/dev/.env
45+
*/.env
46+
*/*/.env

docker/prod/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM openjdk:17-jdk-slim
2+
ARG JAR_FILE=./build/libs/*.jar
3+
COPY ${JAR_FILE} app.jar
4+
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]

docker/prod/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
backend:
3+
image: yugyeong390/photi-server:1.0.0
4+
env_file:
5+
- .env
6+
build:
7+
context: ./docker/prod
8+
dockerfile: ./docker/prod/Dockerfile
9+
ports:
10+
- "8080:8080"
11+
environment:
12+
- TZ=Asia/Seoul
13+
networks:
14+
- server-network
15+
redis:
16+
image: redis:latest
17+
ports:
18+
- "6379:6379"
19+
volumes:
20+
- redis-data:/data
21+
restart: always
22+
networks:
23+
- server-network
24+
25+
volumes:
26+
redis-data:
27+
driver: local
28+
29+
networks:
30+
server-network:
31+
external: true
32+
driver: bridge

0 commit comments

Comments
 (0)