Skip to content

chore: ci.yml 수정 #15

chore: ci.yml 수정

chore: ci.yml 수정 #15

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Lint
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: ktlintCheck
# - name: create .env file
# run: |
# mkdir -p .storage/src/main/resources
# touch .storage/src/main/resources/db-core.yml
# echo "${{ secrets.DB_CORE_YML }}" >> storage/src/main/resources/db-core.yml
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean bootJar
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mediscan .
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mediscan
run-docker-image-on-ec2:
needs: build-docker-image
runs-on: self-hosted
steps:
# 1. 최신 이미지를 풀받습니다
- name: docker pull
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mediscan
# 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 startingblock-prod --rm -d -p 8080:8080 -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/mediscan
# 4. 미사용 이미지를 정리합니다
- name: delete old docker image
run: sudo docker system prune -f