From ee916a506bf9ec4de1e7e5a52a66318498243294 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:23:51 +0200 Subject: [PATCH 01/11] build: makefile: add deploy step --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 9ecbb22..2bf1634 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,11 @@ build-prod: serve: hugo server -D -F +deploy: + @if [ -n "$$KEY" ]; then eval "$$(ssh-agent)"; echo "$$KEY" | ssh-add -; fi + if [ -z "$$USERNAME" ] || [ -z "$$SSH_HOST" ] || [ -z "$$TARGET" ]; then exit 1; fi + rsync --progress -avz --delete public/ "$$USERNAME@$$SSH_HOST:$$TARGET" + .PHONY: clean clean: $(RM) -r public From 7295265a3ebfe1fade1c342940fdd5f5f564c2e0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:24:45 +0200 Subject: [PATCH 02/11] ci: use exec runner --- .drone.jsonnet | 61 ++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 3dca53b..adcaced 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -1,58 +1,55 @@ local Pipeline(isDev) = { kind: "pipeline", - name: if isDev then "deploy-dev" else "deploy-prod", + type: "exec", + name: if isDev then "Deploy to dev" else "Deploy to prod", # Dev ignores "master", prod only triggers on "master" trigger: { branch: { [if isDev then "exclude" else "include"]: [ "main" ] } }, - # We want to clone the submodules, which isn't done by default - clone: { disable: true }, steps: [ { - name: "clone", - image: "plugins/git", - recursive: true, + # We want to clone the submodules, which isn't done by default + name: "submodules", + commands: [ + "git submodule update --recursive --init", + ] }, { - name: "markdownlint", - image: "06kellyjac/markdownlint-cli", + # Include pre-commit checks, which include markdownlint + name: "check", commands: [ - "markdownlint --version", - "markdownlint content/", + "nix flake check", ], }, { + # If dev, include drafts and future articles, change base URL name: "build", - image: "klakegg/hugo", commands: [ - "hugo version", - # If dev, include drafts and future articles, change base URL - "hugo --minify" + if isDev then " -D -F -b https://dev.belanyi.fr" else "", + "nix develop -c make " + if isDev then "build-dev" else "build-prod", ], - [if !isDev then "environment"]: { HUGO_ENV: "production" } }, { name: "deploy", - image: "appleboy/drone-scp", - settings: { - source: "public/*", - strip_components: 1, # Remove 'public/' suffix from file paths - rm: true, # Remove previous files from target directory - host: { from_secret: "ssh_host" }, - target: { from_secret: "ssh_target" + if isDev then "_dev" else "" }, - username: { from_secret: "ssh_user" }, - key: { from_secret: "ssh_key" }, - port: { from_secret: "ssh_port" }, + commands: [ + "nix develop -c make deploy" + ], + environment: { + SSH_HOST: { from_secret: "ssh_host" }, + TARGET: { from_secret: "ssh_target" + if isDev then "_dev" else "" }, + USERNAME: { from_secret: "ssh_user" }, + KEY: { from_secret: "ssh_key" }, }, }, { name: "notify", - image: "plugins/matrix", - settings: { - homeserver: { from_secret: "matrix_homeserver" }, - roomid: { from_secret: "matrix_roomid" }, - username: { from_secret: "matrix_username" }, - password: { from_secret: "matrix_password" }, + commands: [ + "nix run github:ambroisie/matrix-notifier", + ], + environment: { + ADDRESS: { from_secret: "matrix_homeserver" }, + ROOM: { from_secret: "matrix_roomid" }, + USER: { from_secret: "matrix_username" }, + PASS: { from_secret: "matrix_password" }, }, - trigger: { status: [ "failure", "success", ] }, + when: { status: [ "failure", "success", ] }, }, ] }; From 81c0fc89f3e250da2109bd2b72c31c337a82be3d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:37:32 +0200 Subject: [PATCH 03/11] build: makefile: change title on dev deployment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2bf1634..0dd8524 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: build-dev .PHONY: build-dev build-dev: - HUGO_BASEURL=https://dev.belanyi.fr hugo -D -F + HUGO_TITLE="Ambroisie's dev blog" HUGO_BASEURL=https://dev.belanyi.fr hugo -D -F .PHONY: build-prod build-prod: From 445b879afafebda5a1c49574ba041d27e272606f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:41:13 +0200 Subject: [PATCH 04/11] fixup! ci: use exec runner --- .drone.jsonnet | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index adcaced..162e919 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -29,7 +29,8 @@ local Pipeline(isDev) = { { name: "deploy", commands: [ - "nix develop -c make deploy" + "nix shell nixpkgs#openssh", + "nix develop -c make deploy", ], environment: { SSH_HOST: { from_secret: "ssh_host" }, From cd808f311af694321ba1eac11d136f42341a073e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:43:33 +0200 Subject: [PATCH 05/11] nix: add openssh to dev shell --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index be1350a..f8f492d 100644 --- a/flake.nix +++ b/flake.nix @@ -67,6 +67,7 @@ buildInputs = with pkgs; [ gnumake hugo + openssh ]; inherit (self.checks.${system}.pre-commit) shellHook; From ff389ba1fab2cf67c367b14a98b185386e21062b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:45:53 +0200 Subject: [PATCH 06/11] nix: add rsync to dev shell --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index f8f492d..1f8c11c 100644 --- a/flake.nix +++ b/flake.nix @@ -68,6 +68,7 @@ gnumake hugo openssh + rsync ]; inherit (self.checks.${system}.pre-commit) shellHook; From 1a2dd074cb1098764a311a6c271632e95719f4c0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:58:15 +0200 Subject: [PATCH 07/11] fixup! ci: use exec runner --- .drone.jsonnet | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 162e919..33f3eb7 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -34,9 +34,9 @@ local Pipeline(isDev) = { ], environment: { SSH_HOST: { from_secret: "ssh_host" }, - TARGET: { from_secret: "ssh_target" + if isDev then "_dev" else "" }, - USERNAME: { from_secret: "ssh_user" }, - KEY: { from_secret: "ssh_key" }, + SSH_TARGET: { from_secret: "ssh_target" + if isDev then "_dev" else "" }, + SSH_USER: { from_secret: "ssh_user" }, + SSH_KEY: { from_secret: "ssh_key" }, }, }, { From 0986c64a80e5098f66a13554c24c2a6053b5b6bf Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:58:18 +0200 Subject: [PATCH 08/11] fixup! build: makefile: add deploy step --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0dd8524..f123d87 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,12 @@ serve: hugo server -D -F deploy: - @if [ -n "$$KEY" ]; then eval "$$(ssh-agent)"; echo "$$KEY" | ssh-add -; fi - if [ -z "$$USERNAME" ] || [ -z "$$SSH_HOST" ] || [ -z "$$TARGET" ]; then exit 1; fi - rsync --progress -avz --delete public/ "$$USERNAME@$$SSH_HOST:$$TARGET" + @if [ -n "$$SSH_KEY" ]; then eval "$$(ssh-agent)"; echo "$$SSH_KEY" | ssh-add -; fi + @if [ -z "$$SSH_USER" ] || [ -z "$$SSH_HOST" ] || [ -z "$$SSH_TARGET" ]; \ + then echo "Missing one of SSH_USER, SSH_HOST, or TARGET" >&2; \ + exit 1; \ + fi + rsync --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$TARGET" .PHONY: clean clean: From 0cee06c573d81886075d35f1cf9435ac405e4291 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 17:13:04 +0200 Subject: [PATCH 09/11] fixup! 445b879afafebda5a1c49574ba041d27e272606f --- .drone.jsonnet | 1 - 1 file changed, 1 deletion(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 33f3eb7..f899bfb 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -29,7 +29,6 @@ local Pipeline(isDev) = { { name: "deploy", commands: [ - "nix shell nixpkgs#openssh", "nix develop -c make deploy", ], environment: { From 324c0cc77d7a01e48053bb7ae3f7ac6e5fedb778 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 17:14:08 +0200 Subject: [PATCH 10/11] fixup! fixup! build: makefile: add deploy step --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f123d87..0016cbe 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ serve: deploy: @if [ -n "$$SSH_KEY" ]; then eval "$$(ssh-agent)"; echo "$$SSH_KEY" | ssh-add -; fi @if [ -z "$$SSH_USER" ] || [ -z "$$SSH_HOST" ] || [ -z "$$SSH_TARGET" ]; \ - then echo "Missing one of SSH_USER, SSH_HOST, or TARGET" >&2; \ + then echo "Missing one of SSH_USER, SSH_HOST, or SSH_TARGET" >&2; \ exit 1; \ fi rsync --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$TARGET" From 70a023df7a7534b50742a1b83f95d2d3d99fe1bb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 17:14:08 +0200 Subject: [PATCH 11/11] fixup! fixup! build: makefile: add deploy step --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0016cbe..215bdab 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ deploy: then echo "Missing one of SSH_USER, SSH_HOST, or SSH_TARGET" >&2; \ exit 1; \ fi - rsync --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$TARGET" + rsync --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$SSH_TARGET" .PHONY: clean clean: