summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/Dockerfile6
-rw-r--r--utils/drone.star138
-rwxr-xr-xutils/hugo_build.sh8
3 files changed, 152 insertions, 0 deletions
diff --git a/utils/Dockerfile b/utils/Dockerfile
new file mode 100644
index 00000000..e0407998
--- /dev/null
+++ b/utils/Dockerfile
@@ -0,0 +1,6 @@
+FROM alpine:latest
+
+RUN apk add --no-cache ansible py3-netaddr openssh-client rsync
+RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community hugo
+
+CMD ["ansible-playbook", "--version"]
diff --git a/utils/drone.star b/utils/drone.star
new file mode 100644
index 00000000..db0fbaae
--- /dev/null
+++ b/utils/drone.star
@@ -0,0 +1,138 @@
+# starlark is used instead of more readable YAML because protocols will be added/removed in future.
+# you need to set the drone config path to `utils/drone.star` in the webui and also store the ssh key as a drone secret in `ssh_private_key` variable.
+# run custom build with force_rebuild parameter set to true to rebuild and override images on registry
+
+def main(ctx):
+
+ protocols = [
+ 'xray',
+ 'hysteria',
+ 'ocserv',
+ 'sshvpn'
+ ]
+
+ pipelines = [
+ pipeline_1(),
+ pipeline_2(protocols)
+ ]
+
+ return pipelines
+
+def pipeline_1():
+ steps = []
+
+ # step 1: check if image exists on remote registry
+ steps.append({
+ "name": "check_image",
+ "image": "alpine:latest",
+ "commands": [
+ ' wget http://registry.opviel.de/v2/_catalog -O - | grep -q "alpine_ansible_hugo" && [ "$force_rebuild" != "true" ] && echo -n "\nBUILD SKIPPED" && exit 78 || exit 0'
+ ],
+ "trigger": {"branch": "master"}
+ })
+
+ # step 2: if doesn't exist, build and publish image to registry
+ steps.append({
+ "name": "publish_on_registry",
+ "image": "plugins/docker",
+ "settings": {
+ "repo": "registry.opviel.de/alpine_ansible_hugo",
+ "dockerfile": "utils/Dockerfile",
+ "registry": "registry.opviel.de",
+ "tags": ["latest"],
+ "insecure": "true",
+ "purge": "true",
+ "compress": "true"
+ }
+ })
+
+ return {
+ "kind": "pipeline",
+ "type": "docker",
+ "name": "Build and Publish Image",
+ "platform": { "arch": "arm64" },
+ "steps": steps,
+ "trigger": {"branch": "master" }
+ }
+
+
+def pipeline_2(protocols):
+
+ environment_vars = {
+ "SSH_PRIVATE_KEY": {
+ "from_secret": "ssh_private_key"
+ }
+ }
+
+ steps = []
+
+ # step 1: export ssh private key to file
+ steps.append({
+ "name": "export_ssh_key",
+ "image": "alpine",
+ "commands": [
+ 'echo "$SSH_PRIVATE_KEY" > .ssh_private_key',
+ "chmod 600 .ssh_private_key"
+ ],
+ "environment": environment_vars
+ })
+
+ # step 2: add theme
+ steps.append({
+ "name": "git_add_theme",
+ "image": "alpine/git",
+ "commands": [
+ "git submodule add -f https://github.com/alex-shpak/hugo-book web/themes/hugo-book"
+ ],
+ "environment": environment_vars
+ })
+
+ steps.append({
+ "name": "setup_base",
+ "image": "registry.opviel.de:80/alpine_ansible_hugo:latest",
+ "commands": [
+ "/usr/bin/ansible-playbook reactance.yaml -t base"
+ ],
+ "depends_on": ["export_ssh_key"]
+ })
+
+ # step 3: run pipeline
+ web_deps = ["export_ssh_key", "setup_base", "git_add_theme"]
+ for protocol in protocols:
+ steps.append({
+ "name": "setup_{}".format(protocol),
+ "image": "registry.opviel.de:80/alpine_ansible_hugo:latest",
+ "commands": [
+ "/usr/bin/ansible-playbook reactance.yaml -t {}".format(protocol)
+ ],
+ "depends_on": ["export_ssh_key", "setup_base"]
+ })
+
+ web_deps.append("setup_{}".format(protocol))
+ steps.append({
+ "name": "setup_dns",
+ "image": "registry.opviel.de:80/alpine_ansible_hugo:latest",
+ "commands": [
+ "/usr/bin/ansible-playbook reactance.yaml -t dns"
+ ],
+ "depends_on": ["export_ssh_key", "setup_base"]
+ })
+
+ steps.append({
+ "name": "setup_web",
+ "image": "registry.opviel.de:80/alpine_ansible_hugo:latest",
+ "commands": [
+ "/usr/bin/ansible-playbook reactance.yaml -t web"
+ ],
+ "depends_on": web_deps
+ })
+
+ return {
+ "kind": "pipeline",
+ "type": "docker",
+ "name": "Execute Playbook",
+ "platform": { "arch": "arm64" },
+ "steps": steps,
+ "depends_on": ["Build and Publish Image"],
+ "trigger": {"branch": "master"}
+ }
diff --git a/utils/hugo_build.sh b/utils/hugo_build.sh
new file mode 100755
index 00000000..ef344209
--- /dev/null
+++ b/utils/hugo_build.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+for d in .hugo_sites_build/*; do
+ [ -f "$d" ] && continue
+ uname=$(echo $d | rev | cut -d / -f 1 | rev)
+ cd $d && hugo && cd ../..
+ mv $d/public .built_sites/$uname
+done;