Skip to content

Commit

Permalink
feature: add-workflow (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicheng-ning authored Apr 7, 2023
1 parent 36c36c5 commit 95aff6b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
64 changes: 64 additions & 0 deletions .github/workflow/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish SpringBoot with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
# 定义环境变量
env:
# MySQL
MYSQL_URL: ${{ secrets.MYSQL_URL }}
MYSQL_USERNAME: ${{ secrets.MYSQL_USERNAME }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
# Redis
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
# GitHub API Token
NZC_TOKEN: ${{ secrets.NZC_TOKEN }}
TYN_TOKEN: ${{ secrets.TYN_TOKEN }}
ZZY_TOKEN: ${{ secrets.ZZY_TOKEN }}
XXY_TOKEN: ${{ secrets.XXY_TOKEN }}
LZH_TOKEN: ${{ secrets.LZH_TOKEN }}
# Docker Image
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
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
- name: Build Docker Image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Deploy with Docker
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
script: |
docker rm -f od-api
docker rmi ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker pull ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker run -d -p 8081:8080 --restart=always --name od-api ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
22 changes: 11 additions & 11 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ server:
port: 8080
spring:
redis:
host: localhost
port: 6380
password: password123
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
database: 0
lettuce:
pool:
Expand All @@ -14,9 +14,9 @@ spring:
min-idle: 0
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: password123
url: jdbc:mysql://localhost:3306/od_api?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
url: ${MYSQL_URL}
hikari:
minimumIdle: 10
maximum-pool-size: 60
Expand All @@ -35,16 +35,16 @@ github:
tokens:
- id: 1
owner: "zhicheng"
token: "ghp_token1"
token: ${NZC_TOKEN}
- id: 2
owner: "tyn"
token: "ghp_token2"
token: ${TYN_TOKEN}
- id: 3
owner: "zhiwei"
token: "ghp_token3"
token: ${ZZW_TOKEN}
- id: 4
owner: "xiaoya"
token: "ghp_token4"
token: ${XXY_TOKEN}
- id: 5
owner: "zehua"
token: "ghp_token5"
token: ${LZH_TOKEN}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
spring:
profiles:
active: prod
active: dev

0 comments on commit 95aff6b

Please sign in to comment.