From 0136c997429bbbe5c153e6b9d47318a9cd32f0e3 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 21 Jul 2020 19:34:57 +0200 Subject: [PATCH] ci: use Jsonnet for YAML configuration generation Because the two kinds of pipelines were very similar, I used Jsonnet to factorise the definitions. This means I have to switch the configuration file in my settings, and enable Jsonnet files. --- .drone.jsonnet | 45 ++++++++++++++++++++++++++++++ .drone.yml | 76 -------------------------------------------------- 2 files changed, 45 insertions(+), 76 deletions(-) create mode 100644 .drone.jsonnet delete mode 100644 .drone.yml diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..78f6f84 --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,45 @@ +local Pipeline(isDev) = { + kind: "pipeline", + name: if isDev then "deploy-dev" else "deploy-prod", + # Dev ignores "master", prod only triggers on "master" + trigger: { branch: { [if isDev then "exclude" else "include"]: [ "master" ] } }, + # We want to clone the submodules, which isn't done by default + clone: { disable: true }, + steps: [ + { + name: "clone", + image: "plugins/git", + recursive: true, + }, + { + 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 "", + ], + [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" }, + }, + }, + ] +}; + + +[ + Pipeline(false), + Pipeline(true), +] diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index be7f5db..0000000 --- a/.drone.yml +++ /dev/null @@ -1,76 +0,0 @@ -kind: pipeline -name: default - -clone: - disable: true - - -steps: - - name: clone - image: plugins/git - recursive: true - - # Production build and deploy - - name: build - image: klakegg/hugo - commands: - - hugo version - - hugo --minify - environment: - HUGO_ENV: production - when: - branch: - - master - - - name: deploy - image: appleboy/drone-scp - settings: - source: public/* - strip_components: 1 # Make sure the tarball doesn't contain leading path - rm: true # Make sure only the newly generated files are left - host: - from_secret: ssh_host - target: - from_secret: ssh_target - username: - from_secret: ssh_user - key: - from_secret: ssh_key - port: - from_secret: ssh_port - when: - branch: - - master - - # Dev build and deploy - - name: build-dev - image: klakegg/hugo - commands: - - hugo version - # Include drafts and future articles, use dev base url - - hugo --minify -D -F -b https://dev.belanyi.fr - when: - branch: - exclude: - - master - - - name: deploy-dev - image: appleboy/drone-scp - settings: - source: public/* - strip_components: 1 # Make sure the tarball doesn't contain leading path - rm: true # Make sure only the newly generated files are left - host: - from_secret: ssh_host - target: - from_secret: ssh_target_dev - username: - from_secret: ssh_user - key: - from_secret: ssh_key - port: - from_secret: ssh_port - when: - branch: - exclude: - - master