Skip to content

Nightly build and push to Docker Hub #1172

Nightly build and push to Docker Hub

Nightly build and push to Docker Hub #1172

name: Nightly build and push to Docker Hub
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
main:
if: ${{ github.repository_owner == 'haproxytech' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
DOCKER_IMAGE: haproxytech/kubernetes-ingress
steps:
- name: Login to Docker Hub
id: login_docker
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to Container Registry
id: login_ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Check out repo
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare env variables
id: env
run: |
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
- name: Build and push nightly
id: docker_build_nightly
uses: docker/build-push-action@v2
with:
context: .
file: build/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
labels: |
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ env.GIT_SHA }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=nightly
tags: |
${{ env.DOCKER_IMAGE }}:nightly
ghcr.io/${{ github.repository }}:nightly
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache