-
Notifications
You must be signed in to change notification settings - Fork 3
92 lines (78 loc) · 5.47 KB
/
build-docker-images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Build Container Images for Examples
on:
push:
branches: [ 'main' ]
release:
env:
REGISTRY: ghcr.io/${{ github.repository }}
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASS: ${{ secrets.GITHUB_TOKEN }}
permissions:
packages: write
jobs:
build-container-images:
runs-on: ubuntu-latest
strategy:
matrix:
architecture: ["x86_64-linux", "aarch64-linux"]
steps:
- name: Set up QEMU for cross-compilation
if: ${{ matrix.architecture != 'x86_64-linux' }}
uses: docker/setup-qemu-action@v3
with:
platforms: "arm64"
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: skopeo
version: 1.0
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build text2lines image
run: |
echo TEXT2LINES_IMAGE=$(nix build '.#docker-text2lines-cross.${{ matrix.architecture }}' --print-out-paths) >> "$GITHUB_ENV"
- name: Build lines2words image
run: |
echo LINES2WORDS_IMAGE=$(nix build '.#docker-lines2words-cross.${{ matrix.architecture }}' --print-out-paths) >> "$GITHUB_ENV"
- name: Build wordcount image
run: |
echo WORDCOUNT_IMAGE=$(nix build '.#docker-wordcount-cross.${{ matrix.architecture }}' --print-out-paths) >> "$GITHUB_ENV"
- name: Push image
if: ${{ github.ref != 'main' }}
run: |
export BRANCH_NAME=$(bash -c "echo $GITHUB_REF_NAME | sed -r 's,/,_,g'")
skopeo copy --all --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$TEXT2LINES_IMAGE docker://$REGISTRY/iceflow-examples/text2lines/$INPUT_ARCH:$BRANCH_NAME
skopeo copy --all --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$LINES2WORDS_IMAGE docker://$REGISTRY/iceflow-examples/lines2words/$INPUT_ARCH:$BRANCH_NAME
skopeo copy --all --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$WORDCOUNT_IMAGE docker://$REGISTRY/iceflow-examples/wordcount/$INPUT_ARCH:$BRANCH_NAME
env:
INPUT_ARCH: ${{ ( matrix.architecture == 'x86_64-linux' && 'amd64' ) || ( matrix.architecture == 'aarch64-linux' && 'arm64' ) }}
- name: Push image (and update latest tag)
if: ${{ github.ref == 'main' }}
run: |
export BRANCH_NAME=$(bash -c "echo $GITHUB_REF_NAME | sed -r 's,/,_,g'")
skopeo copy --all --additional-tags=latest --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$TEXT2LINES_IMAGE docker://$REGISTRY/iceflow-examples/text2lines/$INPUT_ARCH:$BRANCH_NAME
skopeo copy --all --additional-tags=latest --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$LINES2WORDS_IMAGE docker://$REGISTRY/iceflow-examples/lines2words/$INPUT_ARCH:$BRANCH_NAME
skopeo copy --all --additional-tags=latest --dest-creds="$REGISTRY_USER:$REGISTRY_PASS" docker-archive:$WORDCOUNT_IMAGE docker://$REGISTRY/iceflow-examples/wordcount/$INPUT_ARCH:$BRANCH_NAME
env:
INPUT_ARCH: ${{ ( matrix.architecture == 'x86_64-linux' && 'amd64' ) || ( matrix.architecture == 'aarch64-linux' && 'arm64' ) }}
build-multiarch-manifest:
runs-on: ubuntu-latest
needs: [ "build-container-images" ]
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Upload manifest
if: ${{ github.ref != 'main' }}
run: |
export BRANCH_NAME=$(bash -c "echo $GITHUB_REF_NAME | sed -r 's,/,_,g'")
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/text2lines/ARCH:$BRANCH_NAME --target $REGISTRY/iceflow-examples/text2lines:$BRANCH_NAME
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/lines2words/ARCH:$BRANCH_NAME --target $REGISTRY/iceflow-examples/lines2words:$BRANCH_NAME
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/wordcount/ARCH:$BRANCH_NAME --target $REGISTRY/iceflow-examples/wordcount:$BRANCH_NAME
- name: Upload manifest (and update latest tag)
if: ${{ github.ref == 'main' }}
run: |
export BRANCH_NAME=$(bash -c "echo $GITHUB_REF_NAME | sed -r 's,/,_,g'")
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/text2lines/ARCH:$BRANCH_NAME --tags latest --target $REGISTRY/iceflow-examples/text2lines:$BRANCH_NAME
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/lines2words/ARCH:$BRANCH_NAME --tags latest --target $REGISTRY/iceflow-examples/lines2words:$BRANCH_NAME
nix develop --impure .#ci -c manifest-tool --username $REGISTRY_USER --password $REGISTRY_PASS push from-args --platforms linux/amd64,linux/arm64 --template $REGISTRY/iceflow-examples/wordcount/ARCH:$BRANCH_NAME --tags latest --target $REGISTRY/iceflow-examples/wordcount:$BRANCH_NAME