Skip to content

Commit

Permalink
Split the base image into 2, hopefully now one step can fit in 6h
Browse files Browse the repository at this point in the history
  • Loading branch information
jkozera committed Jul 25, 2024
1 parent 5739b86 commit 6502545
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/cc-base-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths: [ cloudfunctions-cc/Dockerfile.base ]

env:
# the name will always be suffixed by '1' or '2'
REGISTRY_IMAGE: stemclubmodulesbot/cloudfunctions-cc-base

jobs:
Expand All @@ -26,14 +27,6 @@ jobs:
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -46,20 +39,39 @@ jobs:
username: ${{ secrets.CI_REGISTRY_USER }}
password: ${{ secrets.CI_REGISTRY_PASSWORD }}

- name: Build and push by digest
id: build
- name: Build part 1
id: build1
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
context: cloudfunctions-cc
file: cloudfunctions-cc/Dockerfile.base1
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }}1,push=false
tags: latest

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}2
tags: |
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push part 2 by digest
id: build2
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
context: cloudfunctions-cc
file: cloudfunctions-cc/Dockerfile.base
file: cloudfunctions-cc/Dockerfile.base2
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
outputs: type=image,name=${{ env.REGISTRY_IMAGE }}2,push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
digest="${{ steps.build2.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
Expand Down Expand Up @@ -89,7 +101,7 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
images: ${{ env.REGISTRY_IMAGE }}2

- name: Login to Docker Hub
uses: docker/login-action@v3
Expand All @@ -101,8 +113,8 @@ jobs:
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
$(printf '${{ env.REGISTRY_IMAGE }}2@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}2:${{ steps.meta.outputs.version }}
5 changes: 3 additions & 2 deletions cloudfunctions-cc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The base image is built with Dockerfile.base
FROM stemclubmodulesbot/cloudfunctions-cc-base:latest AS build
# The base image is built with Dockerfile.base1 and Dockerfile.base2,
# split in 2 parts to allow the GitHub Actions steps to fit in 6h each.
FROM stemclubmodulesbot/cloudfunctions-cc-base2:latest AS build

COPY . /v/source
RUN curl https://raw.githubusercontent.com/jkozera/oumodulesbot/main/oumodulesbot/cache.json -o /v/source/cache.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Copied from https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-c-plus-plus-service#writing
# Version: 2024.07.25.1 (modify this line to trigger CI build)
# Version: 2024.07.25 (modify this line to trigger CI build)

# We chose Alpine to build the image because it has good support for creating
# statically-linked, small programs.
Expand Down Expand Up @@ -34,14 +34,5 @@ RUN curl -sSL "https://github.com/Microsoft/vcpkg/archive/2024.07.12.tar.gz" | \
&& for path in triplets/*.cmake triplets/community/*.cmake ; do \
echo 'set(VCPKG_BUILD_TYPE release)' >> $path ; \
done \
&& ./bootstrap-vcpkg.sh -disableMetrics

# Copy the source code to /v/source and compile it.
COPY . /v/source
WORKDIR /v/source

# Run the CMake configuration step, setting the options to create
# a statically linked C++ program. This installs the vcpkg dependencies.
RUN cmake -S/v/source -B/v/binary -GNinja \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_BUILD_TYPE=Release
&& ./bootstrap-vcpkg.sh -disableMetrics \
&& ./vcpkg install grpc
13 changes: 13 additions & 0 deletions cloudfunctions-cc/Dockerfile.base2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Version: 2024.07.25 (modify this line to trigger CI build)

FROM stemclubmodulesbot/cloudfunctions-cc-base1 AS build

# Copy the source code to /v/source and compile it.
COPY . /v/source
WORKDIR /v/source

# Run the CMake configuration step, setting the options to create
# a statically linked C++ program. This installs the vcpkg dependencies.
RUN cmake -S/v/source -B/v/binary -GNinja \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_BUILD_TYPE=Release

0 comments on commit 6502545

Please sign in to comment.