Compare commits

...

5 Commits

Author SHA1 Message Date
Jez Cope a7be6d1b37 Teach flake.nix to build website 2021-09-10 21:18:27 +01:00
Jez Cope 1ef1c82b87 Remove yaspin dependency 2021-09-10 19:17:59 +01:00
Jez Cope 972b9ef6be Add .hgignore 2021-09-04 21:26:12 +01:00
Jez Cope b5bf256c9b Remove netlify badge 2021-09-04 21:22:01 +01:00
Jez Cope ab7f933714 Update tasks.py to deploy via rsync 2021-09-04 21:19:05 +01:00
5 changed files with 55 additions and 109 deletions

14
.hgignore Normal file
View File

@ -0,0 +1,14 @@
public
tmp
.output
output.diff
.cache
.doit.db
state_data.json
.ropeproject
drafts
deploy.yaml
resources
.direnv
.envrc
result

View File

@ -31,10 +31,6 @@ params:
pingback: https://webmention.io/erambler.co.uk/xmlrpc
cactus: erambler.co.uk
netlify:
name: erambler
id: 0599621e-c4b4-4341-8e42-6f8b9c1d33cc
social:
- kind: keyoxide
info: 'D9DA3E47E8BD377DA317B3D09E42CE071C4559D1'

View File

@ -5,11 +5,26 @@
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShell = import ./shell.nix { inherit pkgs; };
}
);
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
defaultPackage = pkgs.stdenv.mkDerivation {
name = "erambler-html";
src = ./.;
nativeBuildInputs = [ pkgs.hugo ];
buildPhase = "hugo";
installPhase = ''
mkdir $out
cp -R public/* $out
'';
};
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
(python38.withPackages
(py: with py; [ python invoke rich requests ruamel_yaml sh ]))
yarn
hugo
];
};
});
}

View File

@ -1,31 +0,0 @@
{ pkgs, ... }:
let
python = pkgs.python38;
my_yaspin = python.pkgs.buildPythonPackage rec {
pname = "yaspin";
version = "1.3.0";
src = python.pkgs.fetchPypi {
inherit pname version;
sha256 =
"cc37d35cc7f796dada6c37430b49e471ffa05d0686e6f8de36f83978b732df54";
};
doCheck = false;
meta = {
homepage = "https://github.com/pavdmyt/yaspin";
description = "Yet Another Terminal Spinner for Python";
};
};
pythonWithPackages = python.withPackages (py: [
py.python
# For locally-run tasks
py.invoke
py.rich
py.requests
py.ruamel_yaml
my_yaspin
]);
in pkgs.mkShell {
buildInputs = with pkgs; [ pythonWithPackages yarn hugo ];
}

View File

@ -1,75 +1,27 @@
from invoke import task
from yaspin import yaspin
import requests as rq
from pathlib import Path
from ruamel.yaml import YAML
import sh
yaml = YAML()
CONFIG = yaml.load(Path("deploy.yaml"))
DEPLOY_DIR = Path(__file__).parent / "public"
REMOTE_DIR = "jemisin.petrichor.me:/srv/www/erambler.co.uk/"
@task
def deploy(c, clean=False):
with yaspin().yellow as s:
if clean:
s.text = "clean and rebuild"
c.run(f"rm --recursive --force {CONFIG['deploy-dir']}", hide=True)
c.run("nikola build", hide=True)
s.ok("[done]")
if clean:
print("clean and rebuild...")
sh.rm(DEPLOY_DIR, recursive=True, force=True)
sh.hugo()
print("done")
s.text = "add to IPFS"
s.start()
result = c.run(
f"ipfs add --recursive --hidden --quieter {CONFIG['deploy-dir']}",
hide=True,
)
new_hash = result.stdout.rstrip()
s.ok("[done]")
s.write(f"- published at {new_hash}")
pinata(c, new_hash, "erambler")
update_dnslink(c, f"/ipfs/{new_hash}")
@task
def pinata(c, new_hash, name):
with yaspin(text="pin at pinata").yellow as s:
result = rq.post(
"https://api.pinata.cloud/pinning/pinByHash",
headers={"Authorization": f'Bearer {CONFIG["pinata-key"]}'},
json={
"pinataMetadata": {"name": name},
"hashToPin": new_hash,
},
)
result.raise_for_status()
s.ok("[done]")
details = result.json()
s.write(f'- pin status: {details["status"]}')
@task
def update_dnslink(c, ipfs_path):
with yaspin(text="update dnslink record").yellow as s:
cf_config = CONFIG["cloudflare"]
token = cf_config["token"]
zone_id = cf_config["zone_id"]
record_id = cf_config["record_id"]
result = rq.put(
f"https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/{record_id}",
headers={"Authorization": f"Bearer {token}"},
json={
"type": "TXT",
"name": "_dnslink.erambler.co.uk",
"content": f"dnslink={ipfs_path}",
"ttl": 1,
},
)
result.raise_for_status()
details = result.json()
if details["success"]:
s.ok("[done]")
else:
s.fail()
print("push via rsync...")
sh.rsync(
f"{DEPLOY_DIR}/",
REMOTE_DIR,
checksum=True,
archive=True,
verbose=True,
delete=True,
_fg=True,
)
print("done")