ci: Push images to GitHub Container Registry #346
Workflow file for this run
This file contains 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: GitHub CI | |
on: | |
pull_request: | |
push: | |
paths: | |
- '**/Dockerfile*' | |
schedule: | |
- cron: '0 0 * * *' | |
defaults: | |
run: | |
shell: 'bash -Eeuo pipefail -x {0}' | |
jobs: | |
generate-jobs: | |
name: Generate Jobs | |
runs-on: ubuntu-latest | |
outputs: | |
strategy: ${{ steps.generate-jobs.outputs.strategy }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker-library/bashbrew@v0.1.12 | |
- id: generate-jobs | |
name: Generate Jobs | |
run: | | |
strategy="$("$BASHBREW_SCRIPTS/github-actions/generate.sh")" | |
# If triggered by a cron event, filter strategy to include `unstable` and `unstable-alpine` | |
if [[ "${{ github.event_name }}" == "schedule" ]]; then | |
strategy=$(jq -c '{"fail-fast": .["fail-fast"],"matrix":{"include":[ .matrix.include[]|select(.name =="unstable" or .name== "unstable-alpine")]}}' <<<"$strategy") | |
fi | |
echo "strategy=$strategy" >> "$GITHUB_OUTPUT" | |
jq . <<<"$strategy" # sanity check / debugging aid | |
test: | |
needs: generate-jobs | |
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }} | |
name: ${{ matrix.name }} - test | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Prepare Environment | |
run: ${{ matrix.runs.prepare }} | |
- name: Pull Dependencies | |
run: ${{ matrix.runs.pull }} | |
- name: Build ${{ matrix.name }} | |
run: ${{ matrix.runs.build }} | |
- name: History ${{ matrix.name }} | |
run: ${{ matrix.runs.history }} | |
- name: Test ${{ matrix.name }} | |
run: ${{ matrix.runs.test }} | |
- name: '"docker images"' | |
run: ${{ matrix.runs.images }} | |
build_and_push: | |
if: | | |
((github.event_name == 'push' || github.event_name == 'schedule') && | |
github.ref == 'refs/heads/mainline') | |
needs: | |
- generate-jobs | |
- test | |
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }} | |
name: ${{ matrix.name }} - Build and push | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Tags are created by generate.sh in the format `valkey-container:<tag>` | |
# For Docker Hub this step modifies the tags to `account/valkey:<tag>` to be provided to build-push github action. | |
# For GitHub Container Registry this step modifies the tags to `ghcr.io/<repo-owner>/valkey:<tag>` to be provided to build-push github action. | |
- name: Modify Tags | |
id: modify_tags | |
run: | | |
original_tags="${{ toJson(matrix.meta.entries[0].tags) }}" | |
docker_hub_tags=$(echo $original_tags | sed 's/valkey-container/${{ secrets.DOCKERHUB_ACCOUNT }}\/valkey/g'| sed 's/\[ *//; s/ *\]//; s/ //g') | |
ghcr_tags=$(echo $original_tags | sed 's/valkey-container/ghcr.io\/${{ github.repository_owner }}\/valkey/g'| sed 's/\[ *//; s/ *\]//; s/ //g') | |
echo "docker_hub_tags=$docker_hub_tags" >> $GITHUB_OUTPUT | |
echo "ghcr_tags=$ghcr_tags" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: docker.io | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./${{ matrix.meta.entries[0].directory }}/Dockerfile | |
push: true | |
tags: |- | |
${{ steps.modify_tags.outputs.docker_hub_tags }} | |
${{ steps.modify_tags.outputs.ghcr_tags }} | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
provenance: false | |
load: false | |
update-dockerhub-description: | |
if: | | |
(github.event_name == 'push' && github.ref == 'refs/heads/mainline') | |
needs: | |
- generate-jobs | |
- test | |
- build_and_push | |
name: Update DockerHub Description | |
uses: ./.github/workflows/update-dockerhub-docs.yml | |
secrets: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} |