Matthias Andreas Benkard | c058c56 | 2023-01-08 19:04:34 +0100 | [diff] [blame] | 1 | { system ? builtins.currentSystem }: |
| 2 | let |
| 3 | pkgs = import <nixpkgs> { |
| 4 | inherit system; |
| 5 | overlays = [ |
| 6 | (self: super: { |
| 7 | docker = super.docker.override { |
| 8 | iptables = self.iptables-legacy; |
| 9 | }; |
| 10 | }) |
| 11 | ]; |
| 12 | }; |
| 13 | |
| 14 | in |
| 15 | let |
| 16 | img = spec: { |
| 17 | streamed = pkgs.dockerTools.streamLayeredImage spec; |
| 18 | layered = pkgs.dockerTools.buildLayeredImage spec; |
| 19 | image = pkgs.dockerTools.buildImage spec; |
| 20 | }; |
| 21 | |
| 22 | in |
| 23 | let |
| 24 | init = |
| 25 | pkgs.writeShellScriptBin "init" '' |
| 26 | set -xeuo pipefail |
| 27 | |
| 28 | if ! [ -e /vol/docker-data/docker.ext4 ]; then |
| 29 | ${pkgs.busybox}/bin/dd if=/dev/zero of=/vol/docker-data/docker.ext4 bs=1G count=0 seek=30 |
| 30 | ${pkgs.e2fsprogs}/bin/mkfs.ext4 /vol/docker-data/docker.ext4 |
| 31 | fi |
| 32 | ${pkgs.e2fsprogs}/bin/e2fsck -y /vol/docker-data/docker.ext4 |
| 33 | ${pkgs.busybox}/bin/mkdir -p /var/lib/docker |
| 34 | ${pkgs.busybox}/bin/mount -o loop,rw /vol/docker-data/docker.ext4 /var/lib/docker |
| 35 | |
| 36 | ${pkgs.docker}/bin/dockerd --storage-driver=overlay2 & |
| 37 | sleep 10s |
| 38 | |
| 39 | ${pkgs.docker}/bin/docker kill $(${pkgs.docker}/bin/docker ps -a -q) || : |
Matthias Andreas Benkard | 64ba410 | 2023-01-21 21:10:46 +0100 | [diff] [blame] | 40 | ${pkgs.docker}/bin/docker system prune --force || : |
Matthias Andreas Benkard | c058c56 | 2023-01-08 19:04:34 +0100 | [diff] [blame] | 41 | |
| 42 | exec ${pkgs.gitlab-runner}/bin/gitlab-runner run |
| 43 | ''; |
| 44 | |
| 45 | src = ./.; |
| 46 | |
| 47 | extraDeps = with pkgs; [ |
| 48 | # for Docker |
| 49 | cacert |
| 50 | |
| 51 | # for GitLab runner |
| 52 | docker |
| 53 | ]; |
| 54 | |
| 55 | maintenanceDeps = with pkgs; [ |
| 56 | bash |
| 57 | busybox |
| 58 | coreutils |
| 59 | findutils |
| 60 | pxattr |
| 61 | strace |
| 62 | ]; |
| 63 | |
| 64 | in |
| 65 | img { |
| 66 | name = "docker.benkard.de/mulk/gitlab-runner"; |
| 67 | #tag = "latest"; |
| 68 | maxLayers = 125; |
| 69 | contents = extraDeps ++ maintenanceDeps; |
| 70 | extraCommands = |
| 71 | '' |
| 72 | #!${pkgs.runtimeShell} |
| 73 | |
| 74 | install -dm755 etc/gitlab-runner |
| 75 | install -dm755 vol/docker-data |
| 76 | install -dm755 tmp |
| 77 | |
| 78 | cp -a ${src}/* . |
| 79 | ''; |
| 80 | config = { |
| 81 | Entrypoint = [ "${init}/bin/init" ]; |
| 82 | Cmd = [ ]; |
| 83 | Workdir = "/"; |
| 84 | Volumes = { |
| 85 | "/etc/gitlab-runner" = { }; |
| 86 | "/vol/docker-data" = { }; |
| 87 | }; |
| 88 | }; |
| 89 | } |