Skip to content

Commit bba10de

Browse files
committed
chore: 인프라 관련 파일 추가
1 parent 36deda3 commit bba10de

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout source code
15+
uses: actions/checkout@v3
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: Make Gradle wrapper executable
24+
run: chmod +x ./gradlew
25+
26+
- name: Build with Gradle
27+
run: ./gradlew clean build -x test
28+
29+
- name: Login to DockerHub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Build and Push Docker Image
39+
uses: docker/build-push-action@v5
40+
with:
41+
context: .
42+
push: true
43+
tags: jdagon2000/intro-teami:latest
44+
deploy:
45+
needs: build-and-push
46+
runs-on: ubuntu-latest
47+
steps:
48+
49+
- name: Create PEM file
50+
run: |
51+
echo "${{ secrets.EC2_SSH_KEY }}" > private_key.pem
52+
chmod 600 private_key.pem
53+
54+
- name: SSH to EC2 and deploy
55+
run: |
56+
ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@${{ secrets.EC2_HOST }} << 'EOF'
57+
set -e
58+
cd ~
59+
docker compose pull
60+
docker compose up -d
61+

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# JDK 21 기반 공식 이미지 사용
2+
FROM openjdk:17-jdk-slim
3+
4+
# 컨테이너 내 작업 디렉토리 설정
5+
WORKDIR /app
6+
7+
# 빌드된 JAR 파일을 컨테이너에 복사
8+
COPY build/libs/project-0.0.1-SNAPSHOT.jar intro.jar
9+
10+
# (필요시 포트 노출)
11+
EXPOSE 8080
12+
13+
# 애플리케이션 실행 명령어
14+
ENTRYPOINT ["java", "-jar", "/app/intro.jar"]

docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 도커 컴포즈 파일에 변경 생기면 바로 인스턴스에 반영하기
2+
version: '3.8'
3+
4+
services:
5+
db:
6+
image: mysql:8.0
7+
container_name: db
8+
environment:
9+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
10+
MYSQL_DATABASE: ${MYSQL_DATABASE}
11+
ports:
12+
- "3306:3306"
13+
volumes:
14+
- mysql_data:/var/lib/mysql
15+
networks:
16+
- intro-network
17+
18+
app:
19+
image: jdagon2000/intro-teami
20+
container_name: intro-app
21+
depends_on:
22+
- db
23+
env_file:
24+
- ./.env
25+
ports:
26+
- "8080:8080"
27+
volumes:
28+
- ./logs:/logs
29+
networks:
30+
- intro-network
31+
32+
nginx:
33+
image: nginx:latest
34+
container_name: nginx
35+
ports:
36+
- "80:80"
37+
volumes:
38+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
39+
depends_on:
40+
- app
41+
networks:
42+
- intro-network
43+
44+
volumes:
45+
mysql_data:
46+
47+
networks:
48+
intro-network:

nginx.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
http {
2+
upstream spring_app {
3+
server intro-app:8080;
4+
}
5+
6+
server {
7+
listen 80;
8+
9+
location / {
10+
proxy_pass http://spring_app;
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)