Skip to content

Commit b8d7410

Browse files
- Getting closer.
1 parent 45fd741 commit b8d7410

File tree

2 files changed

+69
-117
lines changed

2 files changed

+69
-117
lines changed

.github/workflows/build.yml

Lines changed: 68 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,17 @@ jobs:
10911091
- linux/arm64
10921092

10931093
steps:
1094+
- name: Prepare
1095+
run: |
1096+
platform=${{ matrix.platform }}
1097+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
1098+
1099+
- name: Docker meta
1100+
id: meta
1101+
uses: docker/metadata-action@v5
1102+
with:
1103+
images: |
1104+
${{ env.STACKQL_IMAGE_NAME }}
10941105
10951106
- name: Check out code into the Go module directory
10961107
uses: actions/[email protected]
@@ -1233,32 +1244,32 @@ jobs:
12331244
12341245
- name: Build Stackql image with buildx
12351246
uses: docker/build-push-action@v6
1247+
id: img_build
12361248
if: env.BUILD_IMAGE_REQUIRED == 'true'
12371249
with:
12381250
context: .
12391251
build-args: |
12401252
BUILDMAJORVERSION=${{env.BUILDMAJORVERSION}}
12411253
BUILDMINORVERSION=${{env.BUILDMINORVERSION}}
12421254
BUILDPATCHVERSION=${{env.BUILDPATCHVERSION}}
1243-
push: false
1255+
load: true
12441256
platforms: ${{ matrix.platform }}
12451257
target: app
1246-
no-cache: ${{ vars.CI_DOCKER_BUILD_NO_CACHE == 'true' && true || false }}
1247-
tags: ${{ env.STACKQL_IMAGE_NAME }}:${{ github.sha }},${{ env.STACKQL_IMAGE_NAME }}:v${{env.BUILDMAJORVERSION}}.${{env.BUILDMINORVERSION}}.${{env.BUILDPATCHVERSION}},${{ env.STACKQL_IMAGE_NAME }}
1248-
outputs: type=docker,dest=${{ runner.temp }}/myimage-${{ env.IMAGE_PLATFORM_SAN }}.tar
1258+
labels: ${{ steps.meta.outputs.labels }}
1259+
outputs: type=image,"name=${{ env.STACKQL_IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true
12491260

1250-
- name: Upload artifact
1261+
- name: Export digest
1262+
run: |
1263+
mkdir -p ${{ runner.temp }}/digests
1264+
digest="${{ steps.img_build.outputs.digest }}"
1265+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
1266+
1267+
- name: Upload digest
12511268
uses: actions/upload-artifact@v4
1252-
if: env.BUILD_IMAGE_REQUIRED == 'true'
12531269
with:
1254-
name: myimage-${{ env.IMAGE_PLATFORM_SAN }}
1255-
path: ${{ runner.temp }}/myimage-${{ env.IMAGE_PLATFORM_SAN }}.tar
1256-
1257-
- name: Load image
1258-
if: env.BUILD_IMAGE_REQUIRED == 'true'
1259-
run: |
1260-
docker load --input ${{ runner.temp }}/myimage-${{ env.IMAGE_PLATFORM_SAN }}.tar
1261-
docker image ls -a
1270+
name: digests-${{ env.PLATFORM_PAIR }}
1271+
path: ${{ runner.temp }}/digests/*
1272+
if-no-files-found: error
12621273

12631274
- name: Debug info
12641275
if: env.BUILD_IMAGE_REQUIRED == 'true'
@@ -1344,109 +1355,49 @@ jobs:
13441355
# run: |
13451356
# sudo rm -rf cicd/vol/postgres/persist
13461357

1347-
dockerpush:
1358+
dockermerge:
13481359
runs-on: ubuntu-latest
1349-
needs: dockerbuild
1350-
strategy:
1351-
fail-fast: false
1352-
matrix:
1353-
platform:
1354-
- linux/amd64
1355-
- linux/arm64
1360+
needs:
1361+
- dockerbuild
13561362
steps:
1357-
1358-
- name: Check out code into the Go module directory
1359-
uses: actions/[email protected]
1360-
1361-
- name: Image env sanitize
1362-
run: |
1363-
BUILD_IMAGE_REQUIRED="true"
1364-
PUSH_IMAGE_REQUIRED="false"
1365-
if [ "$( grep '^build-elide.*' <<< '${{ github.ref_name }}' )" != "" ]; then
1366-
BUILD_IMAGE_REQUIRED="false"
1367-
fi
1368-
# shellcheck disable=SC2235
1369-
if ( \
1370-
[ "${{ github.repository }}" = "stackql/stackql" ] \
1371-
|| [ "${{ github.repository }}" != "stackql/stackql-devel" ] \
1372-
) \
1373-
&& [ "${{ vars.CI_SKIP_DOCKER_PUSH }}" != "true" ] \
1374-
&& [ "$( grep '^build-elide.*' <<< '${{ github.ref_name }}' )" = "" ] \
1375-
&& ( \
1376-
[ "${{ github.ref_type }}" = "branch" ] \
1377-
&& [ "${{ github.ref_name }}" = "main" ] \
1378-
&& [ "${{ github.event_name }}" = "push" ] \
1379-
) \
1380-
|| ( \
1381-
[ "${{ github.ref_type }}" = "tag" ] \
1382-
&& [ "$( grep '^build-release.*' <<< '${{ github.ref_name }}' )" != "" ] \
1383-
); \
1384-
then
1385-
PUSH_IMAGE_REQUIRED="true"
1386-
fi
1387-
if [ "${{ matrix.platform }}" == "linux/arm64" ] && [ "${PUSH_IMAGE_REQUIRED}" = "false" ]; then
1388-
BUILD_IMAGE_REQUIRED="false"
1389-
fi
1390-
{
1391-
echo "IMAGE_PLATFORM_SAN=$( sed 's/\//_/g' <<< '${{ matrix.platform }}' )";
1392-
echo "PUSH_IMAGE_REQUIRED=${PUSH_IMAGE_REQUIRED}";
1393-
echo "BUILD_IMAGE_REQUIRED=${BUILD_IMAGE_REQUIRED}";
1394-
} | tee -a "${GITHUB_ENV}"
1395-
1396-
- name: Download artifact
1397-
uses: actions/download-artifact@v4
1398-
if: env.PUSH_IMAGE_REQUIRED == 'true'
1399-
with:
1400-
name: myimage-${{ env.IMAGE_PLATFORM_SAN }}
1401-
path: ${{ runner.temp }}
1402-
1403-
- name: Extract Build Info and Persist
1404-
env:
1405-
BUILDCOMMITSHA: ${{github.sha}}
1406-
BUILDBRANCH: ${{github.ref}}
1407-
BUILDPLATFORM: ${{runner.os}}
1408-
BUILDPATCHVERSION: ${{github.run_number}}
1409-
run: |
1410-
source cicd/version.txt
1411-
BUILDMAJORVERSION=${MajorVersion}
1412-
BUILDMINORVERSION=${MinorVersion}
1413-
if [[ ! "$BUILDBRANCH" == "*develop" ]]; then
1414-
# shellcheck disable=2269
1415-
BUILDPATCHVERSION="${BUILDPATCHVERSION}"
1416-
fi
1417-
BUILDSHORTCOMMITSHA="$(echo "${BUILDCOMMITSHA}" | cut -c 1-7)"
1418-
BUILDDATE="$(date)"
1419-
export BUILDDATE
1420-
echo "BUILDMAJORVERSION: ${BUILDMAJORVERSION}"
1421-
echo "BUILDMINORVERSION: ${BUILDMINORVERSION}"
1422-
echo "BUILDPATCHVERSION: ${BUILDPATCHVERSION}"
1423-
echo "BUILDBRANCH: ${BUILDBRANCH}"
1424-
echo "BUILDCOMMITSHA: ${BUILDCOMMITSHA}"
1425-
echo "BUILDSHORTCOMMITSHA: ${BUILDSHORTCOMMITSHA}"
1426-
echo "BUILDDATE: ${BUILDDATE}"
1427-
echo "BUILDPLATFORM: ${BUILDPLATFORM}"
1428-
1429-
{
1430-
echo "BUILDMAJORVERSION=$BUILDMAJORVERSION"
1431-
echo "BUILDMINORVERSION=$BUILDMINORVERSION"
1432-
echo "BUILDPATCHVERSION=$BUILDPATCHVERSION"
1433-
echo "UID=${UID}"
1434-
echo "GID=${GID}"
1435-
} >> "${GITHUB_ENV}"
1436-
1437-
- name: Login to Docker Hub
1438-
if: env.PUSH_IMAGE_REQUIRED == 'true'
1439-
uses: docker/login-action@v2
1440-
with:
1441-
username: ${{ secrets.DOCKERHUB_USERNAME }}
1442-
password: ${{ secrets.DOCKERHUB_TOKEN }}
1443-
1444-
- name: Load image
1445-
if: env.PUSH_IMAGE_REQUIRED == 'true'
1446-
run: |
1447-
docker load --input ${{ runner.temp }}/myimage-${{ env.IMAGE_PLATFORM_SAN }}.tar
1448-
docker image ls -a
1449-
docker push ${{ env.STACKQL_IMAGE_NAME }}:${{github.sha}} && \
1450-
docker push ${{ env.STACKQL_IMAGE_NAME }}:v${{env.BUILDMAJORVERSION}}.${{env.BUILDMINORVERSION}}.${{env.BUILDPATCHVERSION}} && \
1451-
docker push ${{ env.STACKQL_IMAGE_NAME }}:latest
1363+
- name: Download digests
1364+
uses: actions/download-artifact@v4
1365+
with:
1366+
path: ${{ runner.temp }}/digests
1367+
pattern: digests-*
1368+
merge-multiple: true
1369+
1370+
- name: Login to Docker Hub
1371+
uses: docker/login-action@v3
1372+
with:
1373+
username: ${{ vars.DOCKERHUB_USERNAME }}
1374+
password: ${{ secrets.DOCKERHUB_TOKEN }}
1375+
1376+
- name: Set up Docker Buildx
1377+
uses: docker/setup-buildx-action@v3
1378+
1379+
- name: Docker meta
1380+
id: meta
1381+
uses: docker/metadata-action@v5
1382+
with:
1383+
images: |
1384+
${{ env.STACKQL_IMAGE_NAME }}
1385+
tags: |
1386+
type=ref,event=branch
1387+
type=ref,event=pr
1388+
type=semver,pattern={{version}}
1389+
type=semver,pattern={{major}}.{{minor}}
1390+
type=raw,value=latest
1391+
type=raw,value=v${{env.BUILDMAJORVERSION}}.${{env.BUILDMINORVERSION}}.${{env.BUILDPATCHVERSION}}
1392+
type=raw,value=${{ github.sha }}
1393+
1394+
- name: Create manifest list and push
1395+
working-directory: ${{ runner.temp }}/digests
1396+
run: |
1397+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
1398+
$(printf '${{ env.STACKQL_IMAGE_NAME }}@sha256:%s ' *)
1399+
1400+
- name: Inspect image
1401+
run: |
1402+
docker buildx imagetools inspect ${{ env.STACKQL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
14521403

docs/CICD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Summary:
1313
- https://docs.docker.com/build/ci/github-actions/share-image-jobs/
1414
- **NOTE**: The QEMU build for linux/arm64 is **very slow**. On the order of 30 minutes. This is currently unavoidable.
1515
- **TODO**: Migrate linux/arm64 docker build to native once GHA supports this platform as a first class citizen.
16+
- ~~**DANGER**: New pattern depends entirely on [docker manifest](https://docs.docker.com/reference/cli/docker/manifest/), which is marked "experimental" by the vendor. Per [this stackoverflow answer](https://stackoverflow.com/a/66337328), in spite of fundamental instability, this is still the best option.~~
1617

1718

1819
## Secrets

0 commit comments

Comments
 (0)