diff --git a/.github/workflow/publish.yml b/.github/workflow/publish.yml new file mode 100644 index 0000000..c7b50c5 --- /dev/null +++ b/.github/workflow/publish.yml @@ -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 }} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a1f4add..6476c6d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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: @@ -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 @@ -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} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 90385b2..caf4dfc 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: prod \ No newline at end of file + active: dev \ No newline at end of file