Skip to content

auto deploy

auto deploy #124

Workflow file for this run

name: auto deploy
on:
push:
branches:
- main
workflow_dispatch:
inputs:
jobs:
push_to_registry:
name: Push to ncp container registry
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create a firebase json file from secret
run: |
curl ${{ secrets.FIREBASE_JSON_URL }} > infra/src/main/resources/firebase.json
cat infra/src/main/resources/firebase.json
- name: Set Yaml
uses: microsoft/variable-substitution@v1
with:
files: ./api/src/main/resources/application.yml
env:
spring.datasource.url: ${{ secrets.DB_URL }}
spring.datasource.username: ${{ secrets.DB_USERNAME }}
spring.datasource.password: ${{ secrets.DB_PASSWORD }}
swagger.server.url: ${{ secrets.SWAGGER_SERVER_URL }}
ncloud.accessKey: ${{ secrets.NCP_ACCESS_KEY }}
ncloud.secretKey: ${{ secrets.NCP_SECRET_KEY }}
weather.apiKey: ${{ secrets.WEATHER_API_KEY }}
weather.apiPath: ${{ secrets.WEATHER_API_PATH }}
jwt.secret: ${{ secrets.JWT_SECRET }}
pawpaw.admin.token: ${{ secrets.PAWPAW_ADMIN_TOKEN }}
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'zulu'
- name: Set up Gradle
run: |
chmod +x gradlew
./gradlew build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to NCP Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/gaetteok:latest
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: connect ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USERNAME }}
password: ${{ secrets.DEV_PASSWORD }}
port: ${{ secrets.DEV_PORT }}
script: |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/gaetteok:latest
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker run -d -p 80:8080 ${{ secrets.NCP_CONTAINER_REGISTRY }}/gaetteok:latest
docker image prune -f