Skip to content

Merge pull request #55 from TreeNut-KR/develop #103

Merge pull request #55 from TreeNut-KR/develop

Merge pull request #55 from TreeNut-KR/develop #103

Workflow file for this run

name: Build and Push Docker Images
permissions:
contents: write # 리포지토리 컨텐츠 쓰기 권한
packages: write # 패키지 쓰기 권한
on:
push:
tags:
- 'v*.*.*' # v로 시작하는 태그에 대해 실행
jobs:
# API 명세서 업데이트 및 GitHub 릴리스 생성 작업
update-docs-and-release:
runs-on: ubuntu-latest
env:
TAG_NAME: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Update API specification version
run: |
# 태그에서 v 접두사 제거
VERSION=$(echo ${{ env.TAG_NAME }} | sed 's/^v//')
# FastAPI 버전 정보 업데이트
sed -i "s/- \*\*버전\*\*: .*/- \*\*버전\*\*: $VERSION/" fastapi/src/docs/api_specification.md
# 변경된 내용을 확인
cat fastapi/src/docs/api_specification.md
- name: Prepare Release Notes
run: |
# 임시 릴리스 노트 파일 생성
echo "# 릴리스 ${{ env.TAG_NAME }}" > release_notes.md
echo "" >> release_notes.md
# FastAPI 명세서 추가
echo "## FastAPI 명세서" >> release_notes.md
cat fastapi/src/docs/api_specification.md >> release_notes.md
echo "" >> release_notes.md
# SpringBoot RoomController 명세서 추가
echo "## SpringBoot RoomController 명세서" >> release_notes.md
cat springboot/src/docs/RoomController.md >> release_notes.md
echo "" >> release_notes.md
# SpringBoot UserController 명세서 추가
echo "## SpringBoot UserController 명세서" >> release_notes.md
cat springboot/src/docs/UserController.md >> release_notes.md
echo "" >> release_notes.md
# SpringBoot CharacterController 명세서 추가
echo "## SpringBoot CharacterController 명세서" >> release_notes.md
cat springboot/src/docs/CharacterController.md >> release_notes.md
echo "" >> release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
body_path: release_notes.md # 통합된 릴리스 노트 사용
files: |
docker-compose.yml # 배포 파일 포함
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Docker 이미지 빌드 및 푸시 작업
build-and-push-images:
runs-on: ubuntu-latest
needs: update-docs-and-release # 릴리스가 먼저 생성된 후에 실행
env:
TAG_NAME: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TREENUT }}
- name: Create React env file
run: |
# React 프로젝트의 환경 변수 설정
echo "${{ secrets.REACT_ENV }}" > nginx/react-frontpage/.env
cat nginx/react-frontpage/.env
- name: Install Node.js and build react-frontpage
run: |
cd nginx/react-frontpage
npm install
npx update-browserslist-db@latest
npm run build || true
env:
NODE_VERSION: '20' # Node.js 버전은 20이상을 사용
- name: Create .env files for Docker build
run: |
echo "${{ secrets.DOCKER_ENV }}" > .env
mkdir -p mongo && echo "${{ secrets.MONGO_ENV }}" > ./mongo/.env
mkdir -p fastapi/src && echo "${{ secrets.FASTAPI_ENV }}" > ./fastapi/src/.env
mkdir -p ./springboot/src/main/resources
echo "${{ secrets.SPRING_ENV }}" > ./springboot/src/main/resources/application.properties
echo "${{ secrets.SPRING_SWAGGER_ENV }}" > ./springboot/src/main/resources/application.yml
- name: Set up SSL certificates
run: |
mkdir -p nginx/certificates
echo "${{ secrets.SSL_CERT }}" | base64 -d > nginx/certificates/treenut.ddns.net_2025040424819.crt.pem
echo "${{ secrets.SSL_KEY }}" | base64 -d > nginx/certificates/treenut.ddns.net_2025040424819.key.pem
echo "${{ secrets.SSL_CHAIN }}" | base64 -d > nginx/certificates/treenut.ddns.net_2025040424819.all.crt.pem
chmod 644 nginx/certificates/*.crt.pem
chmod 600 nginx/certificates/*.key.pem
ls -la nginx/certificates/ # 디버깅용 파일 목록 확인
- name: Build and push Nginx image
uses: docker/build-push-action@v3
with:
context: ./nginx
push: true
tags: |
ghcr.io/treenut-kr/nginx:latest
ghcr.io/treenut-kr/nginx:${{ github.ref_name }}
- name: Build and push FastAPI image
uses: docker/build-push-action@v3
with:
context: ./fastapi
file: ./fastapi/src/server/Dockerfile
push: true
tags: |
ghcr.io/treenut-kr/fastapi:latest
ghcr.io/treenut-kr/fastapi:${{ github.ref_name }}
- name: Build and push MySQL image
uses: docker/build-push-action@v3
with:
context: ./mysql
push: true
tags: |
ghcr.io/treenut-kr/mysql:latest
ghcr.io/treenut-kr/mysql:${{ github.ref_name }}
- name: Build and push MongoDB image
uses: docker/build-push-action@v3
with:
context: ./mongo
push: true
tags: |
ghcr.io/treenut-kr/mongodb:latest
ghcr.io/treenut-kr/mongodb:${{ github.ref_name }}
- name: Build and push SpringBoot image
uses: docker/build-push-action@v3
with:
context: ./springboot
push: true
tags: |
ghcr.io/treenut-kr/springboot:latest
ghcr.io/treenut-kr/springboot:${{ github.ref_name }}
- name: Create custom Flyway Dockerfile
run: |
cat > flyway.Dockerfile << 'EOF'
FROM flyway/flyway:7.15.0
# 마이그레이션 파일과 스크립트 복사 (실행 권한 포함)
COPY ./mysql/migrations /flyway/sql
COPY --chmod=755 ./mysql/flyway-migrate.sh /flyway/flyway-migrate.sh
# 엔트리포인트 설정
ENTRYPOINT ["/bin/bash", "/flyway/flyway-migrate.sh"]
EOF
- name: Build and push Flyway image
uses: docker/build-push-action@v3
with:
context: .
file: ./flyway.Dockerfile
push: true
tags: |
ghcr.io/treenut-kr/flyway:latest
ghcr.io/treenut-kr/flyway:${{ github.ref_name }}