Skip to content

Instantly share code, notes, and snippets.

@arianvp
Created October 16, 2020 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arianvp/b095eeec5d3cb4ef4dc8c06351884779 to your computer and use it in GitHub Desktop.
Save arianvp/b095eeec5d3cb4ef4dc8c06351884779 to your computer and use it in GitHub Desktop.
{ pkgs, lib, config, ... }:
let
cfg = config.webshop;
in
{
options.webshop = {
website = lib.mkOption {
type = lib.types.package;
description = "The static content to serve";
};
};
config.job.webshop = {
datacenters = [ "dc1" ];
group.webserver = {
network.port.http = {};
task.webserver.nix.script = "cd ${cfg.website} && ${pkgs.python3}/bin/python -m http.server $NOMAD_PORT_http";
};
group.database = {
volume.pgdata = { type = "host"; source = "pgdata"; };
network.port.postgres = {};
task.postgres =
let
pgdata = "/pgdata/pgdata";
in
{
resources.memory = 2000;
volume_mount = [ { volume = "pgdata"; destination = "/pgdata"; } ];
env.PGDATA = pgdata;
nix.script = ''
mkdir -p /alloc/pgtmp
test -e ${pgdata}/PG_VERSION || ${pkgs.postgresql}/bin/initdb --no-locale --encoding=UTF8
exec ${pkgs.postgresql}/bin/postgres -p $NOMAD_PORT_postgres -k /alloc/pgtmp
'';
};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment