From e0741b443816ba5952f9aa50808d9094a9f1bb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 1 Apr 2019 17:01:16 +0200 Subject: [PATCH] Ship the customizations as a Docker image The Docker image is used in the initialization process, to copy everything in the custom folder to the Gitea data dir (mounted as a persistent volume). It is built using Packer and is based on the busybox image, so we can use its minimalist shell system to copy files and set permissions --- README.md | 16 ++++++++-- .../custom => custom}/options/label/Default | 0 .../custom => custom}/options/label/Kosmos | 0 kubernetes/gitea-server.yaml | 7 +++-- packer/custom.json | 29 +++++++++++++++++++ script/build_customizations_image | 7 +++++ script/copy_customization | 11 ------- 7 files changed, 55 insertions(+), 15 deletions(-) rename {kubernetes/custom => custom}/options/label/Default (100%) rename {kubernetes/custom => custom}/options/label/Kosmos (100%) create mode 100644 packer/custom.json create mode 100755 script/build_customizations_image delete mode 100755 script/copy_customization diff --git a/README.md b/README.md index bbf687a..af0054b 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,22 @@ This repository contains configuration files and other assets, that are used to deploy and operate this Gitea instance. -To upload the customization files to the running pod: +To create a new image containing the customizations: + +Edit `packer/custom.json` to increment the tag, then run this script (needs +[Packer](https://www.packer.io/) in your path) ``` -./script/copy_customization +./script/build_customizations_image +``` + +Then edit `kubernetes/gitea-server.yaml` to use the new tag +(`image: eu.gcr.io/fluted-magpie-218106/gitea_custom:$VERSION`) and apply the +change: + +``` +cd kubernetes +kubectl apply -f gitea-server.yaml ``` Feel free to [open issues] for questions, suggestions, bugs, to-do items, and diff --git a/kubernetes/custom/options/label/Default b/custom/options/label/Default similarity index 100% rename from kubernetes/custom/options/label/Default rename to custom/options/label/Default diff --git a/kubernetes/custom/options/label/Kosmos b/custom/options/label/Kosmos similarity index 100% rename from kubernetes/custom/options/label/Kosmos rename to custom/options/label/Kosmos diff --git a/kubernetes/gitea-server.yaml b/kubernetes/gitea-server.yaml index c4dfd9e..15cc123 100644 --- a/kubernetes/gitea-server.yaml +++ b/kubernetes/gitea-server.yaml @@ -14,10 +14,13 @@ spec: spec: initContainers: - name: init-config - image: busybox + # This is a busybox image with our gitea customizations saved to + # /custom, built using ./script/build_customizations_image from the + # root of the repo + image: eu.gcr.io/fluted-magpie-218106/gitea_custom:0.1 command: [ 'sh', '-c', - 'mkdir -p /data/gitea/conf && mkdir -p /data/gitea/https && cp /root/conf/app.ini /data/gitea/conf/app.ini && chown 1000:1000 /data/gitea/conf/app.ini && chmod 660 /data/gitea/conf/app.ini && cp /root/conf/*.pem /data/gitea/https && chmod 600 /data/gitea/https/*.pem && chown -R 1000:1000 /data/gitea' + 'mkdir -p /data/gitea/conf && mkdir -p /data/gitea/https && cp /root/conf/app.ini /data/gitea/conf/app.ini && chown 1000:1000 /data/gitea/conf/app.ini && chmod 660 /data/gitea/conf/app.ini && cp /root/conf/*.pem /data/gitea/https && chmod 600 /data/gitea/https/*.pem && cp -R /custom/* /data/gitea && chown -R 1000:1000 /data/gitea' ] volumeMounts: - mountPath: /data diff --git a/packer/custom.json b/packer/custom.json new file mode 100644 index 0000000..cbbffad --- /dev/null +++ b/packer/custom.json @@ -0,0 +1,29 @@ +{ + "builders": [{ + "type": "docker", + "image": "busybox", + "run_command": ["-d", "-i", "-t", "{{.Image}}", "/bin/sh"], + "commit": true + }], + "provisioners": [ + { + "inline": ["mkdir /custom"], + "type": "shell" + }, + { + "type": "file", + "source": "../custom/", + "destination": "/custom" + } + ], + "post-processors": [ + [ + { + "type": "docker-tag", + "repository": "eu.gcr.io/fluted-magpie-218106/gitea_custom", + "tag": "0.1" + }, + "docker-push" + ] + ] +} diff --git a/script/build_customizations_image b/script/build_customizations_image new file mode 100755 index 0000000..da61186 --- /dev/null +++ b/script/build_customizations_image @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# fail fast +set -e + +cd packer/ +packer build custom.json +cd - diff --git a/script/copy_customization b/script/copy_customization deleted file mode 100755 index 9b4ee13..0000000 --- a/script/copy_customization +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -for podname in $(kubectl get pods -l name=gitea-server -o json \ - | jq -r '.items[].metadata.name'); do - for path in ./kubernetes/custom/*; do - echo "Copying ${path}..." - kubectl cp "${path}" "${podname}":"/data/gitea/" - done - # Fix permissions - kubectl exec "${podname}" -- chown -R 1000:1000 /data/gitea/ - done