Skip to content

(fix) ci코드 수정 #34

(fix) ci코드 수정

(fix) ci코드 수정 #34

Workflow file for this run

name: docker-ci
on:
push:
branches: [ "develop", "main" ] # develop: 빌드만, main: 빌드+푸시
pull_request:
branches: [ "main" ] # main 대상 PR 생성/업데이트 시 빌드+푸시
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: gradle
- name: Build Spring Boot JAR
run: ./gradlew clean bootJar --no-daemon
- name: Docker metadata (이미지 태그 자동 생성)
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
tags: |
# 공통
type=sha,format=short
# 브랜치 push 시 (develop/main)
type=ref,event=branch
# PR 시 (main 대상)
type=ref,event=pr
# main push일 때 latest 추가
type=raw,value=latest,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# ✅ DockerHub 로그인: main push 또는 main 대상 PR에서만
- name: Login to DockerHub
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.base_ref == 'main')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 🚫 Alibaba Cloud ACR 관련 단계 (나중 대비용 주석 유지)
# - name: Login to Alibaba Cloud ACR
# if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main')
# uses: docker/login-action@v3
# with:
# registry: cooperation-center-registry.cn-beijing.cr.aliyuncs.com
# username: ${{ secrets.ACR_USERNAME }}
# password: ${{ secrets.ACR_PASSWORD }}
# - name: (옵션) Build & Push to ACR
# uses: docker/build-push-action@v6
# with:
# context: .
# push: true
# tags: |
# cooperation-center-registry.cn-beijing.cr.aliyuncs.com/${{ secrets.ACR_NAMESPACE }}/${{ github.event.repository.name }}:${{ github.sha }}
# cooperation-center-registry.cn-beijing.cr.aliyuncs.com/${{ secrets.ACR_NAMESPACE }}/${{ github.event.repository.name }}:pr-${{ github.event.pull_request.number }}
# cooperation-center-registry.cn-beijing.cr.aliyuncs.com/${{ secrets.ACR_NAMESPACE }}/${{ github.event.repository.name }}:latest
# ✅ Build & Push (조건부 푸시)
- name: Build and (conditionally) Push Docker image (Docker Hub)
uses: docker/build-push-action@v6
with:
context: .
# develop push: false (빌드만)
# main push: true (푸시)
# main 대상 PR: true (푸시)
push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.base_ref == 'main') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}