feat: CI/CD #5
This file contains 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: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. 코드 체크아웃 | |
- uses: actions/checkout@v3 | |
# 2. Java 17 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# 3. Spring Boot 애플리케이션 빌드 | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 | |
with: | |
arguments: clean bootJar | |
# 4. DockerHub 로그인 | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# 5. Docker 이미지 빌드 및 푸시 | |
- name: Build and Push Docker image | |
run: | | |
IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/spark | |
TAG=$(date +'%Y%m%d%H%M') # 현재 시간 기반 태그 생성 | |
# 이미지 빌드 및 태그 설정 | |
docker build -t $IMAGE_NAME:$TAG . | |
docker tag $IMAGE_NAME:$TAG $IMAGE_NAME:latest | |
# Docker Hub로 푸시 | |
docker push $IMAGE_NAME:$TAG | |
docker push $IMAGE_NAME:latest |