2021-01-24 14:24:37 +00:00
|
|
|
name: Docker
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2024-05-02 14:22:04 +00:00
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths-ignore:
|
|
|
|
- web/**
|
|
|
|
- doc/**
|
|
|
|
|
|
|
|
pull_request:
|
2021-01-24 14:24:37 +00:00
|
|
|
branches:
|
|
|
|
- main
|
2023-03-04 17:11:04 +00:00
|
|
|
paths-ignore:
|
|
|
|
- web/**
|
|
|
|
- doc/**
|
2021-01-24 14:24:37 +00:00
|
|
|
|
|
|
|
# Publish `v1.2.3` tags as releases.
|
|
|
|
tags:
|
|
|
|
- v*
|
|
|
|
|
2022-10-13 20:32:01 +00:00
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2021-01-24 14:24:37 +00:00
|
|
|
env:
|
|
|
|
IMAGE_NAME: conky
|
|
|
|
DOCKERHUB_ACCOUNT: brndnmtthws
|
2021-03-01 00:05:44 +00:00
|
|
|
DOCKER_BUILDKIT: 1
|
2021-01-24 14:24:37 +00:00
|
|
|
|
|
|
|
jobs:
|
2024-05-02 17:22:30 +00:00
|
|
|
docker-buildx:
|
2021-01-24 14:24:37 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-09-04 17:18:19 +00:00
|
|
|
uses: actions/checkout@v4
|
2021-01-24 14:24:37 +00:00
|
|
|
- name: Set up QEMU
|
2023-09-18 17:55:27 +00:00
|
|
|
uses: docker/setup-qemu-action@v3
|
2021-01-24 14:24:37 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
id: buildx
|
2023-09-18 17:55:23 +00:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2021-01-24 14:24:37 +00:00
|
|
|
- name: Log into Dockerhub registry
|
|
|
|
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u $DOCKERHUB_ACCOUNT --password-stdin
|
2024-05-02 17:22:30 +00:00
|
|
|
- name: Build and push Docker image
|
|
|
|
env:
|
|
|
|
RELEASE: "${{ startsWith(github.ref, 'refs/tags/') && 'ON' || 'OFF' }}"
|
2021-01-24 14:24:37 +00:00
|
|
|
run: |
|
2024-05-02 17:22:30 +00:00
|
|
|
set -ex
|
|
|
|
|
2021-01-24 14:24:37 +00:00
|
|
|
DOCKERHUB_IMAGE_ID=$DOCKERHUB_ACCOUNT/$IMAGE_NAME
|
|
|
|
|
|
|
|
# Change all uppercase to lowercase
|
|
|
|
DOCKERHUB_IMAGE_ID=$(echo $DOCKERHUB_IMAGE_ID | tr '[A-Z]' '[a-z]')
|
|
|
|
|
2024-05-02 17:22:30 +00:00
|
|
|
image_tags=()
|
|
|
|
|
2021-01-24 14:24:37 +00:00
|
|
|
# Strip git ref prefix from version
|
2024-05-02 17:22:30 +00:00
|
|
|
VERSION_TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
2021-01-24 14:24:37 +00:00
|
|
|
|
|
|
|
# Strip "v" prefix from tag name
|
2024-05-02 17:22:30 +00:00
|
|
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_TAG=$(echo $VERSION_TAG | sed -e 's/^v//')
|
|
|
|
|
|
|
|
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:$VERSION_TAG")
|
|
|
|
|
|
|
|
if [ "$RELEASE" == "ON" ]; then
|
|
|
|
# tag as latest on releases
|
|
|
|
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:latest")
|
|
|
|
fi
|
2021-01-24 14:24:37 +00:00
|
|
|
|
2024-05-02 17:22:30 +00:00
|
|
|
# Only build amd64 on PRs, build all platforms on main. The arm builds
|
|
|
|
# take far too long.
|
|
|
|
image_platforms="--platform linux/amd64"
|
|
|
|
push_image=""
|
|
|
|
cache_tag="pr-cache"
|
|
|
|
if [ "${{ github.ref }}" == "refs/head/main" ]; then
|
|
|
|
# Only push on main
|
|
|
|
push_image="--push"
|
|
|
|
image_platforms="--platform linux/arm/v7,linux/arm64/v8,linux/amd64"
|
|
|
|
cache_tag="main-cache"
|
|
|
|
fi
|
2021-01-24 14:24:37 +00:00
|
|
|
|
2021-03-01 00:05:44 +00:00
|
|
|
docker buildx build \
|
2024-05-02 17:22:30 +00:00
|
|
|
${push_image} \
|
|
|
|
${image_platforms} \
|
|
|
|
--cache-from=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag \
|
|
|
|
--cache-to=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag,mode=max \
|
|
|
|
"${image_tags[@]}" \
|
2021-03-01 00:05:44 +00:00
|
|
|
.
|