From 9211f3d84effedd5d465d02ea7428484c873f060 Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Fri, 24 Jul 2020 11:56:01 -0500
Subject: [PATCH] Try moving shell aliases to bash functions in separate script

---
 helpers/helm_base.yaml   |  4 +---
 helpers/shell_aliases.sh | 13 +++++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 helpers/shell_aliases.sh

diff --git a/helpers/helm_base.yaml b/helpers/helm_base.yaml
index c48f92f..a18d378 100644
--- a/helpers/helm_base.yaml
+++ b/helpers/helm_base.yaml
@@ -4,9 +4,7 @@
   before_script:
     - docker info
     - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
-    - shopt -s expand_aliases
-    - alias helm='docker run -t --rm -e HELM_EXPERIMENTAL_OCI="$HELM_EXPERIMENTAL_OCI" -v $(pwd):/apps -w /apps -v ~/.kube:/root/.kube -v ~/.helm:/root/.helm -v ~/.config/helm:/root/.config/helm -v ~/.cache/helm:/root/.cache/helm alpine/helm:3.2.3'
+    - source ./helpers/shell_aliases.sh
     - helm registry login -u ${CI_REGISTRY_USER} -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
-    - alias kubectl='docker run -a stdout --rm -v $(pwd):/apps -w /apps alpine/k8s:1.18.2 kubectl'
     - helm repo add stable https://kubernetes-charts.storage.googleapis.com
     - helm repo update
diff --git a/helpers/shell_aliases.sh b/helpers/shell_aliases.sh
new file mode 100644
index 0000000..70fabf3
--- /dev/null
+++ b/helpers/shell_aliases.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+# Define custom bash functions that can be passed around to sub-envs
+shopt -s expand_aliases
+
+helm() {
+  docker run -t --rm -e HELM_EXPERIMENTAL_OCI="$HELM_EXPERIMENTAL_OCI" -v $(pwd):/apps -w /apps -v ~/.kube:/root/.kube -v ~/.helm:/root/.helm -v ~/.config/helm:/root/.config/helm -v ~/.cache/helm:/root/.cache/helm alpine/helm:3.2.3 "$@"
+}
+export -f helm
+
+kubectl() {
+    docker run -a stdout --rm -v $(pwd):/apps -w /apps alpine/k8s:1.18.2 kubectl "$@"
+}
+export -f kubectl
-- 
GitLab