Commit 02e4b70b authored by Profpatsch's avatar Profpatsch

containers/rabbitmq: first working version

Getting this to run was quite hard, but finally it does work.
parent 248eb510
let
lib = import <nixpkgs/lib>;
# evaluate the deployment config
eval = import <nixpkgs/nixos> {
configuration = { lib, ... }: {
configuration = { ... }: {
imports = [
./modules/docker-images.nix
./postgres.nix
./rabbitmq.nix
];
config = {
org.techcultivation.deploy.database.buildDockerImage = true;
org.techcultivation.deploy.queue.buildDockerImage = true;
# our own packages
nixpkgs.overlays = [(self: _: {
......@@ -29,9 +32,9 @@ let
# TODO tmp
sanghaPostgresTemplate = eval.config.passthru;
# generated docker image for the sangha postgres server
sanghaPostgresDockerImage = pkgs.runCommand "sangha-docker-image" rec {
image = eval.config.generated.dockerImages.sanghaPostgres;
# make docker image suitable for download from Hydra
buildHydraDockerImage = image: pkgs.runCommand "sangha-docker-image" {
inherit image;
passthru.meta = image.meta;
}
# produces an output link for hydra
......@@ -41,13 +44,15 @@ let
> "$out/nix-support/hydra-build-products"
'';
in {
pkgs = {
inherit (pkgs) sangha;
inherit sanghaPostgresTemplate;
};
downloads.dockerImages = {
sangha.postgres = sanghaPostgresDockerImage;
downloads.dockerImages.sangha = lib.mapAttrs (lib.const buildHydraDockerImage) {
postgres = eval.config.generated.dockerImages.sanghaPostgres;
rabbitmq = eval.config.generated.dockerImages.sanghaRabbitmq;
};
tests = eval.config.tests;
}
......@@ -171,9 +171,7 @@ in {
virtualisation.docker.enable = true;
networking.firewall.enable = false;
};
client = {
# TODO
};
client = { };
};
testScript =
......
{ lib, pkgs, config, testing, ... }:
let
in {
## module options for queue deployment
options.org.techcultivation.deploy.queue = {
enable = lib.mkEnableOption "queue container";
buildDockerImage = lib.mkEnableOption "queue container docker image";
};
## option implementation
config =
let
nixosConfig = {
# TODO
};
dockerConfig =
let
uidGid = 999;
uidGidStr = toString uidGid;
dockerCmd = "/bin/rabbitmq-server";
port = 5672;
description = "TODO";
dockerImage =
let
# The erlang closure is giant by default;
# rabbitmq doesn’t need most of it.
# see https://github.com/rabbitmq/erlang-rpm
# It still compiles some OTP libraries like wx,
# that could be removed (~30–40M).
rabbitmq_server-minimal = pkgs.rabbitmq_server.override {
erlang = pkgs.erlang.override {
javacSupport = false;
odbcSupport = false;
wxSupport = false;
# prevent doc generation (>100M)
installTargets = ["install"];
};
};
baseImage = pkgs.dockerTools.buildImage {
name = "sangha-rabbitmq-base";
tag = "unstable";
contents = [
rabbitmq_server-minimal
# only needed by the /bin/rabbitmq-env script,
# 11M that can probably be avoided
pkgs.coreutils
pkgs.gnused
];
};
# Make a generated docker image debuggable,
# by including bash and coreutils.
# `docker run -it <image>`
debug = image: pkgs.dockerTools.buildImage {
name = image.imageName;
tag = image.imageTag;
fromImage = image;
contents = [
pkgs.strace
pkgs.bash
pkgs.coreutils
pkgs.su-exec
];
inherit (image.buildArgs) config;
};
image = pkgs.dockerTools.buildImage {
name = "sangha-rabbitmq";
tag = "unstable";
fromImage = baseImage;
config = {
User = "rabbitmq";
Cmd = [ "rabbitmq-server" ];
Env = [
# logs to stdout
"RABBITMQ_LOGS=-"
"RABBITMQ_SASL_LOGS=-"
# "RABBITMQ_LOG_BASE=/var/log/rabbitmq"
"HOME=/var/lib/rabbitmq"
];
ExposedPorts."${toString port}/tcp" = {};
};
runAsRoot = ''
${pkgs.stdenv.shell}
${pkgs.dockerTools.shadowSetup}
# some needed system structure
umask 022
mkdir /tmp
mkdir -p /var/lib
echo "rabbitmq::${uidGidStr}:${uidGidStr}::::" > /etc/passwd
echo "127.0.0.1 localhost" > /etc/hosts
echo "hosts: files" > /etc/nsswitch.conf
# rabbit setup
mkdir -p /var/lib/rabbitmq/mnesia
# /var/log/rabbitmq
chown --recursive ${uidGidStr}:${uidGidStr} /var/lib/rabbitmq
# chown --recursive ${uidGidStr}:${uidGidStr} /var/log/rabbitmq
# add a symlink to the .erlang.cookie in /root so we can "docker exec rabbitmqctl ..." without gosu
mkdir /root
ln -sf /var/lib/rabbitmq/.erlang.cookie /root/
'';
};
# in image.overrideAttrs (_: {
# meta = { inherit description; };
# });
in image;
in {
generated.dockerImages.sanghaRabbitmq = dockerImage;
};
in
let
cfg = config.org.techcultivation.deploy.queue;
in
lib.mkMerge [
(lib.mkIf cfg.enable nixosConfig)
(lib.mkIf cfg.buildDockerImage dockerConfig)
];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment