Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ jobs:
- name: Build base image
if: ${{ matrix.has_base }}
run: |
cd ${{ matrix.image }} && ./build.sh
LAYERS_DIR="${{ runner.temp }}/layers/${{ matrix.image }}" ${{ matrix.image }}/build.sh
- name: Build and push
uses: docker/build-push-action@v7
with:
context: "${{ matrix.image }}"
build-contexts: ${{ matrix.has_base && format('base=oci-layout://{0}/layers:base', matrix.image) || '' }}
build-contexts: ${{ matrix.has_base && format('base=oci-layout://{0}/layers/{1}:base', runner.temp, matrix.image) || '' }}
tags: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }}:latest
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }}:latest
cache-to: type=inline
Expand Down
1 change: 0 additions & 1 deletion bazel/.dockerignore

This file was deleted.

1 change: 0 additions & 1 deletion bazel/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/*.tar
/layers
4 changes: 3 additions & 1 deletion bazel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ FROM ghcr.io/toktok/bazel:base AS base
FROM scratch
# hadolint ignore=DL3022,DL3067
COPY --from=base / /
# Reinstate the CMD directive from the squashed image.
# Reinstate the CMD and STOPSIGNAL directives from the squashed image so
# `docker stop` shuts systemd down cleanly instead of waiting for SIGKILL.
CMD ["/usr/sbin/init"]
STOPSIGNAL SIGRTMIN+3

# We need to know where our bash is, because we haven't set up /bin/sh yet.
ENV NIXOS_VERSION="2786a2a72088ecf32aea5b3ec52099e6a7cff78f"
Expand Down
16 changes: 13 additions & 3 deletions bazel/arion-compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ in
boot.specialFileSystems = lib.mkForce { };
boot.tmp.useTmpfs = true;
nix.settings.sandbox = false;
nix.settings.auto-optimise-store = true;

# Avoid /nix/store/.links: in Docker overlay2 it saves 1%.
nix.settings.auto-optimise-store = false;

# TokTok's binary cache, so builds whose results aren't on
# cache.nixos.org (Android cross GHCs and NDKs above all) don't have
# to start again after every container restart.
nix.settings.extra-substituters = [ "https://toktok.cachix.org" ];
nix.settings.extra-trusted-public-keys = [
"toktok.cachix.org-1:ZijcpD+vG99+1uX65TlXaROvLqP//CGCiFlB5OrIGXY="
];

services.journald.settings.Journal = {
ForwardToConsole = true;
Expand All @@ -52,7 +62,7 @@ in
services.openssh.enable = true;
services.nscd.enable = false;

system.stateVersion = "25.11";
system.stateVersion = "26.11";
system.nssModules = lib.mkForce [ ];

systemd.services.systemd-logind.enable = false;
Expand All @@ -73,7 +83,7 @@ in
pkgs.git
# Needed because coursier (for Kotlin) requires that java is in $PATH.
pkgs.jdk21_headless
pkgs.python311
pkgs.python3
];

security.sudo.wheelNeedsPassword = false;
Expand Down
20 changes: 15 additions & 5 deletions bazel/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@

set -eux

# Everything goes in a temporary directory, not the checkout, which may be on a
# slow network file system. LAYERS_DIR, if set, is where the base image goes as
# an OCI layout, for builds that can't read the local docker images (buildx).
SRC="$(cd "$(dirname "$0")" && pwd)"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
cd "$WORK"

# Install nix if it's not there yet (e.g. on Github Actions).
if ! which nix-shell; then
curl -L https://nixos.org/nix/install -o install.sh
sh install.sh --no-daemon --no-channel-add --yes
rm install.sh
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
nix-channel --add https://github.com/NixOS/nixpkgs/archive/2786a2a72088ecf32aea5b3ec52099e6a7cff78f.tar.gz nixpkgs
nix-channel --update
fi

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

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

mkdir layers
docker save "ghcr.io/toktok/bazel:base" | tar -x -C layers
if [ "${LAYERS_DIR:-}" != "" ]; then
mkdir -p "$LAYERS_DIR"
docker save "ghcr.io/toktok/bazel:base" | tar -x -C "$LAYERS_DIR"
fi
Loading