Dduvall has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399256 )

Change subject: Use sed instead of envsubst
......................................................................

Use sed instead of envsubst

Although sed is never a good first choice, it does seem better than
depending on gettext tools that are not available by default on all
platforms (*cough* macOS).

Change-Id: I4f4ebf5ada33673a967c9bf83cd24db3e5bff399
---
M _scaffold/Chart.yaml
M _scaffold/values.yaml
M create_new_service.sh
3 files changed, 36 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/deployment-charts 
refs/changes/56/399256/1

diff --git a/_scaffold/Chart.yaml b/_scaffold/Chart.yaml
index b9e67c4..f2585a2 100644
--- a/_scaffold/Chart.yaml
+++ b/_scaffold/Chart.yaml
@@ -1,4 +1,4 @@
 apiVersion: v1
 description: A Helm chart for Kubernetes
-name: $SERVICE_NAME
+name: ${SERVICE_NAME}
 version: 0.0.1
diff --git a/_scaffold/values.yaml b/_scaffold/values.yaml
index 737f738..70bfe92 100644
--- a/_scaffold/values.yaml
+++ b/_scaffold/values.yaml
@@ -2,27 +2,27 @@
 # This is a YAML-formatted file.
 # Declare variables to be passed into your templates.
 helm_scaffold_version: 0.1 # This can be useful when backporting fixes.
-namespace: $NAMESPACE
+namespace: ${NAMESPACE}
 docker:
   registry: docker-registry.wikimedia.org
   pull_policy: IfNotPresent
 resources:
   replicas: 1
 main_app:
-  image: $IMAGE_NAME
+  image: ${IMAGE_NAME}
   version: latest # we use latest everywhere in the defaults.
-  port: $PORT
+  port: ${PORT}
   limits:
     cpu: 1
     memory: 400Mi
   liveness_probe:
     httpGet:
       path: /
-      port: $PORT
+      port: ${PORT}
   readiness_probe:
     httpGet:
       path: /
-      port: $PORT
+      port: ${PORT}
 
 logging:
   enabled: false
@@ -36,7 +36,7 @@
   image_version: latest
 service:
   deployment: minikube # valid values are "production" and "minikube"
-  port: $SERVICE_PORT
+  port: ${SERVICE_PORT}
   externalIP: null # you need to define this if "production" is used
 config:
   public: {} # Add here all the keys that can be publicly available as a 
ConfigMap
diff --git a/create_new_service.sh b/create_new_service.sh
index 7a1520e..94fde9f 100755
--- a/create_new_service.sh
+++ b/create_new_service.sh
@@ -1,28 +1,47 @@
 #!/bin/bash
 set -eu
 function fail {
-    _msg=shift
-    echo $_msg && exit 1
+    echo $1 && exit 1
 }
 
+declare -a sargs=()
+
+function subadd {
+    local x=$'\001'
+    sargs+=(-e "s${x}\\\${$1}${x}$2${x}g")
+}
+
+function subprompt {
+    read -r value
+    subadd "$1" "$value"
+}
+
+function subst {
+    sed "${sargs[@]}" "$1"
+}
 
 function main {
-    which envsubst || fail "You need envusbst(1) to run this script; please 
install gettext!"
     echo "Please input the name of the service"
     read -r SERVICE_NAME
+    subadd SERVICE_NAME "$SERVICE_NAME"
+
     test -d "charts/${SERVICE_NAME}" && fail "A service named ${SERVICE_NAME} 
already exists, cannot recreate it."
+
     echo "Please input the namespace this service will be deployed to"
-    read -r NAMESPACE
+    subprompt NAMESPACE
+
     echo "Please input the port the application is listening on"
-    read -r PORT
+    subprompt PORT
+
     echo "Please input the port this service will be exposed on (dev only)"
-    read -r SERVICE_PORT
+    subprompt SERVICE_PORT
+
     echo "Please input the docker image to use:"
-    read -r IMAGE_NAME
-    export SERVICE_NAME NAMESPACE SERVICE_PORT IMAGE_NAME PORT
+    subprompt IMAGE_NAME
+
     cp -rp _scaffold/ charts/${SERVICE_NAME}
-    cat _scaffold/values.yaml | envsubst > charts/${SERVICE_NAME}/values.yaml
-    cat _scaffold/Chart.yaml | envsubst > charts/${SERVICE_NAME}/Chart.yaml
+    subst _scaffold/values.yaml > charts/${SERVICE_NAME}/values.yaml
+    subst _scaffold/Chart.yaml > charts/${SERVICE_NAME}/Chart.yaml
     echo "You can edit your chart (if needed!) at 
${PWD}/charts/${SERVICE_NAME}"
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/399256
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f4ebf5ada33673a967c9bf83cd24db3e5bff399
Gerrit-PatchSet: 1
Gerrit-Project: operations/deployment-charts
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to