Skip to content

Commit 180d788

Browse files
authored
Add caching for Dockerfile build (#94)
* Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * Add caching for Dockerfile build * no podman * gawk * env? * env? * env? * path? * path? * grab write all? * grab write all? * grab write all? * grab write all? * grab write all? * grab write all? * grab write all? * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * dockar * cache dir * ccache dir again? * fix ccache dir name in container * change cache dir * update dockerfile
1 parent 53dfc76 commit 180d788

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea
33
/bazel-*
44
/cmake-*
5+
/qpid-proton
56
Dockerfile

.github/workflows/image_build.yaml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,34 @@ on:
66
workflow_dispatch:
77
branches: [ main ]
88

9-
permissions: read-all
9+
permissions:
10+
packages: write
1011

1112
env:
12-
IMAGE_NAME: cli-cpp
1313
IMAGE_REGISTRY: quay.io
1414
IMAGE_NAMESPACE: rhmessagingqe
15+
IMAGE_NAME: cli-cpp
16+
# https://github.com/actions/cache/issues/814
17+
CCACHE_DIR: /ccache
1518

1619
jobs:
1720
build:
1821
name: Build and push image
1922
runs-on: ubuntu-22.04
23+
# https://github.com/redhat-actions/buildah-build/issues/90#issuecomment-1500807385
24+
container:
25+
image: quay.io/buildah/stable:latest
26+
options: --privileged
2027

2128
steps:
29+
2230
- uses: actions/checkout@v3
31+
with:
32+
path: cli-cpp
33+
34+
- name: Install dependencies
35+
run: |
36+
sudo dnf install -y perl podman qemu-user-static gawk
2337
2438
# https://www.integralist.co.uk/posts/github-actions/
2539
- name: Prepare ref name
@@ -28,8 +42,34 @@ jobs:
2842
ref_name=$(echo ${{ github.ref_name }} | perl -pe 's/[^a-zA-Z0-9]+/-/g' | perl -pe 's/(\A-|-\Z)//g' | awk '{print tolower($0)}')
2943
echo "ref_name=${ref_name}" >> $GITHUB_OUTPUT
3044
45+
- name: Initialize ccache
46+
run: mkdir -p "${{ env.CCACHE_DIR }}"
47+
48+
- name: Log in to ghcr.io
49+
run: echo "${{ secrets.GITHUB_TOKEN }}" | buildah login ghcr.io --username="${{ github.actor }}" --password-stdin
50+
51+
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
52+
- name: Prepare registry cache vars
53+
id: cache
54+
run: |
55+
echo "cache-from=--cache-from=ghcr.io/${{ github.repository_owner }}/cli-cpp/buildah-cache" >> $GITHUB_OUTPUT
56+
# don't pollute cache by output from pull request builds
57+
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
58+
echo "cache-to=--cache-to=ghcr.io/${{ github.repository_owner }}/cli-cpp/buildah-cache" >> $GITHUB_OUTPUT
59+
fi
60+
3161
- name: Set up QEMU
32-
uses: docker/setup-qemu-action@v2
62+
run: podman run --privileged --rm docker.io/tonistiigi/binfmt --install all
63+
64+
- name: Cache CCACHE_DIR (restore)
65+
uses: actions/cache/restore@v3
66+
id: restore-ccache-cache
67+
with:
68+
path: "${{ env.CCACHE_DIR }}"
69+
key: ${{ runner.os }}-ccache-${{ matrix.os }}-${{ github.sha }}
70+
restore-keys: |
71+
${{ runner.os }}-ccache-${{ matrix.os }}-
72+
${{ runner.os }}-ccache-
3373
3474
- name: Build Image
3575
id: build-image
@@ -38,8 +78,19 @@ jobs:
3878
image: ${{ env.IMAGE_NAME }}
3979
tags: latest ${{ github.sha }} ${{ steps.cleaned_ref_name.outputs.ref_name }}
4080
archs: amd64, arm64, arm64, s390x
41-
containerfiles: |
42-
./Dockerfile
81+
layers: true
82+
extra-args: |
83+
--volume=${{ env.CCACHE_DIR }}:/ccache
84+
${{ steps.cache.outputs.cache-from }}
85+
${{ steps.cache.outputs.cache-to }}
86+
context: cli-cpp
87+
containerfiles: cli-cpp/Dockerfile
88+
89+
- name: Cache CCACHE_DIR (save)
90+
uses: actions/cache/save@v3
91+
with:
92+
path: "${{ env.CCACHE_DIR }}"
93+
key: ${{ steps.restore-ccache-cache.outputs.cache-primary-key }}
4394

4495
- name: Push To quay.io
4596
if: github.ref == 'refs/heads/main'

Dockerfile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ARG UBI_RUNTIME_TAG=latest
55
ARG IMAGE_BUILD=registry.access.redhat.com/ubi${UBI_VERSION}/ubi-minimal:${UBI_TAG}
66
ARG IMAGE_BASE=registry.access.redhat.com/ubi${UBI_VERSION}/ubi-minimal:${UBI_RUNTIME_TAG}
77

8+
# Build this with something like buildah bud --arch arm64 --volume=/tmp/ccache:/ccache
9+
810
#DEV FROM $IMAGE_BUILD
911
FROM quay.io/centos/centos:stream9 as build
1012

@@ -16,7 +18,7 @@ RUN /usr/bin/crb enable
1618
RUN curl -L https://copr.fedorainfracloud.org/coprs/kpvdr/opentelemetry-cpp/repo/epel-9/kpvdr-opentelemetry-cpp-epel-9.repo > /etc/yum.repos.d/kpvdr-opentelemetry-cpp-epel-9.repo
1719

1820
RUN dnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
19-
findutils git patchelf \
21+
ccache findutils git patchelf \
2022
\
2123
cmake ninja-build \
2224
gcc gcc-c++ \
@@ -29,24 +31,33 @@ RUN dnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
2931
COPY . /src
3032
WORKDIR /src
3133

34+
# can't put $(arch) to CCACHE_DIR, https://github.com/moby/moby/issues/29110
35+
# ENV CCACHE_DIR=
36+
ENV CCACHE_COMPRESS=true
37+
ENV CCACHE_MAXSIZE=400MB
38+
3239
RUN git clone --depth=1 https://github.com/apache/qpid-proton.git
33-
RUN cmake -S qpid-proton -B cmake-build-qpid-proton -GNinja \
40+
RUN CCACHE_DIR=/ccache/$(arch) cmake -S qpid-proton -B cmake-build-qpid-proton -GNinja \
41+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
42+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
3443
-DCMAKE_INSTALL_PREFIX=cmake-install \
3544
-DBUILD_BINDINGS=cpp \
3645
-DBUILD_EXAMPLES=OFF \
3746
-DBUILD_TESTING=OFF \
3847
-DSASL_IMPL=cyrus \
3948
-DSSL_IMPL=openssl \
4049
-DPROACTOR=epoll
41-
RUN cmake --build cmake-build-qpid-proton
42-
RUN cmake --install cmake-build-qpid-proton --config RelWithDebInfo
50+
RUN CCACHE_DIR=/ccache/$(arch) cmake --build cmake-build-qpid-proton
51+
RUN CCACHE_DIR=/ccache/$(arch) cmake --install cmake-build-qpid-proton --config RelWithDebInfo
4352

44-
RUN cmake -S . -B cmake-build-cli-cpp -GNinja \
53+
RUN CCACHE_DIR=/ccache/$(arch) cmake -S . -B cmake-build-cli-cpp -GNinja \
54+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
55+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
4556
-DCMAKE_INSTALL_PREFIX=cmake-install
4657
#-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE \
4758
#-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE
48-
RUN cmake --build cmake-build-cli-cpp
49-
RUN cmake --install cmake-build-cli-cpp --config RelWithDebInfo
59+
RUN CCACHE_DIR=/ccache/$(arch) cmake --build cmake-build-cli-cpp
60+
RUN CCACHE_DIR=/ccache/$(arch) cmake --install cmake-build-cli-cpp --config RelWithDebInfo
5061

5162
# fixup finding the proton library, this is something that our build should handle by itself, though
5263
RUN for i in cmake-install/bin/*; do patchelf --add-rpath /usr/local/lib64 $i; done

0 commit comments

Comments
 (0)