From 4c92c955be1616e3900e4925a8a52e1c31943780 Mon Sep 17 00:00:00 2001
From: Janne Mareike Koschinski <janne@kuschku.de>
Date: Wed, 6 Mar 2024 01:52:58 +0100
Subject: [PATCH] fix: amp activation

---
 amp/Chart.yaml                |  2 +-
 amp/templates/config.yaml     | 70 +++++++++++++++++++++++++++++++++++
 amp/templates/deployment.yaml | 21 +++++++++++
 amp/values.yaml               |  2 +
 4 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 amp/templates/config.yaml

diff --git a/amp/Chart.yaml b/amp/Chart.yaml
index b8c5438..902f9f2 100644
--- a/amp/Chart.yaml
+++ b/amp/Chart.yaml
@@ -2,5 +2,5 @@ apiVersion: v2
 name: amp
 description: Helm Chart for amp
 type: application
-version: 0.1.0
+version: 0.2.2
 appVersion: "latest"
diff --git a/amp/templates/config.yaml b/amp/templates/config.yaml
new file mode 100644
index 0000000..bd44f46
--- /dev/null
+++ b/amp/templates/config.yaml
@@ -0,0 +1,70 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "amp-helm.fullname" . }}
+  labels:
+    {{- include "amp-helm.labels" . | nindent 4 }}
+data:
+  auto-activate: "{{ .Values.config.autoActivate }}"
+  auto-update: "{{ .Values.config.autoUpdate }}"
+  main.sh: |-
+    #!/bin/bash -e
+    #set -o xtrace
+    set -e
+
+    echo "----------------------"
+    echo "Starting AMP-Dockerized..."
+    echo "----------------------"
+    echo "Note: This is an UNOFFICIAL IMAGE for CubeCoders AMP. This was created by the community, NOT CubeCoders."
+    echo "Please, DO NOT contact CubeCoders (Discord or otherwise) for technical support when using this image."
+    echo "They do not support nor endorse this image and will not help you."
+    echo "Instead, please direct support requests to https://github.com/MitchTalmadge/AMP-dockerized/issues."
+    echo "Thank you!!"
+    echo "----------------------"
+    echo ""
+
+    source /opt/entrypoint/utils.sh
+    source /opt/entrypoint/routines.sh
+    trap 'handle_error' ERR
+    trap_with_arg 'shutdown' INT TERM HUP QUIT KILL
+
+    # Migrate legacy vars
+    export AMP_LICENCE=${LICENCE:-${AMP_LICENCE:-"notset"}}
+    export AMP_MODULE=${MODULE:-${AMP_MODULE:-"ADS"}}
+    if [ ! -z "${NIGHTLY}" ]; then
+      export AMP_RELEASE_STREAM="Development"
+    fi
+
+    run_startup_script
+
+    create_amp_user
+
+    check_licence
+
+    configure_timezone
+
+    check_file_permissions
+
+    configure_main_instance
+
+    configure_release_stream
+
+    if [ ${AMP_AUTO_ACTIVATE} = "true" ]; then
+      echo "${AMP_LICENCE}" | run_amp_command "reactivateall"
+    else
+      echo "Skipping automatic reactivation."
+    fi
+
+    if [ ${AMP_AUTO_UPDATE} = "true" ]; then
+      upgrade_instances
+    else
+      echo "Skipping automatic updates."
+    fi
+
+    start_amp
+
+    # Sleep
+    echo "AMP is now running. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs"
+    monitor_amp &
+    tail -f /dev/null &
+    wait $!
diff --git a/amp/templates/deployment.yaml b/amp/templates/deployment.yaml
index 8cbe342..9cc9354 100644
--- a/amp/templates/deployment.yaml
+++ b/amp/templates/deployment.yaml
@@ -6,6 +6,10 @@ metadata:
     {{- include "amp-helm.labels" . | nindent 4 }}
 spec:
   replicas: {{ .Values.replicaCount }}
+  strategy:
+    rollingUpdate:
+      maxSurge: 0
+      maxUnavailable: "100%"
   selector:
     matchLabels:
       {{- include "amp-helm.selectorLabels" . | nindent 6 }}
@@ -29,6 +33,10 @@ spec:
           {{- .Values.volume | nindent 10 }}
         - name: tmp
           emptyDir: {}
+        - name: config
+          configMap:
+            defaultMode: 511
+            name: {{ include "amp-helm.fullname" . }}
       containers:
         - name: {{ .Chart.Name }}
           securityContext:
@@ -51,6 +59,16 @@ spec:
                 secretKeyRef:
                   key: "admin-pass"
                   name: {{ include "amp-helm.fullname" . }}
+            - name: "AMP_AUTO_ACTIVATE"
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "amp-helm.fullname" . }}
+                  key: auto-activate
+            - name: "AMP_AUTO_UPDATE"
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "amp-helm.fullname" . }}
+                  key: auto-update
           ports:
             - name: sftp
               containerPort: 2224
@@ -93,6 +111,9 @@ spec:
               name: data
             - mountPath: "/tmp"
               name: tmp
+            - mountPath: "/opt/entrypoint/main.sh"
+              name: config
+              subPath: "main.sh"
       {{- with .Values.nodeSelector }}
       nodeSelector:
         {{- toYaml . | nindent 8 }}
diff --git a/amp/values.yaml b/amp/values.yaml
index d8cc32b..02e233a 100644
--- a/amp/values.yaml
+++ b/amp/values.yaml
@@ -14,6 +14,8 @@ config:
     user: ""
     pass: ""
   license: ""
+  autoUpdate: false
+  autoActivate: false
 
 service:
   type: ClusterIP
-- 
GitLab