datacap/.github/workflows/publish-docker.yml
2023-08-31 21:56:13 +08:00

127 lines
3.6 KiB
YAML

name: Publish images via Docker
on:
release:
types: [ published ]
env:
APP_NAME: datacap
GITHUB_REGISTRY: ghcr.io
APP_GITHUB_GROUP: devlive-community
APP_DOCKER_GROUP: qianmoq
jobs:
before-compile:
runs-on: ubuntu-latest
outputs:
APP_VERSION: ${{ steps.apply_version.outputs.APP_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Generate app version
run: echo APP_VERSION=`./mvnw -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.help=INFO | tail -1` >> "$GITHUB_OUTPUT"
id: apply_version
- name: Compile from source
run: |
chmod 755 ./mvnw
./mvnw clean install package -Dfindbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true
- name: Cache binary
id: cache-binary
uses: actions/cache@v3
env:
cache-name: cache-binary
with:
path: |
./Dockerfile
./dist/datacap-release.tar.gz
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}
publish-github-ghcr:
runs-on: ubuntu-latest
needs:
- before-compile
steps:
- name: Get cache binary
id: cache-binary
uses: actions/cache@v3
env:
cache-name: cache-binary
with:
path: |
./Dockerfile
./dist/datacap-release.tar.gz
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Build
uses: docker/setup-buildx-action@v1
- name: Login
uses: docker/login-action@v1
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: qianmoq
password: ${{ secrets.PACKAGES_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.GITHUB_REGISTRY }}/${{ env.APP_GITHUB_GROUP }}/${{ env.APP_NAME }}:${{ needs.before-compile.outputs.APP_VERSION }}
${{ env.GITHUB_REGISTRY }}/${{ env.APP_GITHUB_GROUP }}/${{ env.APP_NAME }}:latest
publish-docker-hub:
runs-on: ubuntu-latest
needs:
- before-compile
steps:
- name: Get cache binary
id: cache-binary
uses: actions/cache@v3
env:
cache-name: cache-binary
with:
path: |
./Dockerfile
./dist/datacap-release.tar.gz
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Build
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.APP_DOCKER_GROUP }}/${{ env.APP_NAME }}:${{ needs.before-compile.outputs.APP_VERSION }}
${{ env.APP_DOCKER_GROUP }}/${{ env.APP_NAME }}:latest