Skip to content

Commit

Permalink
ci: cache Guix folders
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 23, 2023
1 parent 6db3c13 commit dfa3c41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 24 additions & 6 deletions .github/workflows/guix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,48 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
path: dash

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Commit variables
id: dockerfile
run: |
echo "hash=$(sha256sum ./contrib/containers/guix/Dockerfile | cut -d ' ' -f1)" >> $GITHUB_OUTPUT
echo "hash=$(sha256sum ${{ github.workspace }}/dash/contrib/containers/guix/Dockerfile | cut -d ' ' -f1)" >> $GITHUB_OUTPUT
echo "host_user_id=$(id -u)" >> $GITHUB_OUTPUT
echo "host_group_id=$(id -g)" >> $GITHUB_OUTPUT
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}
context: ${{ github.workspace }}/dash
build-args: |
USER_ID=${{ steps.dockerfile.outputs.host_user_id }}
GROUP_ID=${{ steps.dockerfile.outputs.host_group_id }}
build-contexts: |
docker_root=${{ github.workspace }}/contrib/containers/guix
file: ./contrib/containers/guix/Dockerfile
docker_root=${{ github.workspace }}/dash/contrib/containers/guix
file: ${{ github.workspace }}/dash/contrib/containers/guix/Dockerfile
load: true
tags: guix_ubuntu:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Restore Guix cache
id: guix-cache-restore
uses: actions/cache/restore@v3
with:
path: |
${{ github.workspace }}/.cache/guix
key: ${{ runner.os }}-guix

- name: Run Guix build
run: |
docker run --privileged -d --rm -t \
--name guix-daemon \
-e ADDITIONAL_GUIX_COMMON_FLAGS="--max-jobs=$(nproc --all)" \
-v ${{ github.workspace }}:/src/dash \
-v ${{ github.workspace }}/dash:/src/dash \
-v ${{ github.workspace }}/.cache/guix:/home/ubuntu/.cache/guix \
-w /src/dash \
guix_ubuntu:latest && \
docker exec guix-daemon bash -c '/usr/local/bin/guix-start'
Expand All @@ -57,6 +67,14 @@ jobs:
exit 1
fi
- name: Save Guix cache
id: guix-cache-save
uses: actions/cache/save@v3
with:
path: |
${{ github.workspace }}/.cache/guix
key: ${{ steps.guix-cache-restore.outputs.cache-primary-key }}

- name: Compute SHA256 checksums
run: |
./contrib/containers/guix/scripts/guix-check ${{ github.workspace }}
${{ github.workspace }}/dash/contrib/containers/guix/scripts/guix-check ${{ github.workspace }}/dash
4 changes: 3 additions & 1 deletion contrib/containers/guix/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ COPY --from=docker_root ./scripts/guix-start /usr/local/bin/guix-start

# Create directory for mounting and grant necessary permissions
RUN mkdir -p /src/dash && \
chown -R ${USER_ID}:${GROUP_ID} /src
mkdir -p /home/${USERNAME}/.cache/guix && \
chown -R ${USER_ID}:${GROUP_ID} /src && \
chown -R ${USER_ID}:${GROUP_ID} /home/${USERNAME}/.cache/guix
WORKDIR "/src/dash"

# Switch to unprivileged context
Expand Down

0 comments on commit dfa3c41

Please sign in to comment.