Skip to content

Commit

Permalink
moved scripts to image entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk committed Mar 10, 2024
1 parent 74d39d7 commit 8522b76
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 300 deletions.
8 changes: 4 additions & 4 deletions requirements.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies:
- name: redis
repository: oci://registry-1.docker.io/bitnamicharts
version: 18.12.1
version: 18.19.1
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 13.4.4
digest: sha256:1eaf4fb2a3299e8922a03fad1738dfb7895a2956927b8b5dc164e42ac8c67899
generated: "2024-02-07T13:02:13.441958453+02:00"
version: 13.4.6
digest: sha256:8db4ce09a5b6bd07db541bb4ff6a3fae95a1dc76fa27dee5710d2b59bab3fd69
generated: "2024-03-09T17:57:58.062411571+02:00"
2 changes: 1 addition & 1 deletion scripts/update-env-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def upper_repl(match):
name = env = m.group(1).strip()
desc = m.group(2).strip()
default = m.group(3).strip()
if env in ["REDASH_REDIS_URL", "REDASH_DATABASE_URL"]:
if env in ["REDASH_CACHE_URL", "REDASH_DB_URL"]:
continue
secret = False
if env in [
Expand Down
22 changes: 11 additions & 11 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Shared environment block used across each component.
{{- define "redash.env" }}
{{- if not .Values.redash.selfManagedSecrets }}
{{- if not .Values.postgresql.enabled }}
- name: REDASH_DATABASE_URL
- name: REDASH_DB_URL
{{ if .Values.externalPostgreSQLSecret -}}
valueFrom:
secretKeyRef:
Expand All @@ -100,22 +100,22 @@ Shared environment block used across each component.
value: {{ default "" .Values.externalPostgreSQL | quote }}
{{- end }}
{{- else -}}
- name: REDASH_DATABASE_USER
- name: REDASH_DB_USER
value: "{{ .Values.postgresql.auth.username }}"
- name: REDASH_DATABASE_PASSWORD
- name: REDASH_DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-postgresql
key: password
- name: REDASH_DATABASE_HOSTNAME
- name: REDASH_DB_HOSTNAME
value: {{ include "redash.postgresql.fullname" . }}
- name: REDASH_DATABASE_PORT
- name: REDASH_DB_PORT
value: "{{ .Values.postgresql.primary.service.ports.postgresql }}"
- name: REDASH_DATABASE_DB
- name: REDASH_DB_NAME
value: "{{ .Values.postgresql.auth.database }}"
{{- end }}
{{- if not .Values.redis.enabled }}
- name: REDASH_REDIS_URL
- name: REDASH_CACHE_URL
{{- if .Values.externalRedisSecret }}
valueFrom:
secretKeyRef:
Expand All @@ -124,7 +124,7 @@ Shared environment block used across each component.
value: {{ default "" .Values.externalRedis | quote }}
{{- end }}
{{- else }}
- name: REDASH_REDIS_PASSWORD
- name: REDASH_CACHE_PASSWORD
valueFrom:
secretKeyRef:
{{- if .Values.redis.existingSecret }}
Expand All @@ -133,11 +133,11 @@ Shared environment block used across each component.
name: {{ .Release.Name }}-redis
{{- end }}
key: redis-password
- name: REDASH_REDIS_HOSTNAME
- name: REDASH_CACHE_HOSTNAME
value: {{ include "redash.redis.fullname" . }}
- name: REDASH_REDIS_PORT
- name: REDASH_CACHE_PORT
value: "{{ .Values.redis.master.service.ports.redis }}"
- name: REDASH_REDIS_DB
- name: REDASH_CACHE_NAME
value: "{{ .Values.redis.database }}"
{{- end }}
{{- end }}
Expand Down
19 changes: 7 additions & 12 deletions templates/adhocworker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ spec:
- name: {{ include "redash.name" . }}-adhocworker
securityContext:
{{- toYaml .Values.adhocWorker.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
image: "{{ .Values.image.registry }}/{{ .Values.image.repo }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/bin/sh"]
args: ["-c", ". /config/dynamicenv.sh && /app/bin/docker-entrypoint worker"]
{{- with .Values.adhocWorker.volumeMounts }}
volumeMounts:
- name: config
mountPath: /config
{{- with .Values.adhocWorker.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
args:
- worker
env:
{{- include "redash.env" . | nindent 12 }}
{{- range $key, $value := .Values.adhocWorker.env }}
Expand All @@ -58,13 +56,10 @@ spec:
{{- if .Values.adhocWorker.resources }}
resources: {{ toYaml .Values.adhocWorker.resources | nindent 12 }}
{{- end }}
{{- with .Values.adhocWorker.volumes }}
volumes:
- name: config
configMap:
name: {{ include "redash.fullname" . }}
{{- with .Values.adhocWorker.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if .Values.adhocWorker.nodeSelector }}
nodeSelector:
{{ toYaml .Values.adhocWorker.nodeSelector | indent 8 }}
Expand Down
93 changes: 0 additions & 93 deletions templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,93 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "redash.fullname" . }}
labels:
{{- include "redash.labels" . | nindent 4 }}
data:
install-upgrade.sh: |
#!/usr/bin/env bash
echo "This will retry connections until PostgreSQL/Redis is up, then perform database installation/migrations as needed."
# Status command timeout
STATUS_TIMEOUT=45
# Create tables command timeout
CREATE_TIMEOUT=60
# Upgrade command timeout
UPGRADE_TIMEOUT=600
# Time to wait between attempts
RETRY_WAIT=10
# Max number of attempts
MAX_ATTEMPTS=5
# Load connection variables
. /config/dynamicenv.sh
# Check Settings (for debug)
# /app/manage.py check_settings
# Initialize attempt counter
ATTEMPTS=0
while ((ATTEMPTS < MAX_ATTEMPTS)); do
echo "Starting attempt ${ATTEMPTS} of ${MAX_ATTEMPTS}"
ATTEMPTS=$((ATTEMPTS+1))
# Install and upgrade
if [[ "${1}" == "install" ]]; then
echo "Installing Redash:"
timeout $CREATE_TIMEOUT /app/manage.py database create_tables
echo "Tables created"
echo "Running Redash database migrations after install"
timeout $UPGRADE_TIMEOUT /app/manage.py db upgrade
echo "Upgrade complete"
fi
# Upgrade
if [[ "${1}" == "upgrade" ]]; then
echo "Running Redash database migrations:"
timeout $UPGRADE_TIMEOUT /app/manage.py db upgrade
echo "Upgrade complete"
fi
STATUS=$(timeout $STATUS_TIMEOUT /app/manage.py status 2>&1)
RETCODE=$?
echo "Return code: ${RETCODE}"
echo "Status: ${STATUS}"
case "$RETCODE" in
0)
exit 0
;;
124)
echo "Status command timed out after ${STATUS_TIMEOUT} seconds."
;;
esac
case "$STATUS" in
*sqlalchemy.exc.OperationalError*)
echo "Database not yet functional, waiting."
;;
*sqlalchemy.exc.ProgrammingError*)
echo "Database does not appear to be installed."
;;
esac
echo "Waiting ${RETRY_WAIT} seconds before retrying."
sleep 10
done
echo "Reached ${MAX_ATTEMPTS} attempts, giving up."
exit 1
dynamicenv.sh: |
# Build connection URLs from environment variables.
# NOTES:
# This script should be sourced, not run directly.
# All variables are expected to be set by the caller.
if [ -z "$REDASH_DATABASE_URL" ]; then
export REDASH_DATABASE_URL=postgresql://${REDASH_DATABASE_USER}:${REDASH_DATABASE_PASSWORD}@${REDASH_DATABASE_HOSTNAME}:${REDASH_DATABASE_PORT}/${REDASH_DATABASE_DB}
echo "Using Database: postgresql://${REDASH_DATABASE_USER}:******@${REDASH_DATABASE_HOSTNAME}:${REDASH_DATABASE_PORT}/${REDASH_DATABASE_DB}"
else
echo "Using external postgresql database"
fi
if [ -z "$REDASH_REDIS_URL" ]; then
export REDASH_REDIS_URL=redis://:${REDASH_REDIS_PASSWORD}@${REDASH_REDIS_HOSTNAME}:${REDASH_REDIS_PORT}/${REDASH_REDIS_DB}
echo "Using Redis: redis://:******@${REDASH_REDIS_HOSTNAME}:${REDASH_REDIS_PORT}/${REDASH_REDIS_DB}"
else
echo "Using external redis database"
fi
19 changes: 7 additions & 12 deletions templates/genericworker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ spec:
- name: {{ include "redash.name" . }}-genericworker
securityContext:
{{- toYaml .Values.genericWorker.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
image: "{{ .Values.image.registry }}/{{ .Values.image.repo }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/bin/sh"]
args: ["-c", ". /config/dynamicenv.sh && /app/bin/docker-entrypoint worker"]
{{- with .Values.genericWorker.volumeMounts }}
volumeMounts:
- name: config
mountPath: /config
{{- with .Values.genericWorker.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
args:
- worker
env:
{{- include "redash.env" . | nindent 12 }}
{{- range $key, $value := .Values.genericWorker.env }}
Expand All @@ -58,13 +56,10 @@ spec:
{{- if .Values.genericWorker.resources }}
resources: {{ toYaml .Values.genericWorker.resources | nindent 12 }}
{{- end }}
{{- with .Values.genericWorker.volumes }}
volumes:
- name: config
configMap:
name: {{ include "redash.fullname" . }}
{{- with .Values.genericWorker.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if .Values.genericWorker.nodeSelector }}
nodeSelector:
{{ toYaml .Values.genericWorker.nodeSelector | indent 8 }}
Expand Down
71 changes: 0 additions & 71 deletions templates/hook-install-job.yaml

This file was deleted.

Loading

0 comments on commit 8522b76

Please sign in to comment.