11name : docker publish
2+
23on :
34 push :
45 tags :
56 - ' *'
7+ workflow_dispatch :
8+ inputs :
9+ usd_version :
10+ description : ' OpenUSD version to build (e.g. 26.05). The ghcr.io/plattar/python-usd:version-<usd_version> base image must already exist.'
11+ required : true
12+ default : ' 26.05'
13+ type : string
14+ image_tag :
15+ description : ' Image tag to publish (defaults to the OpenUSD version above).'
16+ required : false
17+ default : ' '
18+ type : string
19+ tag_latest :
20+ description : ' Also publish the image as :latest.'
21+ required : false
22+ default : false
23+ type : boolean
24+
25+ env :
26+ REGISTRY : ghcr.io
27+
628jobs :
7- build-amd64 :
29+ setup :
830 runs-on : ubuntu-latest
9- timeout-minutes : 360
31+ outputs :
32+ usd_version : ${{ steps.derive.outputs.usd_version }}
33+ image_tag : ${{ steps.derive.outputs.image_tag }}
34+ image_name : ${{ steps.derive.outputs.image_name }}
35+ tag_latest : ${{ steps.derive.outputs.tag_latest }}
1036 steps :
11- - name : checkout code
12- uses : actions/checkout@v3
13- - name : setup qemu
14- uses : docker/setup-qemu-action@v2
15- - name : setup buildx
16- id : buildx
17- uses : docker/setup-buildx-action@v2
18- - name : print available platforms
19- run : echo ${{ steps.buildx.outputs.platforms }}
20- - name : set version from tag
21- run : echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
22- - name : print version number
23- run : echo ${{ env.RELEASE_VERSION }}
24- - name : login to dockerhub
25- uses : docker/login-action@v2
26- with :
27- username : ${{ secrets.DOCKER_UPLOAD_USERNAME }}
28- password : ${{ secrets.DOCKER_UPLOAD_TOKEN }}
29- - name : build & upload
37+ - name : derive build parameters
38+ id : derive
3039 run : |
31- docker buildx build \
32- --push \
33- --tag plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }}-amd64 \
34- --platform linux/amd64 \
35- --file Dockerfile .
36- build-arm64 :
37- runs-on : ubuntu-latest
40+ set -euo pipefail
41+
42+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
43+ usd_version="${{ inputs.usd_version }}"
44+ image_tag="${{ inputs.image_tag }}"
45+ tag_latest="${{ inputs.tag_latest }}"
46+ else
47+ ref="${GITHUB_REF#refs/tags/}"
48+ usd_version="${ref#v}"
49+ image_tag="$ref"
50+ tag_latest="true"
51+ fi
52+
53+ if [[ -z "$image_tag" ]]; then
54+ image_tag="$usd_version"
55+ fi
56+
57+ image_name="$(echo "${{ github.repository_owner }}/python-usd-ar" | tr '[:upper:]' '[:lower:]')"
58+
59+ echo "usd_version=$usd_version" >> "$GITHUB_OUTPUT"
60+ echo "image_tag=$image_tag" >> "$GITHUB_OUTPUT"
61+ echo "image_name=$image_name" >> "$GITHUB_OUTPUT"
62+ echo "tag_latest=$tag_latest" >> "$GITHUB_OUTPUT"
63+
64+ echo "Building OpenUSD v${usd_version} -> ${{ env.REGISTRY }}/${image_name}:${image_tag} (latest=${tag_latest})"
65+
66+ build :
67+ needs : setup
68+ strategy :
69+ fail-fast : false
70+ matrix :
71+ include :
72+ - platform : linux/amd64
73+ runner : ubuntu-latest
74+ - platform : linux/arm64
75+ runner : ubuntu-24.04-arm
76+ runs-on : ${{ matrix.runner }}
3877 timeout-minutes : 360
78+ permissions :
79+ contents : read
80+ packages : write
3981 steps :
82+ - name : prepare platform pair
83+ run : |
84+ platform="${{ matrix.platform }}"
85+ echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"
86+
4087 - name : checkout code
41- uses : actions/checkout@v3
42- - name : setup qemu
43- uses : docker/setup-qemu-action@v2
88+ uses : actions/checkout@v4
89+
4490 - name : setup buildx
45- id : buildx
46- uses : docker/setup-buildx-action@v2
47- - name : print available platforms
48- run : echo ${{ steps.buildx.outputs.platforms }}
49- - name : set version from tag
50- run : echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
51- - name : print version number
52- run : echo ${{ env.RELEASE_VERSION }}
53- - name : login to dockerhub
54- uses : docker/login-action@v2
91+ uses : docker/setup-buildx-action@v3
92+
93+ - name : login to GHCR
94+ uses : docker/login-action@v3
5595 with :
56- username : ${{ secrets.DOCKER_UPLOAD_USERNAME }}
57- password : ${{ secrets.DOCKER_UPLOAD_TOKEN }}
58- - name : build & upload
96+ registry : ${{ env.REGISTRY }}
97+ username : ${{ github.actor }}
98+ password : ${{ secrets.GITHUB_TOKEN }}
99+
100+ - name : build and push by digest
101+ id : build
102+ uses : docker/build-push-action@v6
103+ with :
104+ context : .
105+ file : Dockerfile
106+ platforms : ${{ matrix.platform }}
107+ build-args : |
108+ USD_VERSION=${{ needs.setup.outputs.usd_version }}
109+ labels : |
110+ org.opencontainers.image.title=python-usd-ar
111+ org.opencontainers.image.version=${{ needs.setup.outputs.image_tag }}
112+ org.opencontainers.image.revision=${{ github.sha }}
113+ org.opencontainers.image.source=https://github.com/${{ github.repository }}
114+ outputs : type=image,name=${{ env.REGISTRY }}/${{ needs.setup.outputs.image_name }},push-by-digest=true,name-canonical=true,push=true
115+
116+ - name : export digest
59117 run : |
60- docker buildx build \
61- --push \
62- --tag plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }}-arm64 \
63- --platform linux/arm64 \
64- --file Dockerfile .
65- build-manifest :
118+ mkdir -p /tmp/digests
119+ digest="${{ steps.build.outputs.digest }}"
120+ touch "/tmp/digests/${digest#sha256:}"
121+
122+ - name : upload digest
123+ uses : actions/upload-artifact@v4
124+ with :
125+ name : digests-${{ env.PLATFORM_PAIR }}
126+ path : /tmp/digests/*
127+ if-no-files-found : error
128+ retention-days : 1
129+
130+ merge :
131+ needs : [setup, build]
66132 runs-on : ubuntu-latest
67- timeout-minutes : 360
68- needs : [build-amd64, build-arm64]
133+ permissions :
134+ contents : read
135+ packages : write
69136 steps :
70- - name : checkout code
71- uses : actions/checkout@v3
72- - name : set version from tag
73- run : echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
74- - name : print version number
75- run : echo ${{ env.RELEASE_VERSION }}
76- - name : login to dockerhub
77- uses : docker/login-action@v2
137+ - name : download digests
138+ uses : actions/download-artifact@v4
139+ with :
140+ path : /tmp/digests
141+ pattern : digests-*
142+ merge-multiple : true
143+
144+ - name : setup buildx
145+ uses : docker/setup-buildx-action@v3
146+
147+ - name : login to GHCR
148+ uses : docker/login-action@v3
78149 with :
79- username : ${{ secrets.DOCKER_UPLOAD_USERNAME }}
80- password : ${{ secrets.DOCKER_UPLOAD_TOKEN }}
81- - name : create manifest
82- run : docker manifest create plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }} plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }}-amd64 plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }}-arm64
83- - name : upload manifest
84- run : docker manifest push plattar/python-usd-ar:version-${{ env.RELEASE_VERSION }}
150+ registry : ${{ env.REGISTRY }}
151+ username : ${{ github.actor }}
152+ password : ${{ secrets.GITHUB_TOKEN }}
153+
154+ - name : assemble tag args
155+ id : tags
156+ run : |
157+ set -euo pipefail
158+ image="${{ env.REGISTRY }}/${{ needs.setup.outputs.image_name }}"
159+ tags=("version-${{ needs.setup.outputs.image_tag }}" "${{ needs.setup.outputs.image_tag }}")
160+ if [[ "${{ needs.setup.outputs.tag_latest }}" == "true" ]]; then
161+ tags+=("latest")
162+ fi
163+ args=""
164+ for t in "${tags[@]}"; do
165+ args+=" -t ${image}:${t}"
166+ done
167+ echo "args=${args}" >> "$GITHUB_OUTPUT"
168+
169+ - name : create multi-arch manifest
170+ working-directory : /tmp/digests
171+ run : |
172+ set -euo pipefail
173+ image="${{ env.REGISTRY }}/${{ needs.setup.outputs.image_name }}"
174+ # shellcheck disable=SC2046
175+ docker buildx imagetools create ${{ steps.tags.outputs.args }} \
176+ $(printf "${image}@sha256:%s " *)
177+
178+ - name : inspect
179+ run : |
180+ docker buildx imagetools inspect \
181+ ${{ env.REGISTRY }}/${{ needs.setup.outputs.image_name }}:${{ needs.setup.outputs.image_tag }}
0 commit comments