-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (58 loc) · 2.2 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 }}