Skip to content

fix: add exception handling (#41) #56

fix: add exception handling (#41)

fix: add exception handling (#41) #56

Workflow file for this run

name: Publish SpringBoot with Maven
on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: NZC-ENV
# 定义环境变量
env:
REGISTRY: docker.io
IMAGE_NAME: ning2516085027/od-api
IMAGE_TAG: latest
# 定义步骤
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: |
mvn -B package --file pom.xml -Dmaven.test.skip=true
pwd
env
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Deploy with Docker
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
# Method one:
# script: |
# cd /project/od-api
# ./start.sh
# Method two
script: |
docker rm -f od-api
docker rmi ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker pull ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker run -e MYSQL_URL=${{ secrets.MYSQL_URL }} -e MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} -e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} -e REDIS_HOST=${{ secrets.REDIS_HOST }} -e REDIS_PORT=${{ secrets.REDIS_PORT }} -e REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} -e NZC_TOKEN=${{ secrets.NZC_TOKEN }} -e TYN_TOKEN=${{ secrets.TYN_TOKEN }} -e ZZW_TOKEN=${{ secrets.ZZW_TOKEN }} -e XXY_TOKEN=${{ secrets.XXY_TOKEN }} -e LZH_TOKEN=${{ secrets.LZH_TOKEN }} -d -p 8081:8080 --restart=always --name=od-api ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}