chore: ci.yml 수정 #30
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/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@v3 | |
with: | |
arguments: clean jar | |
- name: Check build output | |
run: ls -al /home/runner/work/Mediscan-Server/Mediscan-Server | |
- 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: | | |
echo "Docker Username: ${{ secrets.DOCKER_USERNAME }}" | |
echo "Docker Repo: ${{ secrets.DOCKER_REPO_PROD }}" | |
CONTAINER_IDS=$(sudo docker ps -qa) | |
if [ ! -z "$CONTAINER_IDS" ]; then | |
sudo docker rm -f $CONTAINER_IDS | |
fi | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_PROD }} | |
sudo docker run -dp 80:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_PROD }} |