Build Docker Image #256
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Image | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: Specify a custom version | |
required: false | |
default: '' | |
schedule: | |
- cron: "0 20 * * *" | |
env: | |
DOCKERHUB_REPO: ${{ secrets.HACN_USERNAME }}/hacn | |
GITHUB_CR_REPO: ghcr.io/hasscc/hacn | |
ALIYUN_CR_REPO: registry.cn-hangzhou.aliyuncs.com/hasscc/hacn | |
QCLOUD_CR_REPO: ccr.ccs.tencentyun.com/hacn/hacn | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: |- | |
${{ fromJson( | |
github.event.inputs.version == '' && '["","stable","dev","latest"]' || '[""]' | |
) }} | |
addons: ['', mqtt, nodered, addons] | |
steps: | |
- name: Docker tags | |
run: | | |
ver="${{ matrix.version }}" | |
[ -z "$ver" ] && ver="${{ github.event.inputs.version }}" | |
[ -z "$ver" ] && ver="$(date +%Y).$(date +%-m)" | |
if [ -z "${{ matrix.addons }}" ]; then | |
tags="type=raw,value=$ver" | |
if [ "$ver" == "dev" ]; then | |
tags=$({ | |
echo "$tags" | |
echo "type=raw,value=$ver-$(date +%Y%m%d)" | |
}) | |
fi | |
else | |
tags="type=raw,value=$ver-${{ matrix.addons }}" | |
if [ "$ver" == "stable" ]; then | |
tags=$({ | |
echo "$tags" | |
echo "type=raw,value=${{ matrix.addons }}" | |
}) | |
fi | |
if [ "$ver" == "dev" ]; then | |
tags=$({ | |
echo "$tags" | |
echo "type=raw,value=$ver-${{ matrix.addons }}-$(date +%Y%m%d)" | |
}) | |
fi | |
fi | |
echo "VERSION=$ver" >> $GITHUB_ENV | |
{ | |
echo 'ALL_TAGS<<EOF' | |
echo "$tags" | |
echo EOF | |
} >> $GITHUB_ENV | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.DOCKERHUB_REPO }} | |
${{ env.GITHUB_CR_REPO }} | |
tags: ${{ env.ALL_TAGS }} | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.HACN_USERNAME }} | |
password: ${{ secrets.HACN_PASSWORD }} | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
build-args: | | |
VERSION=${{ env.VERSION }} | |
ADDONS=${{ matrix.addons }} | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
sync: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Sync images | |
uses: hhyasdf/image-sync-action@main | |
with: | |
auth_file: .sync/auth.yaml | |
images_file: .sync/images.yaml | |
env: | |
ALIYUN_CR_USER: ${{ secrets.ALIYUN_CR_USER }} | |
ALIYUN_CR_PASS: ${{ secrets.ALIYUN_CR_PASS }} | |
QCLOUD_CR_USER: ${{ secrets.QCLOUD_CR_USER }} | |
QCLOUD_CR_PASS: ${{ secrets.QCLOUD_CR_PASS }} | |
- name: Pull images | |
run: | | |
docker pull ghcr.nju.edu.cn/hasscc/hacn:stable | |
docker pull ghcr.nju.edu.cn/hasscc/hacn:addons |