Skip to content

Update README.md

Update README.md #64

# github repository Actions 페이지에 나타낼 이름
name: 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
## make garamgaebi-firebase-secret.json
- name: make garamgaebi-firebase-secret.json
id: create-json
uses: jsdaniell/[email protected]
with:
name: garamgaebi-firebase-secret.json
json: ${{ secrets.FIREBASE_SECRET }}
dir: './src/main/resources'
## 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: Buid with Gradle
run: ./gradlew build -x test
## 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 -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.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm -f $(docker ps -qa)
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 run -v /var/log:/var/log -p 8080:8080 -e JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }} -e TZ=Asia/Seoul -e "SPRING_PROFILES_ACTIVE=prod" --add-host=host.docker.internal:host-gateway -d docker.io/${{ secrets.DOCKER_REPO }}:latest
# ## deploy to develop
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'dev')
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USERNAME }}
port: ${{ secrets.DEV_PORT }}
key: ${{ secrets.DEV_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm -f $(docker ps -qa)
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 run -v /var/log:/var/log -p 8080:8080 -e JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }} -e TZ=Asia/Seoul -e "SPRING_PROFILES_ACTIVE=dev" --add-host=host.docker.internal:host-gateway -d docker.io/${{ secrets.DOCKER_REPO }}:latest