Skip to content
# 构建docker image
#### https://github.com/marketplace?type=actions
#### https://github.com/sdras/awesome-actions
name: Microservice Docker Image
on:
push:
paths:
- 'taotao-cloud-microservice/**'
branches: [ master ]
pull_request:
branches: [ master ]
env:
TAOTAO_CLOUD_OSSRH_USERNAME: ${{ secrets.TAOTAO_CLOUD_OSSRH_USERNAME }}
TAOTAO_CLOUD_OSSRH_PASSWORD: ${{ secrets.TAOTAO_CLOUD_OSSRH_PASSWORD }}
TAOTAO_CLOUD_MAVEN_USERNAME: ${{ secrets.TAOTAO_CLOUD_MAVEN_USERNAME }}
TAOTAO_CLOUD_MAVEN_USERNAME_NEW: ${{ secrets.TAOTAO_CLOUD_MAVEN_USERNAME_NEW }}
TAOTAO_CLOUD_MAVEN_PASSWORD: ${{ secrets.TAOTAO_CLOUD_MAVEN_PASSWORD }}
TAOTAO_CLOUD_MAVEN_PASSWORD_NEW: ${{ secrets.TAOTAO_CLOUD_MAVEN_PASSWORD_NEW }}
TAOTAO_CLOUD_GITHUB_USERNAME: ${{ secrets.TAOTAO_CLOUD_GITHUB_USERNAME }}
TAOTAO_CLOUD_GITHUB_TOKEN: ${{ secrets.TAOTAO_CLOUD_GITHUB_TOKEN }}
TAOTAO_CLOUD_REGISTRY_USERNAME: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
TAOTAO_CLOUD_REGISTRY_PASSWORD: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
TAOTAO_CLOUD_VERSION: 2024.09
jobs:
build:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-docker-image') }}
steps:
#https://github.com/marketplace/actions/checkout
- name: Checkout Project
uses: actions/checkout@v4.1.7
#- name: Set up JDK 21
# uses: actions/setup-java@v4.2.1
# with:
# java-version: 21
# distribution: 'temurin'
#https://github.com/marketplace/actions/github-action-for-graalvm
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.TAOTAO_CLOUD_GITHUB_TOKEN }}
native-image-job-reports: 'true'
- name: Example step
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
echo "JAVA_HOME: $JAVA_HOME"
java --version
native-image --version
#https://github.com/marketplace/actions/cache
- name: Cache Gradle Packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Show Github
run: echo "$GITHUB_CONTEXT"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
MESSAGE_IS_TRUE: ${{ contains(github.event.head_commit.message, 'taotao-cloud-monitor') }}
MESSAGES: ${{ github.event.head_commit.message }}
# base64 secring.gpg > secring.gpg.b64 SIGNING_SECRET_KEY_RING_FILE -> secring.gpg.b64
- name: Decode Signing Secret Key Ring File
run: |
echo "${{ secrets.TAOTAO_CLOUD_SIGNING_SECRET_KEY_RING_FILE }}" > ~/secring.gpg.b64 && base64 -d ~/secring.gpg.b64 > ~/secring.gpg
echo "signing.keyId=${{ secrets.TAOTAO_CLOUD_SIGNING_KEY_ID }}" >> gradle.properties
echo "signing.password=${{ secrets.TAOTAO_CLOUD_SIGNING_PASSWORD }}" >> gradle.properties
echo "signing.secretKeyRingFile=$HOME/secring.gpg" >> gradle.properties
- name: write secrets maven username password
run: |
echo "mavenUsernameNew=${{ secrets.TAOTAO_CLOUD_MAVEN_USERNAME_NEW }}" >> gradle.properties
echo "mavenPasswordNew=${{ secrets.TAOTAO_CLOUD_MAVEN_PASSWORD_NEW }}" >> gradle.properties
#- name: echo gradle
# run: |
# gradle -v
# which gradle
# env
# cat gradle.properties
# echo ${{ secrets.TAOTAO_CLOUD_MAVEN_PASSWORD_NEW }} | base64
#- name: Build And Publish Dependencies To Local
# run: |
# cd ${{ github.workspace }}/taotao-cloud-dependencies
# gradle publishToMavenLocal
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: 8.10
#https://github.com/marketplace/actions/gradle-build-action
- name: Gradle BootJar taotao-cloud-monitor
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-monitor') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-monitor clean bootJar -x test -Pprofile=dev
#https://github.com/marketplace/actions/publish-docker
- name: Publish Docker Image taotao-cloud-monitor
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-monitor') }}
uses: elgohr/Publish-Docker-Github-Action@v5
env:
DINGDING_TOKEN_ID_ARG: ${{ secrets.DING_TOKEN }}
DINGDING_SECRET_ARG: ${{ secrets.DING_SECRET }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-monitor
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
buildargs: DINGDING_SECRET_ARG,DINGDING_TOKEN_ID_ARG
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-monitor
#https://github.com/marketplace/actions/ssh-remote-commands
- name: Ssh To server To execute taotao-cloud-monitor script
#uses: fifsky/ssh-action@master
uses: appleboy/ssh-action@v1.0.3
with:
#command: |
# cd /develop/work/education-back-server
# sh start.sh
host: ${{secrets.SERVER_HOST}}
username: ${{secrets.SERVER_USERNAME}}
port: ${{secrets.SERVER_PORT }}
#key: ${{secrets.SERVER_PRIVATE_KEY}}
password: ${{secrets.SERVER_PASSWORD}}
script:
sh /develop/work/taotao-cloud/taotao-cloud-monitor-start.sh
# sh start.sh
- name: Gradle BootJar taotao-cloud-gateway
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-gateway') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-gateway clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-gateway
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-gateway') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-gateway
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-gateway
- name: Gradle BootJar taotao-cloud-auth
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-auth') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-auth/taotao-cloud-auth-biz clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-auth
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-auth') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-auth
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-auth/taotao-cloud-auth-biz
- name: Gradle BootJar taotao-cloud-xxljob
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-xxljob') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-xxljob clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-xxljob
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-xxljob') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-xxljob
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-xxljob
- name: Gradle BootJar taotao-cloud-order
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-order') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-order/taotao-cloud-order-biz clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-order
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-order') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-order
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-order/taotao-cloud-order-biz
- name: Gradle BootJar taotao-cloud-sys
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-sys') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-sys/taotao-cloud-sys-biz clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-sys
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-sys') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-sys
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-sys/taotao-cloud-sys-biz
- name: Gradle BootJar taotao-cloud-job
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-job') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-job/taotao-cloud-job-biz clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-job
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-job') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-job
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-job/taotao-cloud-job-biz
- name: Gradle BootJar taotao-cloud-file
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-file') }}
run: gradle -p taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-file/taotao-cloud-file-biz clean bootJar -x test -Pprofile=dev
- name: Publish Docker Image taotao-cloud-file
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ contains(github.event.head_commit.message, 'taotao-cloud-file') }}
with:
name: registry.cn-hangzhou.aliyuncs.com/taotao-cloud-project/taotao-cloud-file
username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
buildoptions: "--compress --force-rm"
tags: "${{env.TAOTAO_CLOUD_VERSION}}"
workdir: ${{ github.workspace }}/taotao-cloud-microservice/taotao-cloud-business/taotao-cloud-file/taotao-cloud-file-biz
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.5.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
#- name: login to registry
# uses: docker/login-action@v1
# with:
# registry: registry.cn-hangzhou.aliyuncs.com
# username: ${{ secrets.TAOTAO_CLOUD_REGISTRY_USERNAME }}
# password: ${{ secrets.TAOTAO_CLOUD_REGISTRY_PASSWORD }}
#https://github.com/marketplace/actions/dingding-notify-action
- name: build success
if: ${{ success() }}
uses: zcong1993/actions-ding@master
with:
dingToken: ${{ secrets.DING_TOKEN }}
secret: ${{ secrets.DING_SECRET }}
# body 内容 https://blog.csdn.net/lxw1844912514/article/details/125747327
body: |
{
"msgtype": "text",
"text": {
"content": "taotao github action [taotao-cloud-microservice-docker-image] publish docker image success"
}
}
- name: build failure
if: ${{ failure() }}
uses: zcong1993/actions-ding@master
with:
dingToken: ${{ secrets.DING_TOKEN }}
secret: ${{ secrets.DING_SECRET }}
# body 内容 https://blog.csdn.net/lxw1844912514/article/details/125747327
body: |
{
"msgtype": "text",
"text": {
"content": "taotao github action [taotao-cloud-microservice-docker-image] publish docker image failure"
}
}
# - name: build success
# if: ${{ success() }}
# uses: fifsky/dingtalk-action@master
# with:
# url: https://oapi.dingtalk.com/robot/send?access_token=${{ secrets.TAOTAO_CLOUD_DINGTAOK_TOKEN }}
# type: markdown
# content: |
# # 💯👨‍💻 Success 🎉🎉🎉
# > [Microservice Starters Publish Aliyun] Publish Docker success
# > ^_^ from github action message
#
# - name: build error
# if: ${{ error() }}
# uses: fifsky/dingtalk-action@master
# with:
# url: https://oapi.dingtalk.com/robot/send?access_token=${{ secrets.TAOTAO_CLOUD_DINGTAOK_TOKEN }}
# type: markdown
# content: |
# # 💯👨‍💻 Error 🎉🎉🎉
# > [Microservice Starters Publish Aliyun] Publish Docker error
# > ^_^ from github action message