Skip to content

chore(deps): update docker/build-push-action action to v6 #25

chore(deps): update docker/build-push-action action to v6

chore(deps): update docker/build-push-action action to v6 #25

Workflow file for this run

name: "build images"
on:
workflow_dispatch:
workflow_call:
push:
paths:
- '.github/workflows/build-images.yml'
- '**/Dockerfile'
- 'docker-compose.yml'
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
jobs:
build-info:
runs-on: ubuntu-latest
outputs:
repo-owner: ${{ steps.repo-owner.outputs.result }}
tags: ${{ steps.image-tags.outputs.image-tags }}
build-config: ${{ steps.build-info.outputs.result }}
steps:
#github forces lower case for the image name
- name: Get lowercase repo owner name
uses: actions/github-script@v7
id: repo-owner
with:
result-encoding: string
script: |
return context.repo.owner.toLowerCase()
- uses: actions/checkout@v4
- name: Set nightly tag if commit was on main
id: add-nightly-tag
if: startsWith(github.ref, 'refs/heads/main')
run: |
echo "nightly-tag=nightly" | tr -d "\n" >> $GITHUB_OUTPUT
- name: Set latest tag if its a tag
id: add-latest-tag
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "latest-tag=latest" | tr -d "\n" >> $GITHUB_OUTPUT
- uses: actions/github-script@v7
id: get-tag
if: startsWith(github.ref, 'refs/tags/')
with:
result-encoding: string
script: |
return context.payload.ref.replace('refs/tags/', '')
- name: concat tags to list
id: image-tags
run: |
TAGS=$(cat <<-END
[
"${{ github.sha }}",
"${{ steps.add-nightly-tag.outputs.nightly-tag }}",
"${{ steps.add-latest-tag.outputs.latest-tag }}",
"${{ steps.get-tag.outputs.result }}"
]
END
)
TAGS=$(echo $TAGS | jq -c 'map(select(length > 0))')
echo "image-tags=$TAGS" | tr -d "\n" >> $GITHUB_OUTPUT
- name: Get build info
id: build-info
run: |
set -x
sudo snap install yq
export REPO_NAME=$(basename $(pwd))
echo "services:" > /tmp/docker-compose.yml
for i in $(find . -name docker-compose.yml); do
docker compose -f $i config | yq .services | sed 's/^/ /' >> /tmp/docker-compose.yml
done
yq_pipe='.services.[]'
yq_pipe=$yq_pipe'| select(.build != null)'
yq_pipe=$yq_pipe'| [.build * {"image": .image}]'
yq_pipe=$yq_pipe'| map(.dockerfile=.context + "/" + .dockerfile)'
BUILD_INFO=$(cat /tmp/docker-compose.yml | yq "$yq_pipe" -o=json)
BUILD_INFO=$(echo $BUILD_INFO | jq -c -s add | sed "s|:local||g")
echo "result=$BUILD_INFO" | tr -d "\n" >> $GITHUB_OUTPUT
env:
REPO_OWNER: ${{ steps.repo-owner.outputs.result }}
VERSION: local
build-image:
runs-on: ubuntu-latest
needs:
- build-info
strategy:
fail-fast: false
matrix:
build-config: ${{ fromJSON(needs.build-info.outputs.build-config) }}
env:
tags: ${{ needs.build-info.outputs.tags }}
repo-owner: ${{ needs.build-info.outputs.repo-owner }}
steps:
- uses: actions/checkout@v4
- run: |
echo "inputs:"
cat <<-HEREDOC
${{ toJSON(inputs) }}
HEREDOC
echo "build config:"
cat <<-HEREDOC
${{ toJSON(matrix.build-config) }}
HEREDOC
echo "build tags:"
cat <<-HEREDOC
${{ env.tags }}
HEREDOC
echo "build repo owner:"
cat <<-HEREDOC
${{ env.repo-owner }}
HEREDOC
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v7
id: expand-tags
with:
script: |
return JSON.parse('${{ env.tags }}').map(tag => `${{ matrix.build-config.image }}:${ tag }`)
- name: Build and push image
uses: docker/build-push-action@v6
with:
push: true
file: ${{ matrix.build-config.dockerfile }}
tags: ${{ join(fromJSON(steps.expand-tags.outputs.result)) }}
context: ${{ matrix.build-config.context }}
cache-from: type=gha,scope=${{ matrix.build-config.image }}
cache-to: type=gha,scope=${{ matrix.build-config.image }},mode=max