Merge pull request #17 from 2024-9oormthonUNIV-Team-7/chore/#16 #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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "develop" ] | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | |
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build | |
# 3. Docker 이미지 빌드 | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/groomthon-univ . | |
# 4. DockerHub 로그인 | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# 5. Docker Hub 이미지 푸시 | |
- name: docker Hub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/groomthon-univ | |
cd: | |
# build-docker-image (위)과정이 완료되어야 실행됩니다. | |
needs: ci | |
runs-on: self-hosted | |
steps: | |
# 1. 최신 이미지를 풀받습니다 | |
- name: docker pull | |
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/groomthon-univ | |
# 2. 기존의 컨테이너를 중지시킵니다 | |
- name: docker stop container | |
run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true | |
# 3. 최신 이미지를 컨테이너화하여 실행시킵니다 | |
- name: docker run new container | |
run: sudo docker run --name groomthon-univ --rm -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/groomthon-univ | |
# 4. 미사용 이미지를 정리합니다 | |
- name: delete old docker image | |
run: sudo docker system prune -f | |
# dependency-submission: | |
# runs-on: ubuntu-latest | |
# permissions: | |
# contents: write | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Set up JDK 17 | |
# uses: actions/setup-java@v4 | |
# with: | |
# java-version: '17' | |
# distribution: 'temurin' | |
# # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. | |
# # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md | |
# - name: Generate and submit dependency graph | |
# uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |