From 4274671a23108a060369deaba0cb91ddcc7fdd53 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:23:51 +0200 Subject: [PATCH 1/5] build: makefile: add deploy step --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 9ecbb22..bf1e0a3 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,14 @@ build-prod: serve: hugo server -D -F +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 SSH_TARGET" >&2; \ + exit 1; \ + fi + rsync --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$SSH_TARGET" + .PHONY: clean clean: $(RM) -r public From c23858ac269c5ed5b599d1445228d22c92ef6205 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:24:45 +0200 Subject: [PATCH 2/5] ci: use exec runner --- .drone.jsonnet | 61 ++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 3dca53b..f899bfb 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" }, + SSH_TARGET: { from_secret: "ssh_target" + if isDev then "_dev" else "" }, + SSH_USER: { from_secret: "ssh_user" }, + SSH_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 b743fb2e686ce40ca71f064357dc1fd49aa35bb4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:37:32 +0200 Subject: [PATCH 3/5] build: makefile: change title on dev deployment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bf1e0a3..215bdab 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 e456e8977bb67b9d965f9ac92cac178853c876bc Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 16:43:33 +0200 Subject: [PATCH 4/5] WIP: nix: add openssh/rsync to dev shell --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index be1350a..1f8c11c 100644 --- a/flake.nix +++ b/flake.nix @@ -67,6 +67,8 @@ buildInputs = with pkgs; [ gnumake hugo + openssh + rsync ]; inherit (self.checks.${system}.pre-commit) shellHook; From 33fe7ee7006e0cd53f34b0c3a94f40fbdfe23761 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Aug 2021 17:20:55 +0200 Subject: [PATCH 5/5] fixup! build: makefile: add deploy step --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 215bdab..fcec24d 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:$$SSH_TARGET" + rsync -e 'ssh -o StrictHostKeyChecking=no' --progress -avz --delete public/ "$$SSH_USER@$$SSH_HOST:$$SSH_TARGET" .PHONY: clean clean: