Skip to content

Update cd.yml

Update cd.yml #2

Workflow file for this run

# github repository actions 페이지에 나타날 이름
name: CI/CD using github actions
# event trigger
# main 브랜치에 push 됐을때 실행
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Set up jdk'
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java
# gradle caching - 빌드 시간 향상
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
## gradle build
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
## docker build & push to production
- name: Docker build & push to prod
if: contains(github.ref, 'main')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_REPO }}
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.HOST_USERNAME }}
password: ${{ secrets.HOST_PASSWORD }}
port: ${{ secrets.HOST_PORT }}
script: |
docker rm -f gpt-be
docker image rm ${{ secrets.DOCKER_REPO }} -f
docker pull ${{ secrets.DOCKER_REPO }}
docker run -d --name gpt-be --network host
--env DB_CONNECTION=${{secrets.DB_CONNECTION}}
--env DB_NAME=${{secrets.DB_NAME}}
--env GPT_DB_USERNAME=${{secrets.GPT_DB_USERNAME}}
--env GPT_DB_PASSWORD=${{secrets.GPT_DB_PASSWORD}}
--env FLASK_DOMAIN=${{secrets.FLASK_DOMAIN}} ${{secrets.DOCKER_REPO }} --restart on-failure