Skip to content

Commit 785f7dc

Browse files
committed
fix: Speed up nix package stuff in bazel image a bit.
1 parent 7d7e16a commit 785f7dc

6 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎.github/workflows/docker.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ jobs:
5454
- name: Build base image
5555
if: ${{ matrix.has_base }}
5656
run: |
57-
cd ${{ matrix.image }} && ./build.sh
57+
LAYERS_DIR="${{ runner.temp }}/layers/${{ matrix.image }}" ${{ matrix.image }}/build.sh
5858
- name: Build and push
5959
uses: docker/build-push-action@v7
6060
with:
6161
context: "${{ matrix.image }}"
62-
build-contexts: ${{ matrix.has_base && format('base=oci-layout://{0}/layers:base', matrix.image) || '' }}
62+
build-contexts: ${{ matrix.has_base && format('base=oci-layout://{0}/layers/{1}:base', runner.temp, matrix.image) || '' }}
6363
tags: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }}:latest
6464
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }}:latest
6565
cache-to: type=inline

‎bazel/.dockerignore‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎bazel/.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/*.tar
2-
/layers

‎bazel/Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ FROM ghcr.io/toktok/bazel:base AS base
33
FROM scratch
44
# hadolint ignore=DL3022,DL3067
55
COPY --from=base / /
6-
# Reinstate the CMD directive from the squashed image.
6+
# Reinstate the CMD and STOPSIGNAL directives from the squashed image so
7+
# `docker stop` shuts systemd down cleanly instead of waiting for SIGKILL.
78
CMD ["/usr/sbin/init"]
9+
STOPSIGNAL SIGRTMIN+3
810

911
# We need to know where our bash is, because we haven't set up /bin/sh yet.
1012
ENV NIXOS_VERSION="2786a2a72088ecf32aea5b3ec52099e6a7cff78f"

‎bazel/arion-compose.nix‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ in
4343
boot.specialFileSystems = lib.mkForce { };
4444
boot.tmp.useTmpfs = true;
4545
nix.settings.sandbox = false;
46-
nix.settings.auto-optimise-store = true;
46+
47+
# Avoid /nix/store/.links: in Docker overlay2 it saves 1%.
48+
nix.settings.auto-optimise-store = false;
49+
50+
# TokTok's binary cache, so builds whose results aren't on
51+
# cache.nixos.org (Android cross GHCs and NDKs above all) don't have
52+
# to start again after every container restart.
53+
nix.settings.extra-substituters = [ "https://toktok.cachix.org" ];
54+
nix.settings.extra-trusted-public-keys = [
55+
"toktok.cachix.org-1:ZijcpD+vG99+1uX65TlXaROvLqP//CGCiFlB5OrIGXY="
56+
];
4757

4858
services.journald.settings.Journal = {
4959
ForwardToConsole = true;
@@ -52,7 +62,7 @@ in
5262
services.openssh.enable = true;
5363
services.nscd.enable = false;
5464

55-
system.stateVersion = "25.11";
65+
system.stateVersion = "26.11";
5666
system.nssModules = lib.mkForce [ ];
5767

5868
systemd.services.systemd-logind.enable = false;
@@ -73,7 +83,7 @@ in
7383
pkgs.git
7484
# Needed because coursier (for Kotlin) requires that java is in $PATH.
7585
pkgs.jdk21_headless
76-
pkgs.python311
86+
pkgs.python3
7787
];
7888

7989
security.sudo.wheelNeedsPassword = false;

‎bazel/build.sh‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22

33
set -eux
44

5+
# Everything goes in a temporary directory, not the checkout, which may be on a
6+
# slow network file system. LAYERS_DIR, if set, is where the base image goes as
7+
# an OCI layout, for builds that can't read the local docker images (buildx).
8+
SRC="$(cd "$(dirname "$0")" && pwd)"
9+
WORK="$(mktemp -d)"
10+
trap 'rm -rf "$WORK"' EXIT
11+
cd "$WORK"
12+
513
# Install nix if it's not there yet (e.g. on Github Actions).
614
if ! which nix-shell; then
715
curl -L https://nixos.org/nix/install -o install.sh
816
sh install.sh --no-daemon --no-channel-add --yes
9-
rm install.sh
1017
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
1118
nix-channel --add https://github.com/NixOS/nixpkgs/archive/2786a2a72088ecf32aea5b3ec52099e6a7cff78f.tar.gz nixpkgs
1219
nix-channel --update
1320
fi
1421

1522
# Build a docker image.
16-
nix-shell -p arion --run 'arion build'
17-
IMAGE="$(nix-shell -p arion --run 'arion config' | grep -o 'ghcr.io/toktok/bazel:.*')"
23+
ARION="arion --file $SRC/arion-compose.nix --pkgs $SRC/arion-pkgs.nix"
24+
nix-shell -p arion --run "$ARION build"
25+
IMAGE="$(nix-shell -p arion --run "$ARION config" | grep -o 'ghcr.io/toktok/bazel:.*')"
1826

1927
docker tag "$IMAGE" "ghcr.io/toktok/bazel:base"
2028

21-
mkdir layers
22-
docker save "ghcr.io/toktok/bazel:base" | tar -x -C layers
29+
if [ -n "${LAYERS_DIR:-}" ]; then
30+
mkdir -p "$LAYERS_DIR"
31+
docker save "ghcr.io/toktok/bazel:base" | tar -x -C "$LAYERS_DIR"
32+
fi

0 commit comments

Comments
 (0)