summaryrefslogtreecommitdiff
path: root/playbooks/roles/ci/templates/volumes/laminar/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'playbooks/roles/ci/templates/volumes/laminar/jobs')
-rwxr-xr-xplaybooks/roles/ci/templates/volumes/laminar/jobs/build_image.run36
-rwxr-xr-xplaybooks/roles/ci/templates/volumes/laminar/jobs/playbook.run25
2 files changed, 61 insertions, 0 deletions
diff --git a/playbooks/roles/ci/templates/volumes/laminar/jobs/build_image.run b/playbooks/roles/ci/templates/volumes/laminar/jobs/build_image.run
new file mode 100755
index 0000000..ed7bf21
--- /dev/null
+++ b/playbooks/roles/ci/templates/volumes/laminar/jobs/build_image.run
@@ -0,0 +1,36 @@
+#!/bin/bash
+# usage: laminarc queue build_publish_image registry="oci.liz.coffee" \
+# repo="src/cgit" tag="latest" remote="ssh://src.liz.coffee:2222/cgit" \
+# rev="<sha>" image_file="Dockerfile"
+
+set -e
+
+declare -a args=("$registry" "$repo" "$tag" "$remote" "$rev" "$image_file")
+for arg in "${args[@]}"
+do
+ if [[ ! "$arg" =~ ^[[:alnum:]:_\.\/\-]*$ ]]; then
+ echo "Invalid argument format. Don't be sneaky snek (-_-)."
+ exit 1
+ fi
+done
+
+log "Logging into registry $registry"
+registry_username="$(get_secret $registry | jq -r ".login.username")"
+get_secret $registry | jq -r ".login.password" \
+ | docker login --username "$registry_username" --password-stdin "$registry"
+
+log "Cloning remote $remote"
+r=$(echo "build-$(date --iso-8601=seconds)")
+git clone "$remote" "$r" && cd "$r"
+git checkout "$rev"
+
+image_tag="$registry/$repo:$tag"
+log "Building image $image_tag"
+env -i HOME="$HOME" bash -l -c "docker build . -t '$image_tag' -f '$image_file'"
+
+log "Pushing $image_tag"
+docker push "$image_tag"
+
+cd -
+rm -rf "$r"
+docker logout "$registry"
diff --git a/playbooks/roles/ci/templates/volumes/laminar/jobs/playbook.run b/playbooks/roles/ci/templates/volumes/laminar/jobs/playbook.run
new file mode 100755
index 0000000..181a050
--- /dev/null
+++ b/playbooks/roles/ci/templates/volumes/laminar/jobs/playbook.run
@@ -0,0 +1,25 @@
+#!/bin/bash
+# usage: laminarc queue playbook remote="ssh://src.liz.coffee:2222/infra" playbooks="deploy.yml playbooks/labdns.yml"
+
+set -e
+
+declare -a args=("$remote" "$playbooks")
+for arg in "${args[@]}"
+do
+ if [[ ! "$arg" =~ ^[[:alnum:]:_\ \.\/\-]*$ ]]; then
+ echo "Invalid argument format. Don't be sneaky snek (-_-)."
+ exit 1
+ fi
+done
+
+log "Cloning remote $remote"
+r=$(echo "ansible-$(date --iso-8601=seconds)")
+git clone "$remote" "$r" && cd "$r"
+
+get_secret "ansible_secrets" | jq -r '.notes' > secrets.yml
+private_key=$(get_secret "ssh_key" | jq -r '.notes')
+
+env -i HOME="$HOME" ssh-agent bash -c "ssh-add <(echo \"$private_key\") && ansible-playbook -e @secrets.yml $playbooks"
+
+cd -
+rm -rf "$r"