11name : Docker Build Images (AMD64)
22
3+ env :
4+ # Also remember to change the 'docker/build.sh' script
5+ IMAGE_VER : " v2"
6+
37on :
48 schedule :
59 # Once every Wednesday at 00:00
@@ -26,40 +30,59 @@ jobs:
2630 matrix :
2731 # arch is to tag docker images for uniqueness
2832 host :
29- - { name: 'ubuntu-20 .04', arch: '' }
33+ - { name: 'ubuntu-22 .04', arch: '' }
3034 container :
31- - { distro: 'ubuntu', version: '20.04', codename: 'focal' }
32- - { distro: 'ubuntu', version: '22.04', codename: 'jammy' }
35+ - { version: '20.04', codename: 'focal' }
36+ - { version: '22.04', codename: 'jammy' }
3337
3438 runs-on : ${{ matrix.host.name }}
3539
40+ permissions :
41+ packages : write
42+ contents : read
43+
3644 steps :
3745 - name : Cleanup working directory with container root
3846 run : |
3947 docker run --rm -v $(pwd):/workspace -w /workspace ubuntu:latest find . -name . -o -prune -exec rm -rf -- {} + || true
4048 - uses : actions/checkout@v3
41- - name : Build and Push
49+ - name : Generate Image Name
50+ env :
51+ BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
52+ run : |
53+ test_name=""
54+ if [[ "${GITHUB_REF}" != "refs/heads/master" ]] ; then
55+ test_name="test-${BRANCH_NAME////_}-"
56+ fi
57+ echo "IMAGE_NAME=ghcr.io/lifting-bits/cxx-common/${test_name}vcpkg-builder-ubuntu-${{ env.IMAGE_VER }}:${{ matrix.container.version }}${{ matrix.host.arch }}" >> ${GITHUB_ENV}
58+
59+ - name : Build caching image
4260 working-directory : docker
4361 run : |
4462 # Pull freshest ubuntu Docker image
4563 docker pull ubuntu:${{ matrix.container.version}}
4664
47- docker build -f Dockerfile.ubuntu.vcpkg --target caching --no-cache --build-arg "DISTRO_VERSION=${{ matrix.container.codename }}" -t "docker.pkg.github.com/${DOCKER_TAG}" .
48- # Docker image with NuGet support goes to github packages for CI use only
49- if [[ "${GITHUB_REF}" == "refs/heads/master" ]] ; then
50- docker login docker.pkg.github.com -u publisher -p "${GITHUB_PACKAGE_REGISTRY_TOKEN}"
51- for i in 1 2 3; do docker push "docker.pkg.github.com/${DOCKER_TAG }" && break || sleep 10; done
52- fi
65+ docker build -f Dockerfile.ubuntu.vcpkg \
66+ --no-cache \
67+ --target caching \
68+ --build-arg "DISTRO_VERSION=${{ matrix.container.codename }}" \
69+ -t "${IMAGE_NAME }" \
70+ .
5371
54- # NOTE: Docker Hub only allows one slash in tag
55- docker build -f Dockerfile.ubuntu.vcpkg --target base --build-arg "DISTRO_VERSION=${{ matrix.container.codename }}" -t "trailofbits/cxx-common-vcpkg-builder-${{ matrix.container.distro }}:${{ matrix.container.version }}${{ matrix.host.arch }}" .
56- # Smaller Docker image without NuGet support goes to Docker Hub for users
57- if [[ "${GITHUB_REF}" == "refs/heads/master" ]] ; then
58- docker login -u "${DOCKER_HUB_USER}" -p "${DOCKER_HUB_TOKEN}"
59- for i in 1 2 3; do docker push "trailofbits/cxx-common-vcpkg-builder-${{ matrix.container.distro }}:${{ matrix.container.version }}${{ matrix.host.arch }}" && break || sleep 10; done
60- fi
61- env :
62- DOCKER_TAG : lifting-bits/cxx-common/vcpkg-builder-${{ matrix.container.distro }}:${{ matrix.container.version }}${{ matrix.host.arch }}
63- GITHUB_PACKAGE_REGISTRY_TOKEN : ${{ secrets.GITHUB_PACKAGE_REGISTRY_TOKEN }}
64- DOCKER_HUB_USER : ${{ secrets.DOCKER_HUB_USER }}
65- DOCKER_HUB_TOKEN : ${{ secrets.DOCKER_HUB_TOKEN }}
72+ - name : Log in to registry
73+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
74+
75+ - name : Push caching image
76+ run : docker push "${IMAGE_NAME}"
77+
78+ - name : Build and Push non-caching image
79+ if : github.ref == 'refs/heads/master'
80+ run : |
81+ # Only push smaller image on default branch. This could change in the
82+ # future if we actually need to test the smaller image before merging
83+ docker build -f Dockerfile.ubuntu.vcpkg \
84+ --target base \
85+ --build-arg "DISTRO_VERSION=${{ matrix.container.codename }}" \
86+ -t "${IMAGE_NAME}" \
87+ .
88+ docker push "${IMAGE_NAME}"
0 commit comments