Skip to content

fix: github runner 재설치 #401

fix: github runner 재설치

fix: github runner 재설치 #401

Workflow file for this run

# 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: #push 이벤트 발생시
branches: #어떤 브랜치에서
- develop
pull_request: #pull_request 발생시
branches: #어떤 브랜치에서
- develop
permissions: #작업에 필요한 권환₩#
contents: read
jobs: #작업을 정의
build-docker-image:
runs-on: ubuntu-latest # Ubunt 환경에서 작업을 실행
steps: #작업 단계 정의
- uses: actions/checkout@v3 #현재 레퍼지토리를 체크아웃
- name: Set up JDK 11 #JDK 11 설치
uses: actions/setup-java@v3 #JDK 11을 설치하는 액션을 사용
with:
java-version: '11'
distribution: 'temurin'
- name: Copy Firebase
env:
FIREBASE: ${{ secrets.FIREBASE }}
FIREBASE_DIR: src/main/resources/key
FIREBASE_DIR_FILE_NAME: just-firebase-key.json
run: |
mkdir -p $FIREBASE_DIR
echo $FIREBASE | base64 --decode > $FIREBASE_DIR/$FIREBASE_DIR_FILE_NAME
- name: Copy Secret
env:
OCCUPY_SECRET: ${{ secrets.OCCUPY_SECRET }}
OCCUPY_SECRET_DIR: src/main/resources
OCCUPY_SECRET_DIR_FILE_NAME: application.yml
run: echo $OCCUPY_SECRET | base64 --decode > $OCCUPY_SECRET_DIR/$OCCUPY_SECRET_DIR_FILE_NAME
- name: Build with Gradle #Gradle이용하여 빌드
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
gradle-version: 7.2 #그래들 버전 7.2 사용
arguments: clean build -x test
# 2. Docker Registry 실행
- name: docker registry run
run: docker run --name private-repo -d -p 5000:5000 registry
# 3. Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/just .
# 4. DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name : docker tag
run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/just localhost:5000/${{ secrets.DOCKERHUB_USERNAME }}/just:latest
# 5. Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push localhost:5000/${{ secrets.DOCKERHUB_USERNAME }}/just:latest
#
run-docker-image-on-ec2:
# build-docker-image (위)과정이 완료되어야 실행됩니다.
needs: build-docker-image
runs-on: self-hosted
steps:
# 1. 최신 이미지를 풀받습니다
- name: docker pull
run: sudo docker pull localhost:5000/${{ secrets.DOCKERHUB_USERNAME }}/just:latest
# 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 just --rm -d -p 9000:9000 localhost:5000/${{ secrets.DOCKERHUB_USERNAME }}/just:latest
# 4. 미사용 이미지를 정리합니다
- name: delete old docker image
run: sudo docker system prune -f