Ci update #66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: docker-ci | |
| on: | |
| push: | |
| branches: [ "develop", "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| # Node 설치 (JS/CSS 빌드를 위한) | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "npm" | |
| - name: Install npm dependencies | |
| run: | | |
| if [ -f package.json ]; then | |
| npm install | |
| fi | |
| # JDK 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: '17' | |
| cache: gradle | |
| # Spring Boot 빌드 (JS/CSS 포함) | |
| - name: Build Spring Boot JAR | |
| run: ./gradlew clean bootJar --no-daemon | |
| # 🤝 Dockerfile에 COPY app.jar 하기 위해 파일명 통일 | |
| - name: Prepare JAR for docker build | |
| run: cp build/libs/*.jar app.jar | |
| # Docker metadata | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} | |
| tags: | | |
| type=sha,format=short | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=raw,value=latest,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| # 로그인 (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 }} | |
| # 이미지 빌드 & 푸시 | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| 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 }} |