full deployment via nix

This commit is contained in:
Brian Picciano 2021-08-03 17:47:01 -06:00
parent 8ebf4a26f4
commit 5ca7dadd02
7 changed files with 67 additions and 4 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
result result
config.nix

View File

@ -0,0 +1,4 @@
install:
nix-build -A install
./result

9
config.nix.tpl Normal file
View File

@ -0,0 +1,9 @@
{
powSecret = "";
mlSMTPAddr = "";
mlSMTPAuth = "";
dataDir = ".";
publicURL = "http://localhost:4000";
listenProto = "tcp";
listenAddr = ":4000";
}

43
default.nix Normal file
View File

@ -0,0 +1,43 @@
let
utils = (import ./nix) {};
pkgs = utils.pkgs;
system = utils.system;
in
rec {
srv = (import ./srv).build;
static = (import ./static).build;
config = (import ./config.nix);
service = pkgs.writeText "mediocregopher-mediocre-blog" ''
[Unit]
Description=mediocregopher mediocre blog
Requires=network.target
After=network.target
[Service]
Restart=always
RestartSec=1s
User=mediocregopher
ExecStart=${srv}/bin/mediocre-blog \
-pow-secret "${config.powSecret}" \
-ml-smtp-addr "${config.mlSMTPAddr}" \
-ml-smtp-auth "${config.mlSMTPAuth}" \
-data-dir "${config.dataDir}" \
-public-url "${config.publicURL}" \
-static-dir "${static}" \
-listen-proto "${config.listenProto}" \
-listen-addr "${config.listenAddr}"
[Install]
WantedBy=multi-user.target
'';
install = pkgs.writeScript "mediocregopher-mediocre-blog" ''
set -e -x
sudo cp ${service} /etc/systemd/system/mediocregopher-mediocre-blog.service
sudo systemctl daemon-reload
sudo systemctl enable mediocregopher-mediocre-blog.service
sudo systemctl restart mediocregopher-mediocre-blog.service
'';
}

View File

@ -143,8 +143,8 @@ func main() {
Store: mlStore, Store: mlStore,
Mailer: mailer, Mailer: mailer,
Clock: clock, Clock: clock,
FinalizeSubURL: path.Join(publicURL.String(), "/mailinglist/finalize.html"), FinalizeSubURL: publicURL.String() + "/mailinglist/finalize.html",
UnsubURL: path.Join(publicURL.String(), "/mailinglist/unsubscribe.html"), UnsubURL: publicURL.String() + "/mailinglist/unsubscribe.html",
}) })
mux := http.NewServeMux() mux := http.NewServeMux()
@ -183,6 +183,12 @@ func main() {
loggerFatalErr(ctx, logger, "creating listen socket", err) loggerFatalErr(ctx, logger, "creating listen socket", err)
} }
if *listenProto == "unix" {
if err := os.Chmod(*listenAddr, 0777); err != nil {
loggerFatalErr(ctx, logger, "chmod-ing unix socket", err)
}
}
srv := &http.Server{Handler: mux} srv := &http.Server{Handler: mux}
go func() { go func() {
if err := srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { if err := srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) {

View File

@ -9,7 +9,7 @@ in
pname = "mediocre-blog-srv"; pname = "mediocre-blog-srv";
version = "dev"; version = "dev";
src = ./.; src = ./.;
vendorSha256 = "0xr5gks5mrh34s5npncw71wncrzqrhnm3vjfwdakd7fzd6iw049z"; vendorSha256 = "08wv94yv2wmlxzmanw551gixc8v8nl6zq2m721ig9nl3r540x46f";
}; };
shell = pkgs.stdenv.mkDerivation { shell = pkgs.stdenv.mkDerivation {

View File

@ -114,7 +114,7 @@ func TestManager(t *testing.T) {
c := mgr.NewChallenge() c := mgr.NewChallenge()
solution := Solve(c) solution := Solve(c)
clock.Add(2 * time.Second) clock.Add(2 * time.Second)
assert.ErrorIs(t, mgr.CheckSolution(c.Seed, solution), ErrExpiredSolution) assert.ErrorIs(t, mgr.CheckSolution(c.Seed, solution), ErrExpiredSeed)
} }
} }