linux: build the fedora-sytemd image in the ci #1
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: "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 | |
compose_paths="" | |
for i in $(find . -name docker-compose.yml); do | |
compose_paths="$compose_paths -f $i" | |
done | |
docker compose $compose_paths config > /tmp/docker-compose.yml | |
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@v2 | |
- 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@v5 | |
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 |