|
1 | | -name: build on change |
| 1 | +name: build image |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - master |
7 | 7 | - main |
8 | 8 | workflow_dispatch: |
| 9 | + inputs: |
| 10 | + buildtype: |
| 11 | + description: 'Build by "force" or on "change"' |
| 12 | + required: true |
| 13 | + default: 'force' |
9 | 14 | repository_dispatch: |
10 | 15 | types: debian |
11 | 16 |
|
12 | 17 | jobs: |
13 | | - debian: |
14 | | - runs-on: ubuntu-20.04 |
| 18 | + |
| 19 | + compare: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + flag: ${{ steps.set-flag.outputs.flag }} |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + arch: [amd64, arm, arm64] |
| 27 | + steps: |
| 28 | + - name: checkout repository |
| 29 | + uses: actions/checkout@v2 |
| 30 | + - name: container registries |
| 31 | + run: | |
| 32 | + docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} |
| 33 | + docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} |
| 34 | + - name: compare image |
| 35 | + id: set-flag |
| 36 | + run: | |
| 37 | + export DOCKER_CLI_EXPERIMENTAL=enabled |
| 38 | + version="buster" |
| 39 | + repo="treehouses/debian-tags:${{ matrix.arch }}" |
| 40 | + case ${{ matrix.arch }} in |
| 41 | + amd64) : "amd64/debian:$version" ;; |
| 42 | + arm) : "balenalib/raspberry-pi-debian:$version" ;; |
| 43 | + arm64) : "arm64v8/debian:$version" ;; |
| 44 | + esac |
| 45 | + base="$_" |
| 46 | + docker pull -q $base &>/dev/null |
| 47 | + docker pull -q $repo &>/dev/null |
| 48 | + basesha=$(docker image inspect $base | jq --raw-output '.[0].RootFS.Layers|.[]') |
| 49 | + reposha=$(docker image inspect $repo | jq --raw-output '.[0].RootFS.Layers|.[]') |
| 50 | + echo "base sha:$basesha repo sha:$reposha" |
| 51 | + ${{ github.event.inputs.buildtype == 'force' }} && echo "::set-output name=flag::true" || echo "building on change" |
| 52 | + [[ $reposha == *$basesha* ]] && echo "no changes" || echo "::set-output name=flag::true" |
| 53 | +
|
| 54 | + images: |
| 55 | + needs: compare |
| 56 | + runs-on: ubuntu-latest |
| 57 | + outputs: |
| 58 | + build: ${{ steps.set-build.outputs.build }} |
| 59 | + strategy: |
| 60 | + fail-fast: false |
| 61 | + matrix: |
| 62 | + arch: [amd64, arm, arm64] |
15 | 63 | steps: |
16 | | - - name: checkout |
| 64 | + - name: checkout repository |
17 | 65 | uses: actions/checkout@v2 |
18 | | - - name: docker login |
19 | | - run: docker login -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} |
20 | | - - name: treehouses debian |
| 66 | + - name: container registries |
| 67 | + run: | |
| 68 | + docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} |
| 69 | + docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} |
| 70 | + - name: docker image |
| 71 | + if: ${{ needs.compare.outputs.flag }} |
| 72 | + id: set-build |
21 | 73 | run: | |
22 | 74 | export DOCKER_CLI_EXPERIMENTAL=enabled |
23 | | - repo="treehouses/debian" |
24 | | - source .github/workflows/utils.sh |
25 | | - echo "amd64" |
26 | | - debian_x86_sha=$(get_variant_sha "debian" "latest" "amd64") |
27 | | - echo $debian_x86_sha |
28 | | - variant_debian_x86_sha=$(get_manifest_sha "$repo:latest" "amd64") |
29 | | - echo $variant_debian_x86_sha |
30 | | - echo "arm" |
31 | | - balena_rpi_sha=$(get_tag_sha "balenalib/raspberry-pi-debian" "latest") |
32 | | - echo $balena_rpi_sha |
33 | | - variant_rpi_sha=$(get_manifest_sha "$repo:latest" "arm") |
34 | | - echo $variant_rpi_sha |
35 | | - echo "arm64" |
36 | | - debian_arm64_sha=$(get_variant_sha "debian" "latest" "arm64") |
37 | | - echo $debian_arm64_sha |
38 | | - variant_debian_arm64_sha=$(get_manifest_sha "$repo:latest" "arm64") |
39 | | - echo $variant_debian_arm64_sha |
40 | | - echo "change" |
41 | | - flag=$(compare_sha "$debian_x86_sha" "$variant_debian_x86_sha" "$balena_rpi_sha" "$variant_rpi_sha" "$debian_arm64_sha" "$variant_debian_arm64_sha") |
42 | | - echo $flag |
43 | | - if [[ $flag == true ]]; then |
44 | | - sudo npm install -g @treehouses/cli |
45 | | - export gitter_channel="${{ secrets.CHANNEL }}" |
46 | | - tag="$(date +%Y%m%d%H%M)" |
47 | | - echo $tag |
48 | | - docker manifest create $repo:$tag "debian@"$debian_x86_sha "balenalib/raspberry-pi-debian@"$balena_rpi_sha "debian@"$debian_arm64_sha |
49 | | - docker manifest annotate $repo:$tag "debian@"$debian_arm64_sha --arch arm64 |
50 | | - docker manifest annotate $repo:$tag "balenalib/raspberry-pi-debian@"$balena_rpi_sha --arch arm |
51 | | - docker manifest inspect $repo:$tag |
52 | | - docker manifest push $repo:$tag |
53 | | - tag2="latest" |
54 | | - echo $tag2 |
55 | | - docker manifest create $repo:$tag2 "debian@"$debian_x86_sha "balenalib/raspberry-pi-debian@"$balena_rpi_sha "debian@"$debian_arm64_sha |
56 | | - docker manifest annotate $repo:$tag2 "debian@"$debian_arm64_sha --arch arm64 |
57 | | - docker manifest annotate $repo:$tag2 "balenalib/raspberry-pi-debian@"$balena_rpi_sha --arch arm |
58 | | - docker manifest inspect $repo:$tag2 |
59 | | - docker manifest push $repo:$tag2 |
60 | | - echo "https://hub.docker.com/r/treehouses/debian/tags" |
61 | | - treehouses feedback "new treehouses/debian check https://hub.docker.com/r/treehouses/debian/tags" |
62 | | - else |
63 | | - echo "no changes" |
64 | | - fi |
| 75 | + version="buster" |
| 76 | + case ${{ matrix.arch }} in |
| 77 | + amd64) : "amd64/debian:$version" ;; |
| 78 | + arm) : "balenalib/raspberry-pi-debian:$version" ;; |
| 79 | + arm64) : "arm64v8/debian:$version" ;; |
| 80 | + esac |
| 81 | + image="$_" |
| 82 | + repo="treehouses/debian-tags" |
| 83 | + dest="$repo:${{ matrix.arch }}" |
| 84 | + date="$(date +%Y%m%d%H%M)" |
| 85 | + docker build -t ghcr.io/$dest --build-arg IMAGE=$image . |
| 86 | + docker tag ghcr.io/$dest docker.io/$dest |
| 87 | + docker tag ghcr.io/$dest ghcr.io/$dest-$date |
| 88 | + docker tag docker.io/$dest docker.io/$dest-$date |
| 89 | + docker push --all-tags ghcr.io/$repo |
| 90 | + docker push --all-tags docker.io/$repo |
| 91 | + docker images |
| 92 | + echo "::set-output name=build::true" |
| 93 | +
|
| 94 | + manifests: |
| 95 | + needs: images |
| 96 | + strategy: |
| 97 | + fail-fast: false |
| 98 | + matrix: |
| 99 | + registry: [docker.io, ghcr.io] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + outputs: |
| 102 | + send: ${{ steps.set-send.outputs.send }} |
| 103 | + steps: |
| 104 | + - name: container registries |
| 105 | + run: | |
| 106 | + docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} |
| 107 | + docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} |
| 108 | + - name: create manifests |
| 109 | + if: ${{ needs.images.outputs.build }} |
| 110 | + id: set-send |
| 111 | + run: | |
| 112 | + repo="${{ matrix.registry }}/treehouses/debian" |
| 113 | + date="$(date +%Y%m%d%H%M)" |
| 114 | + docker manifest create $repo:latest $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 |
| 115 | + docker manifest create $repo:$date $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 |
| 116 | + docker manifest annotate $repo:latest $repo-tags:arm --os linux --arch arm |
| 117 | + docker manifest annotate $repo:$date $repo-tags:arm --os linux --arch arm |
| 118 | + docker manifest inspect $repo:latest |
| 119 | + docker manifest push $repo:latest |
| 120 | + docker manifest push $repo:$date |
| 121 | + echo "::set-output name=send::true" |
| 122 | +
|
| 123 | + message: |
| 124 | + needs: manifests |
| 125 | + runs-on: ubuntu-latest |
| 126 | + steps: |
| 127 | + - name: message chat of new image |
| 128 | + if: ${{ needs.manifests.outputs.send }} |
| 129 | + run: | |
| 130 | + sudo npm install -g @treehouses/cli |
| 131 | + export gitter_channel="${{ secrets.CHANNEL }}" |
| 132 | + echo "https://hub.docker.com/r/treehouses/debian/tags" |
| 133 | + echo "https://github.com/treehouses/debian/pkgs/container/debian" |
| 134 | + treehouses feedback "new treehouses/debian check https://hub.docker.com/r/treehouses/debian/tags or https://github.com/treehouses/debian/pkgs/container/debian" |
0 commit comments