From bbfa3f29641fdc083d46b0fde6da1e5e0d347101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 27 Feb 2019 17:47:48 +0100 Subject: [PATCH] Add a script to copy the content of the custom folder to a running pod For now it is only labels, but adding anything supported will work (robots.txt, public files, templates, etc) The content will be copied to the /data/gitea/ folder that is a mounted persistent volume https://docs.gitea.io/en-us/customizing-gitea/ --- .gitignore | 2 +- README.md | 6 ++++++ kubernetes/{custom => }/config/.gitkeep | 0 kubernetes/gitea-server.yaml | 10 +--------- script/copy_customization | 11 +++++++++++ script/get_secrets | 2 +- script/replace_secrets | 4 ++-- 7 files changed, 22 insertions(+), 13 deletions(-) rename kubernetes/{custom => }/config/.gitkeep (100%) create mode 100755 script/copy_customization diff --git a/.gitignore b/.gitignore index 748794d..769e3a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/kubernetes/custom/config/ +/kubernetes/config/ diff --git a/README.md b/README.md index f9bc1dc..bbf687a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ 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: + +``` +./script/copy_customization +``` + Feel free to [open issues] for questions, suggestions, bugs, to-do items, and whatever else you want to discuss or resolve. diff --git a/kubernetes/custom/config/.gitkeep b/kubernetes/config/.gitkeep similarity index 100% rename from kubernetes/custom/config/.gitkeep rename to kubernetes/config/.gitkeep diff --git a/kubernetes/gitea-server.yaml b/kubernetes/gitea-server.yaml index 802fd8e..7284ed5 100644 --- a/kubernetes/gitea-server.yaml +++ b/kubernetes/gitea-server.yaml @@ -17,18 +17,13 @@ spec: image: busybox command: [ 'sh', '-c', - 'mkdir -p /data/gitea/conf && mkdir -p /data/gitea/https && mkdir -p /data/gitea/options/label && 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 /root/options/label/* /data/gitea/options/label/ && 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 && chown -R 1000:1000 /data/gitea' ] volumeMounts: - mountPath: /data name: gitea-server-data - mountPath: /root/conf name: config - # The labels have been created as a ConfigMap from local files using this command: - # - # kubectl create configmap gitea-options-label --from-file=custom/options/label/ - - mountPath: /root/options/label - name: label containers: - name: gitea-server image: gitea/gitea:1.7.2 @@ -57,9 +52,6 @@ spec: - key: key.pem path: key.pem mode: 256 - - name: label - configMap: - name: gitea-options-label --- apiVersion: v1 kind: PersistentVolumeClaim diff --git a/script/copy_customization b/script/copy_customization new file mode 100755 index 0000000..9b4ee13 --- /dev/null +++ b/script/copy_customization @@ -0,0 +1,11 @@ +#!/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 diff --git a/script/get_secrets b/script/get_secrets index 310929c..0a7dcc2 100755 --- a/script/get_secrets +++ b/script/get_secrets @@ -7,7 +7,7 @@ secret = `kubectl get secret gitea-config -o yaml` yaml = YAML.load(secret) yaml['data'].each do |key, data| - filename = File.join('kubernetes', 'custom', 'config', key) + filename = File.join('kubernetes', 'config', key) File.open(filename, "w+") do |f| puts "Writing #{filename}" f.write Base64.decode64(data) diff --git a/script/replace_secrets b/script/replace_secrets index c2ef0cf..2a3de09 100755 --- a/script/replace_secrets +++ b/script/replace_secrets @@ -2,8 +2,8 @@ # Delete the gitea-config secrets kubectl delete secret gitea-config -# Replace it from the local files in kubernetes/custom/config/* (acquired by running +# Replace it from the local files in kubernetes/config/* (acquired by running # ./script/get_secrets) -kubectl create secret generic gitea-config --from-file=cert.pem=kubernetes/custom/config/cert.pem --from-file=key.pem=kubernetes/custom/config/key.pem --from-file=app.ini=kubernetes/custom/config/app.ini +kubectl create secret generic gitea-config --from-file=cert.pem=kubernetes/config/cert.pem --from-file=key.pem=kubernetes/config/key.pem --from-file=app.ini=kubernetes/config/app.ini # Force the pod to restart by patching the deployment resource kubectl patch deployment gitea-server -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"