chore: ci.yml 수정 #41
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: 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/db-core/src/main/resources | |
touch storage/db-core/src/main/resources/db-core.yml | |
echo "${{ secrets.DB_CORE_YML }}" > storage/db-core/src/main/resources/db-core.yml | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v3 | |
with: | |
arguments: clean jar | |
- 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: ubuntu-latest | |
steps: | |
- name: Deploy to prod | |
uses: appleboy/[email protected] | |
id: deploy-prod | |
if: contains(github.ref, 'main') | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
sudo docker pull suretrea/${{ secrets.DOCKER_REPO_PROD }} | |
sudo docker stop mediscan 2>/dev/null || true | |
sudo docker rm mediscan 2>/dev/null || true | |
sudo docker run --name mediscan --rm -d -p 8080:8080 suretrea/${{ secrets.DOCKER_REPO_PROD }} | |
sleep 10 | |
sudo docker logs mediscan | |
sudo docker system prune -f |