-
Notifications
You must be signed in to change notification settings - Fork 25
ROX-26272 Enable ccache for faster builds #1838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robbycochran
wants to merge
12
commits into
master
Choose a base branch
from
rc-ccache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d441fd3
X-Smart-Branch-Parent: origin/master
robbycochran 82d352f
X-Smart-Squash: Squashed 50 commits:
robbycochran 5479a24
create ccache dir on remote for collector build
robbycochran 6366dc3
key names
robbycochran 1693602
fmt
robbycochran b8980b7
key
robbycochran 770f8c3
label
robbycochran 72a9257
fmt
robbycochran 56fe902
optional steps
robbycochran abdf93a
debug ansible
robbycochran 7f13405
fmt
robbycochran 4f69acf
fix
robbycochran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ env: | |
COLLECTOR_TAG: ${{ inputs.collector-tag }} | ||
DEFAULT_BUILDER_TAG: master | ||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible/ansible.cfg | ||
USE_CCACHE: ${{ !contains(github.event.pull_request.labels.*.name, 'no-ccache') }} | ||
|
||
jobs: | ||
builder-needs-rebuilding: | ||
|
@@ -74,6 +75,24 @@ jobs: | |
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Set up builder ccache | ||
if: env.USE_CCACHE | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ github.workspace }}/builder/.ccache | ||
key: builder-ccache-${{ matrix.arch }}-${{ github.sha }} | ||
restore-keys: | | ||
builder-ccache-${{ matrix.arch }}- | ||
|
||
- name: Set up builder ccache in docker cache | ||
if: env.USE_CCACHE && matrix.arch != 's390x' | ||
uses: reproducible-containers/buildkit-cache-dance@v3.1.2 | ||
with: | ||
cache-map: | | ||
{ | ||
"${{ github.workspace }}/builder/.ccache": "/root/.ccache" | ||
} | ||
Comment on lines
+87
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you had to implement the logic that this action provides for s390x, I wonder if it makes sense to just handle all archs the same way in our ansible playbooks and drop this step, mostly for consistency, this approach is fine. |
||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
@@ -128,6 +147,7 @@ jobs: | |
echo "rhacs_eng_password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}" | ||
echo "collector_git_ref: ${{ github.ref }}" | ||
echo "collector_builder_tag: ${{ env.COLLECTOR_BUILDER_TAG }}" | ||
echo "use_ccache: ${{ env.USE_CCACHE }}" | ||
} > ${{ github.workspace }}/ansible/secrets.yml | ||
|
||
- name: Build images | ||
|
@@ -156,6 +176,7 @@ jobs: | |
-i ansible/ci \ | ||
-e build_hosts='job_id_${{ env.JOB_ID }}' \ | ||
-e arch='${{ matrix.arch }}' \ | ||
-e github_workspace='${{ github.workspace }}' \ | ||
-e @'${{ github.workspace }}/ansible/secrets.yml' \ | ||
ansible/ci-build-builder.yml | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
.idea/ | ||
.rox/ | ||
.ccache/ | ||
builder/.ccache/ | ||
|
||
integration-tests/container-logs/ | ||
integration-tests/*.log | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
# based on https://github.com/reproducible-containers/buildkit-cache-dance | ||
|
||
set -e | ||
|
||
usage() { | ||
echo "Usage: $0 <cache_destination_directory> <target_path_inside_container>" | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne 2 ]; then | ||
usage | ||
fi | ||
|
||
CACHE_DEST="$1" | ||
TARGET_PATH="$2" | ||
|
||
CCACHE_ARCHIVE="docker.tar.gz" | ||
|
||
SCRATCH_DIR=$(mktemp -d) | ||
SCRATCH_ARCHIVE=$(mktemp) | ||
# shellcheck disable=SC2064 | ||
trap "rm -rf ${SCRATCH_DIR}; rm -f ${SCRATCH_ARCHIVE}" EXIT | ||
|
||
# Timestamp to bust cache | ||
date -Iseconds > "${SCRATCH_DIR}/buildstamp" | ||
|
||
cat << EOF > "${SCRATCH_DIR}/Dockerfile.extract" | ||
FROM busybox:1 | ||
COPY buildstamp buildstamp | ||
RUN --mount=type=cache,target=${TARGET_PATH} \\ | ||
mkdir -p /var/docker-cache/ \\ | ||
&& cp -p -R ${TARGET_PATH}/. /var/docker-cache/ || true | ||
EOF | ||
|
||
echo "Generated Dockerfile.extract" | ||
cat "${SCRATCH_DIR}/Dockerfile.extract" | ||
|
||
# Build the image and load it into Docker | ||
docker buildx build -f "${SCRATCH_DIR}/Dockerfile.extract" --tag cache:extract --load "${SCRATCH_DIR}" | ||
docker images | ||
|
||
# Remove any existing cache-container | ||
docker rm -f cache-container || true | ||
|
||
# Create a container from cache:extract | ||
docker create --name cache-container cache:extract | ||
docker ps | ||
|
||
# Extract the cache from the container | ||
docker cp -L cache-container:/var/docker-cache - | tar -H posix -x -C "${SCRATCH_DIR}" | ||
ls "${SCRATCH_DIR}" | ||
|
||
# Compress the cache from the container | ||
(cd "${SCRATCH_DIR}/docker-cache" && chmod -R 777 . && tar czf "${SCRATCH_ARCHIVE}" .) | ||
|
||
# Move the cache into its dest | ||
rm -f "${CACHE_DEST}/${CCACHE_ARCHIVE}" | ||
mv "${SCRATCH_ARCHIVE}" "${CACHE_DEST}/${CCACHE_ARCHIVE}" | ||
chmod 666 "${CACHE_DEST}/${CCACHE_ARCHIVE}" | ||
|
||
echo "Docker cache extraction completed successfully." |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to run with ccache on the master branch and nightlies? That way PRs could just pull the cache from there and see a speed up from the very first commit that gets pushed, otherwise the first build will be as slow as the ones we have now. Maybe we can check if the branch being used is
master
somewhere in our build and clean the cache before building? That way the master branch would always be built from a clean slate, but the cache would still be provided for PRs.https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#example-of-search-priority
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good idea. We could skip cache restore on master but always save the cache.