Skip to content

Create heypets-cicd.yml #1

Create heypets-cicd.yml

Create heypets-cicd.yml #1

Workflow file for this run

# github repository Actions 페이지에 나타낼 이름
name: heypets CI/CD
# event trigger
on:
push:
branches:
- dev
- main
permissions:
contents: read
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout@v3
- name: Set up JDK 17
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: Change gradlew permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build
## docker build & push to production
- name: Docker build & push
if: contains(github.ref, 'dev')
run: |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker build --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }} .
sudo docker push ${{ secrets.DOCKER_REPO }}
# ## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HEYPETS_SERVER_HOST }}
username: ${{ secrets.HEYPETS_SERVER_USERNAME }}
port: ${{ secrets.HEYPETS_SERVER_PORT }}
key: ${{ secrets.HEYPETS_PRIVATE_KEY }}
script: |
sudo apt-get update
sudo docker compose down
sudo docker rmi $(sudo docker images -q)
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_REPO }}
sudo docker image prune -f
sudo docker compose up -d