blob: de427db654b089e31e4c75479105159e8fd854ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
{ pkgs, self }:
let
version = "unstable";
shortSHA = self.shortRev or self.dirtyShortRev;
fullSHA = self.rev or self.dirtyRev;
mkDocker = type: { server, website }:
let
PORT = 80;
in
pkgs.dockerTools.${type} {
name = "registry.fly.io/alanpearce-eu";
tag = fullSHA;
contents = [
(pkgs.writeTextDir "config.toml" (builtins.readFile ./../config.toml))
website
];
config = {
Cmd = [ "${server}/bin/server" ];
Env = [
"PRODUCTION=true"
"LISTEN_ADDRESS=::"
"PORT=${builtins.toString PORT}"
];
ExposedPorts = {
"${builtins.toString PORT}/tcp" = { };
};
};
};
mkDockerStream = mkDocker "streamLayeredImage";
mkDockerImage = mkDocker "buildLayeredImage";
in
with pkgs; rec {
default = server;
builder = buildGoApplication {
pname = "website-builder";
inherit version;
CGO_ENABLED = 0;
src = with lib.fileset; toSource {
root = ./..;
fileset = unions [
./../go.mod
./../go.sum
./../cmd/build
./../internal
];
};
modules = ./gomod2nix.toml;
subPackages = [ "cmd/build" ];
};
website = runCommandLocal "build"
{
src = with lib.fileset; toSource {
root = ./..;
fileset = unions [
./../config.toml
./../content
./../static
./../templates
];
};
} ''
${builder}/bin/build -s $src -d $out/website
'';
server = buildGoApplication {
pname = "server";
inherit version;
CGO_ENABLED = 0;
src = with lib.fileset; toSource {
root = ./..;
fileset = unions [
./../go.mod
./../go.sum
./../cmd/server
./../internal
];
};
modules = ./gomod2nix.toml;
subPackages = [ "cmd/server" ];
ldflags = [
"-s"
"-w"
"-X"
"website/internal/server.CommitSHA=${fullSHA}"
"-X"
"website/internal/server.ShortSHA=${shortSHA}"
];
};
docker-stream = mkDockerStream { inherit server website; };
docker-stream-aarch64-linux = mkDockerStream {
inherit website; server = (self.packages.aarch64-linux.server);
};
docker-stream-x86_64-linux = mkDockerStream {
inherit website; server = (self.packages.x86_64-linux.server);
};
docker-image = mkDockerImage { inherit server website; };
docker-image-aarch64-linux = mkDockerImage {
inherit website; server = (self.packages.aarch64-linux.server);
};
docker-image-x86_64-linux = mkDockerImage {
inherit website; server = (self.packages.x86_64-linux.server);
};
}
|