aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-11-23 10:19:19 +0100
committerWojtek Kosior <koszko@koszko.org>2022-11-23 10:20:33 +0100
commitb3e66d97993318e91c0ff634fec62978f6530785 (patch)
treed3f1be83a44315588cc98bc02332beb8fcaa02c6
parentf62c989e9a3dd9a25c288ecde38ad234aee63e4e (diff)
downloadkoszko-org-server-b3e66d97993318e91c0ff634fec62978f6530785.tar.gz
koszko-org-server-b3e66d97993318e91c0ff634fec62978f6530785.zip
facilitate starting a test container without using `mount` to create the host directories container expects to exist
-rw-r--r--.gitmodules3
-rw-r--r--Makefile35
-rwxr-xr-xguix-container.sh16
-rwxr-xr-xrun-with-fake-mounts.sh24
m---------subrepos/hydrilla-website0
5 files changed, 37 insertions, 41 deletions
diff --git a/.gitmodules b/.gitmodules
index 7216302..06004a1 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -7,3 +7,6 @@
[submodule "koszko-org-website"]
path = subrepos/koszko-org-website
url = ../koszko-org-website
+[submodule "hydrilla-website"]
+ path = subrepos/hydrilla-website
+ url = ../hydrilla-website
diff --git a/Makefile b/Makefile
index 9c02eec..79a1133 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,10 @@ GUIX_SHELL = $(GUIX_TM) shell
KOSZKO_ORG_WEBSITE_INFO = \
subrepos/koszko-org-website/src/koszko_org_website.egg-info/PKG-INFO
-LOGDIR = "/tmp/$$(pwd | sed 's|/|!|g')!log"
+TEST_ROOT_DIR = "/tmp/$$(pwd | sed 's|/|!|g')!!test-root"
+TEST_WWW_DIR=$(TEST_ROOT_DIR)/var/www
+TEST_ALL_LOGS_DIR = $(TEST_ROOT_DIR)/var/log
+TEST_LOG_DIR = $(TEST_ALL_LOGS_DIR)/guix-container
all: | container-runner.touchfile log
@@ -45,18 +48,31 @@ hosts: hosts-extra /etc/hosts
cat $^ > $@
log:
- ln -sf $(LOGDIR) $@
+ ln -sf $(TEST_LOG_DIR) $@
-start-container: guix-container.sh container-runner.touchfile | log
- unshare --mount ./run-with-fake-mounts.sh $(LOGDIR) \
- ./$< start -e ./container-runner -p ./pidfile -l $(LOGDIR)
+prepare-test-root:
+ rm -rf $(TEST_ROOT_DIR)
+ @# Prepare replacement `/var/www`
+ mkdir -p $(TEST_WWW_DIR)/koszko.org/html
+ printf ':D\n' > $(TEST_WWW_DIR)/koszko.org/html/index.html
+ @# Prepare replacement `/var/log`
+ mkdir -p $(TEST_ALL_LOGS_DIR)
+
+GUIX_CONTAINER_FLAGS = \
+ -e ./container-runner -p ./pidfile \
+ -l $(TEST_LOG_DIR) \
+ -w $(TEST_WWW_DIR)
+
+start-container: guix-container.sh container-runner.touchfile \
+ prepare-test-root | log
+ ./$< start $(GUIX_CONTAINER_FLAGS)
stop-container: guix-container.sh
- ./$< stop -e ./container-runner -p ./pidfile
+ ./$< stop $(GUIX_CONTAINER_FLAGS)
-restart-container: guix-container.sh container-runner.touchfile | log
- unshare --mount ./run-with-fake-mounts.sh $(LOGDIR) \
- ./$< restart -e ./container-runner -p ./pidfile -l $(LOGDIR)
+restart-container: guix-container.sh container-runner.touchfile \
+ prepare-test-root | log
+ ./$< restart $(GUIX_CONTAINER_FLAGS)
enter-container: pidfile
nsenter -a -t "$$(cat pidfile)" \
@@ -86,6 +102,7 @@ clean: clean-runner
.PHONY: all \
clean-runner clean \
+ prepare-test-root \
start-container stop-container restart-container \
enter-container fake-client \
install reinstall \
diff --git a/guix-container.sh b/guix-container.sh
index 9218a54..f844b5d 100755
--- a/guix-container.sh
+++ b/guix-container.sh
@@ -27,18 +27,20 @@ fi
PIDFILE=/run/guix-container.pid
EXECUTABLE=/usr/local/bin/guix-container
LOG_DIR=/var/log/guix-container
+WWW_DIR=/var/www
MAX_CONTAINER_SPINUP_WAIT=60
ACTION="$1"
shift
OPTIND=1
-while getopts qe:p:l:L: OPTION_LETTER ; do
+while getopts p:e:l:w:s: OPTION_LETTER ; do
case "$OPTION_LETTER" in
p) PIDFILE="$OPTARG" ;;
e) EXECUTABLE="$OPTARG" ;;
l) LOG_DIR="$OPTARG" ;;
- w) MAX_CONTAINER_SPINUP_WAIT="$OPTARG" ;;
+ w) WWW_DIR="$OPTARG" ;;
+ s) MAX_CONTAINER_SPINUP_WAIT="$OPTARG" ;;
esac
done
@@ -79,14 +81,12 @@ onexit() {
}
start() {
- KOSZKO_SIDELOAD_REAL=/var/www/koszko.org/html
- KOSZKO_SIDELOAD_INSIDE=/srv/http/koszko.org
+ KOSZKO_SIDELOAD_REAL="$WWW_DIR"/koszko.org/html
LOG_REAL="$LOG_DIR"/container
- LOG_INSIDE=/var/log
- HTTP_DIR_SHARE_OPT=--share="$KOSZKO_SIDELOAD_REAL"="$KOSZKO_SIDELOAD_INSIDE"
- LOG_DIR_SHARE_OPT=--share="$LOG_REAL"="$LOG_INSIDE"
- mkdir -p "$(dirname "$LOG_DIR")"
+ HTTP_DIR_SHARE_OPT=--share="$KOSZKO_SIDELOAD_REAL"=/srv/http/koszko.org
+ LOG_DIR_SHARE_OPT=--share="$LOG_REAL"=/var/log
+
mkdir --mode=700 -p "$LOG_DIR"
mkdir --mode=700 -p "$LOG_DIR"/container
diff --git a/run-with-fake-mounts.sh b/run-with-fake-mounts.sh
deleted file mode 100755
index 57b3078..0000000
--- a/run-with-fake-mounts.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-# SPDX-License-Identifier: CC0-1.0
-
-# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
-#
-# Available under the terms of Creative Commons Zero v1.0 Universal.
-
-set -e
-
-LOGDIR="$1"
-
-shift
-
-mkdir -p /var/www
-mount -t tmpfs dummy /var/www
-mkdir -p /var/www/koszko.org/html
-
-rm -rf "$LOGDIR"
-mkdir -p "$LOGDIR"
-
-printf ':D\n' > /var/www/koszko.org/html/index.html
-
-"$@"
diff --git a/subrepos/hydrilla-website b/subrepos/hydrilla-website
new file mode 160000
+Subproject e5d9ee98a548e2b863104e52eb2bc309b133617