Skip to content

Build and push new releases to Docker Hub #451

Build and push new releases to Docker Hub

Build and push new releases to Docker Hub #451

Workflow file for this run

name: Build and push new releases to Docker Hub
on:
schedule:
- cron: "0 0 * * *"
jobs:
changes:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.get_tag.outputs.value }}
env:
repo: bojand/ghz
steps:
- name: Install skopeo
run: sudo apt install skopeo
- name: Get all tags that are not in DockerHub yet
id: get_tag
run: |
get_latest() {
local git=$(curl --silent "https://api.github.com/repos/bojand/ghz/git/refs/tags" | jq -r '.[].ref' | sed '1,66d' | sed 's/^refs\/tags\///g' | paste -d, -s)
local docker=$(skopeo inspect docker://obvionaoe/ghz | jq -r '.RepoTags[]' | sed '1d' | sort -V | paste -d, -s)
local result="\""
local flag=0
for i in ${git//,/ }
do
for j in ${docker//,/ }
do
if [[ "$i" == "$j" ]]; then
flag=1
break
fi
done
if [[ $flag -eq 1 ]]; then
flag=0
continue
fi
result+="$i,"
done
result=${result::-1}
if [ -z $result ]; then
result+="\"\""
else
result+="\""
fi
echo $result | jq 'split(",")'
}
delimiter="$(openssl rand -hex 8)"
echo "value<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$(get_latest)" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
docker:
needs: [ changes ]
if: ${{ needs.changes.outputs.tags != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
value: ${{ fromJson(needs.changes.outputs.tags) }}
steps:
- name: Cache Docker build layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ github.repository_owner }}/ghz:${{ matrix.value }},${{ github.repository_owner }}/ghz:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: APP_VERSION=${{ matrix.value }}