commit 4e95a1c0c8d139c6769463f34320f16b75bcb988 Author: Maximilian Güntner Date: Fri Jun 19 17:00:37 2020 +0200 initial commit static docker registry is working diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..be9e9d6 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +./build_containers.sh +./build_registry.py > static_registry/default.nix diff --git a/build_containers.sh b/build_containers.sh new file mode 100755 index 0000000..f98d939 --- /dev/null +++ b/build_containers.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -x +for dir in $(ls static_registry) +do + [ ! -d static_registry/$dir ] && continue + pushd . + echo $dir + cd static_registry/$dir + COMMIT_HASH=$(docker build . | tail -n 1 | cut -d ' ' -f3) + TAG=$(basename $(pwd)):$COMMIT_HASH + docker tag $COMMIT_HASH $TAG + docker save $TAG | gzip > $COMMIT_HASH.tar.gz + popd +done diff --git a/build_registry.py b/build_registry.py new file mode 100755 index 0000000..bc59ac2 --- /dev/null +++ b/build_registry.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +from pathlib import Path + +pathlist = Path("static_registry").glob('**/*.tar.gz') +registry = { +} + +def build_images(name, images): + return '{\n' + "\n".join([ f' {name}_{tag} = {{ image = "${{{image}}}"; tag = "{name}:{tag}"; }};' for tag, image in images.items() ]) + '\n };' + +def build_registry(registry): + return '{\n' + "\n".join([ f' {name} = ' + build_images(name, images) for name, images in registry.items() ]) + '\n}' + +def print_registry(registry): + print(build_registry(registry)) + +for path in pathlist: + name = path.parts[-2] + image = str(path.resolve()) + tag = path.parts[-1].split('.', 1)[0] + if name not in registry: + registry[name] = {} + registry[name][tag] = image +print_registry(registry) diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..c64dacf --- /dev/null +++ b/module.nix @@ -0,0 +1,18 @@ +{ config, lib, ... }: + +with lib; + +let + cfg = config.foo.bar; + +in + +{ + options.foo.bar = { + enable = mkEnableOption "foobar"; + }; + + config = mkIf cfg.enable { + # ... + }; +} diff --git a/static_registry/nginx/Dockerfile b/static_registry/nginx/Dockerfile new file mode 100644 index 0000000..6910b28 --- /dev/null +++ b/static_registry/nginx/Dockerfile @@ -0,0 +1 @@ +FROM nginx:1.19-alpine \ No newline at end of file diff --git a/tests.nix b/tests.nix new file mode 100644 index 0000000..285d9c1 --- /dev/null +++ b/tests.nix @@ -0,0 +1,37 @@ +{ system ? builtins.currentSystem +, pkgs ? import { inherit system; } +}: + +with import { inherit system pkgs; }; + +let + registry = import ./static_registry/default.nix; +in +{ + mytest = makeTest { + machine = { ... }: { + imports = [ ./module.nix ]; + + virtualisation.cores = 4; + virtualisation.memorySize = 1024; + + foo.bar.enable = true; + + docker-containers.nginx = let + image = registry.nginx.nginx_7d0cdcc60a96; + in + { + image = image.tag; + imageFile = image.image; + ports = ["8181:80"]; + }; + }; + + testScript = '' + machine.start() + machine.wait_for_unit("docker-nginx.service") + machine.wait_for_open_port(8181) + machine.wait_until_succeeds("curl http://localhost:8181") + ''; + }; +}