Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4590539
Deploy to EC2 test1
bagjuna Sep 21, 2025
87315b5
Merge remote-tracking branch 'origin/08-cicd' into 08-cicd
bagjuna Sep 21, 2025
2dbbd31
Deploy to EC2 test2
bagjuna Sep 21, 2025
59b73c6
Deploy to EC2 test3
bagjuna Sep 21, 2025
508545e
Deploy to EC2 test4
bagjuna Sep 21, 2025
58eca33
Deploy to EC2 test5
bagjuna Sep 21, 2025
717c69c
clipse-temurin:11 로 변경
bagjuna Sep 21, 2025
67b7a38
gradle:jdk11 로 변경
bagjuna Sep 21, 2025
9d34901
cicd 변경
bagjuna Sep 21, 2025
e89c51d
eclipse-temurin:11-jre로 변경
bagjuna Sep 21, 2025
444e2ca
valiid수정
bagjuna Sep 21, 2025
9c57f11
cicd 수정
bagjuna Sep 21, 2025
5a03451
되라 제발
bagjuna Sep 21, 2025
419bd89
fast test
bagjuna Sep 21, 2025
694717c
permissions contents: read
bagjuna Sep 21, 2025
4c86aa3
통합으로 테스트
bagjuna Sep 21, 2025
fbe45e6
다시테스트 take 10
bagjuna Sep 21, 2025
2f643c6
다시테스트 take 11
bagjuna Sep 21, 2025
9db6af0
다시 테스트 take 12
bagjuna Sep 21, 2025
32b14a6
다시 테스트 take 15
bagjuna Sep 21, 2025
99acd0c
new 테스트 take 16
bagjuna Sep 21, 2025
bcef1f5
init 수정
bagjuna Sep 21, 2025
40253a0
new 테스트 take 17
bagjuna Sep 21, 2025
b06d68a
set up 수정 2
bagjuna Sep 21, 2025
92f7d69
set up 수정 3
bagjuna Sep 21, 2025
327516a
new 테스트 take 18
bagjuna Sep 21, 2025
6b479e9
new 테스트 take 19
bagjuna Sep 21, 2025
c1657c3
new 테스트 take 20
bagjuna Sep 21, 2025
6d12fe4
new 테스트 take 21
bagjuna Sep 21, 2025
046feef
new 테스트 take 22
bagjuna Sep 21, 2025
ff42590
new 테스트 take 25
bagjuna Sep 21, 2025
728dd12
new 테스트 take 26
bagjuna Sep 21, 2025
e956ab8
new 테스트 take 27
bagjuna Sep 21, 2025
dde9d01
new 테스트 take 28
bagjuna Sep 21, 2025
c0b8a94
new 테스트 take 29
bagjuna Sep 21, 2025
d50d141
new 테스트 take 30
bagjuna Sep 21, 2025
e7001f0
new 테스트 take 31
bagjuna Sep 21, 2025
d978839
new 테스트 take 32
bagjuna Sep 21, 2025
cf1b900
new 테스트 take 33
bagjuna Sep 21, 2025
2f79dd0
new 테스트 take 34
bagjuna Sep 21, 2025
2921bce
new 테스트 take 35
bagjuna Sep 21, 2025
f1b0bbc
new 테스트 take 36
bagjuna Sep 21, 2025
ba18f71
new 테스트 take 37
bagjuna Sep 21, 2025
8003b47
new 테스트 take 38
bagjuna Sep 21, 2025
8fcb4d7
new 테스트 take 39
bagjuna Sep 21, 2025
4c1a630
new 테스트 take 40
bagjuna Sep 21, 2025
3b8f8b9
new 테스트 take 40
bagjuna Sep 21, 2025
d567b17
new 테스트 take 41
bagjuna Sep 21, 2025
27d7d9a
new 테스트 take 41
bagjuna Sep 21, 2025
8a4b2f3
new 테스트 take 42
bagjuna Sep 22, 2025
27f92bd
new 테스트 take 43
bagjuna Sep 22, 2025
1b52464
new 테스트 take 44
bagjuna Sep 22, 2025
886c2d6
new 테스트 take 45
bagjuna Sep 22, 2025
475c4b5
new 테스트 take 46
bagjuna Sep 22, 2025
f751923
new 테스트 take 47
bagjuna Sep 22, 2025
d8bde20
new 테스트 take 48
bagjuna Sep 22, 2025
38c950f
new 테스트 take 49
bagjuna Sep 22, 2025
5680b6e
new 테스트 take 50
bagjuna Sep 22, 2025
ef98d72
new 테스트 take 51
bagjuna Sep 22, 2025
b529699
new 테스트 take 55
bagjuna Sep 22, 2025
af4954e
new 테스트 take 56
bagjuna Sep 22, 2025
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
142 changes: 0 additions & 142 deletions .github/workflows/deploy-on-ec2.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/initial-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# .github/workflows/initial-setup.yml
name: Initial EC2 Setup

on:
workflow_dispatch:

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup EC2 instance
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
# --- 1. Docker 및 Docker Compose 설치 ---
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
sudo apt-get update && sudo apt-get install -y docker.io
sudo systemctl start docker && sudo systemctl enable docker
sudo usermod -aG docker ${{ secrets.EC2_USERNAME }}
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi

# --- 2. docker-compose.yml 파일 생성 (검증된 버전) ---
echo "Creating docker-compose.yml..."
cat << EOF > docker-compose.yml
version: '3.8'
services:
leafy-postgres:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest
ports:
- "5432:5432"
environment:
- POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }}
- POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}
- POSTGRES_DB=${{ secrets.DATASOURCE_URL }}
volumes:
- leafy_data:/var/lib/postgresql/data
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"]
interval: 5s
timeout: 5s
retries: 5
leafy-backend:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest
restart: on-failure
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }}
- SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}
- SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}
- SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect
depends_on:
leafy-postgres:
condition: service_healthy
leafy-front:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest
restart: on-failure
ports:
- "80:80"
environment:
- BACKEND_HOST=leafy-backend
- BACKEND_PORT=8080
depends_on:
- leafy-backend
volumes:
leafy_data:
EOF

# --- 3. 서비스 시작 ---
echo "Starting services..."
sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}"
sudo docker-compose pull
sudo docker-compose up -d

echo "Initial setup complete."
120 changes: 88 additions & 32 deletions .github/workflows/leafy-backend-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,98 @@
name: Backend Build and Push
# .github/workflows/leafy-backend-build-and-push.yml

name: Backend CI/CD

on:
push:
branches:
- 08-cicd
# 08-cicd 브랜치에 push될 때 워크플로우가 실행됩니다.
- '08-cicd'
paths:
- 'leafy-backend/**'

jobs:
build-and-push:
runs-on: ubuntu-latest
# 가장 최신의 Ubuntu 러너를 사용합니다.
- '.github/workflows/leafy-backend-build-and-push.yml'

jobs:
# --- 1. 빌드 및 푸시 Job ---
build:
runs-on: ubuntu-latest
outputs:
sha_tag: ${{ steps.get_sha.outputs.sha }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
# 현재 리포지토리를 체크아웃합니다.
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get short commit sha
id: get_sha
run: echo "sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./leafy-backend
file: ./leafy-backend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ steps.get_sha.outputs.sha }},${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest
platforms: linux/amd64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Docker Buildx를 설정합니다.

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
# GitHub Secret에서 Docker Hub 사용자 이름을 가져옵니다.
password: ${{ secrets.DOCKERHUB_TOKEN }}
# GitHub Secret에서 Docker Hub 액세스 토큰을 가져옵니다.
# --- 2. 배포 Job ---
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2 instance
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
# --- 1. docker-compose.yml 파일이 없으면 새로 생성 ---
if [ ! -f docker-compose.yml ]; then
echo "Creating initial docker-compose.yml"
cat << 'EOF' > docker-compose.yml
services:
leafy-postgres:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest
ports: ["5432:5432"]
environment:
- POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }}
- POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}
- POSTGRES_DB=${{ secrets.DATASOURCE_URL }}
volumes: [- leafy_data:/var/lib/postgresql/data]
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"]
interval: 5s
timeout: 5s
retries: 5
leafy-backend:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }}
restart: on-failure
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }}
- SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}
- SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}
depends_on:
leafy-postgres: { condition: service_healthy }
leafy-front:
image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest
restart: on-failure
ports: ["80:80"]
depends_on: ["leafy-backend"]
volumes:
leafy_data:
EOF
fi

# --- 2. 백엔드 이미지 태그만 수정 ---
sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }}|g" docker-compose.yml

- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./leafy-backend
# Dockerfile이 있는 위치입니다.
file: ./leafy-backend/Dockerfile
# Dockerfile의 경로입니다.
push: true # 이미지를 레지스트리에 푸시합니다.
tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ github.sha }}
platforms: linux/amd64,linux/arm64,windows/amd64

sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}"
sudo docker-compose pull leafy-backend
sudo docker-compose up -d --remove-orphans
sudo docker image prune -af
Loading