build image #2737
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 image | |
on: | |
push: | |
branches: | |
- master | |
- main | |
workflow_dispatch: | |
inputs: | |
buildtype: | |
description: 'building by "force" or on "change"' | |
required: true | |
default: 'force' | |
repository_dispatch: | |
types: alpine | |
jobs: | |
compare: | |
runs-on: ubuntu-latest | |
outputs: | |
images: ${{ steps.images.outputs.images }} | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [amd64, arm, arm64] | |
#version: [3.12, 3.14, 3.16, 3.18] | |
version: [3.12] | |
env: | |
name: "treehouses/alpine" | |
steps: | |
- name: checkout repository | |
uses: actions/checkout@v4 | |
- name: compare image | |
id: images | |
run: | | |
export DOCKER_CLI_EXPERIMENTAL=enabled | |
tags="$name-tags" | |
repo="$tags:${{ matrix.arch }}" | |
more="treehouses/alpine-tags:${{ matrix.arch }}-${{ matrix.version }}" | |
case ${{ matrix.arch }} in | |
amd64) : "amd64/alpine:${{ matrix.version }}" ;; | |
arm) : "balenalib/raspberry-pi-alpine:${{ matrix.version }}" ;; | |
arm64) : "arm64v8/alpine:${{ matrix.version }}" ;; | |
esac | |
base="$_" | |
docker pull -q $base &>/dev/null | |
docker pull -q $repo &>/dev/null | |
#docker pull -q $more &>/dev/null | |
basesha=$(docker image inspect $base | jq --raw-output '.[0].RootFS.Layers|.[]') | |
reposha=$(docker image inspect $repo | jq --raw-output '.[0].RootFS.Layers|.[]') | |
#reposha=$(docker image inspect $more | jq --raw-output '.[0].RootFS.Layers|.[]') | |
echo "base sha:$basesha repo sha:$reposha" | |
${{ github.event.inputs.buildtype == 'force' }} && echo "images=true" >> $GITHUB_OUTPUT || echo "no force" | |
[[ $reposha == *$basesha* ]] && echo "no changes" || echo "images=true" >> $GITHUB_OUTPUT | |
images: | |
needs: compare | |
if: ${{ needs.compare.outputs.images }} | |
runs-on: ubuntu-latest | |
outputs: | |
manifests: ${{ steps.manifests.outputs.manifests }} | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [amd64, arm, arm64] | |
#version: [3.12, 3.14, 3.16, 3.18] | |
version: [3.12] | |
env: | |
name: "treehouses/alpine" | |
steps: | |
- name: checkout repository | |
uses: actions/checkout@v4 | |
- name: container registries | |
run: | | |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} | |
- name: docker image | |
id: manifests | |
run: | | |
export DOCKER_CLI_EXPERIMENTAL=enabled | |
tags="$name-tags" | |
repo="$tags:${{ matrix.arch }}" | |
more="treehouses/alpine-tags:${{ matrix.arch }}-${{ matrix.version }}" | |
case ${{ matrix.arch }} in | |
amd64) : "amd64/alpine:${{ matrix.version }}" ;; | |
arm) : "balenalib/raspberry-pi-alpine:${{ matrix.version }}" ;; | |
arm64) : "arm64v8/alpine:${{ matrix.version }}" ;; | |
esac | |
base="$_" | |
date="$repo-$(date +%Y%m%d%H%M)" | |
docker build -t $name --build-arg IMAGE=$base . | |
#for compatilbity reasons | |
if [[ "${{ matrix.version }}" == "3.12" ]]; then | |
docker tag $name ghcr.io/$repo | |
docker tag $name docker.io/repo | |
docker tag $name ghcr.io/$date | |
docker tag $name docker.io/$date | |
#docker push docker.io/$repo | |
docker push ghcr.io/$repo | |
fi | |
docker push --all-tags ghcr.io/$tags | |
docker push --all-tags docker.io/$tags | |
docker images | |
echo "manifests=true" >> $GITHUB_OUTPUT | |
manifests: | |
needs: images | |
if: ${{ needs.images.outputs.manifests }} | |
strategy: | |
fail-fast: false | |
matrix: | |
registry: [docker.io, ghcr.io] | |
#version: [3.12, 3.14, 3.16, 3.18] | |
version: [3.12] | |
runs-on: ubuntu-latest | |
outputs: | |
message: ${{ steps.message.outputs.message }} | |
env: | |
name: "${{ matrix.registry }}/treehouses/alpine" | |
steps: | |
- name: container registries | |
run: | | |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} | |
- name: create manifests | |
id: message | |
run: | | |
export DOCKER_CLI_EXPERIMENTAL=enabled | |
tags="$name-tags" | |
date="$(date +%Y%m%d%H%M)" | |
#for compatilbity reasons | |
if [[ "${{ matrix.version }}" == "3.12" ]]; then | |
docker manifest create $name:latest $tags:amd64 $tags:arm $tags:arm64 | |
docker manifest annotate $name:latest $tags:arm --os linux --arch arm | |
docker manifest inspect $name:latest | |
docker manifest push $name:latest | |
docker manifest create $name:$date $tags:amd64 $tags:arm $tags:arm64 | |
docker manifest annotate $name:$date $tags:arm --os linux --arch arm | |
docker manifest inspect $name:$date | |
docker manifest push $name:$date | |
fi | |
echo "message=true" >> $GITHUB_OUTPUT | |
message: | |
needs: manifests | |
if: ${{ needs.manifests.outputs.message }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: message chat of new image | |
run: | | |
sudo npm install -g @treehouses/cli | |
export discord_channel="${{ secrets.CHANNEL }}" | |
echo "https://hub.docker.com/r/treehouses/alpine/tags" | |
echo "https://github.com/treehouses/alpine/pkgs/container/alpine" | |
treehouses feedback "new treehouses/alpine check https://hub.docker.com/r/treehouses/alpine/tags or https://github.com/treehouses/alpine/pkgs/container/alpine" |