Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
--helm-set gateway.listener.hostname=tim-api.${{ env.PREVIEW_NS}}.dev.greybox.chat
--helm-set gateway.httpRoute.hostnames[0]=tim-api.${{ env.PREVIEW_NS}}.dev.greybox.chat
--helm-set externalSecrets.secrets.planetscale.enabled=false
--helm-set databaseMigration.enabled=true
--helm-set databaseMigration.image.tag=${{ github.event.pull_request.head.sha }}
--label environment=preview
--label argocd.argoproj.io/instance=tim-api
--sync-policy automated
Expand Down Expand Up @@ -177,10 +179,10 @@ jobs:
echo "Done."

- uses: actions/checkout@v5
- name: Run database migrations
uses: docker://amacneil/dbmate:2.28
with:
args: --wait --url ${{ steps.credentials.outputs.DB_URL }} --schema-file tim-db/gen/schema/schema.sql --migrations-dir tim-db/migrations up
# - name: Run database migrations
# uses: docker://amacneil/dbmate:2.28
# with:
# args: --wait --url ${{ steps.credentials.outputs.DB_URL }} --schema-file tim-db/gen/schema/schema.sql --migrations-dir tim-db/migrations up

- uses: azure/setup-kubectl@v3
- uses: teleport-actions/setup@v1
Expand Down
40 changes: 40 additions & 0 deletions charts/tim-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- $dbEnvVar := .Values.databaseMigration.databaseUrlEnvVar | default "TIM_API_DATABASE_URL" }}
{{- if .Values.databaseMigration.enabled }}
initContainers:
- name: dbmate-migrate
image: "{{ .Values.databaseMigration.image.repository }}:{{ .Values.databaseMigration.image.tag }}"
imagePullPolicy: {{ .Values.databaseMigration.image.pullPolicy }}
{{- if .Values.databaseMigration.command }}
command:
{{- toYaml .Values.databaseMigration.command | nindent 12 }}
{{- else }}
command:
- /bin/sh
- -c
- |
set -euo pipefail
DB_URL={{ printf "\"${%s:?%s must be set}\"" $dbEnvVar $dbEnvVar }}
SCHEMA_PATH="${SCHEMA_SQL_PATH:-/config/tim-db/gen/schema/schema.sql}"
MIGRATIONS_PATH="${MIGRATIONS_DIR:-/config/tim-db/migrations}"
echo "Running dbmate migrations from ${MIGRATIONS_PATH} ..."
dbmate --wait --url "${DB_URL}" --schema-file "${SCHEMA_PATH}" --migrations-dir "${MIGRATIONS_PATH}" up
{{- end }}
{{- if .Values.databaseMigration.args }}
args:
{{- toYaml .Values.databaseMigration.args | nindent 12 }}
{{- end }}
env:
- name: {{ $dbEnvVar }}
valueFrom:
secretKeyRef:
name: {{ .Values.databaseMigration.databaseUrlSecret.name }}
key: {{ .Values.databaseMigration.databaseUrlSecret.key }}
{{- range $key, $value := .Values.databaseMigration.extraEnv }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- with .Values.databaseMigration.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
containers:
- name: {{ include "tim-api.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down
18 changes: 18 additions & 0 deletions charts/tim-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ secrets:
key: segmentApiKey
envVarName: TIM_API_ANALYTICS_API_KEY

databaseMigration:
enabled: false
# Image built from tim-db/Dockerfile (inherits schema + migrations from repo)
image:
repository: ghcr.io/greybox-labs/tim-db
tag: "latest"
pullPolicy: IfNotPresent
# Secret that provides the database URL value exposed as TIM_API_DATABASE_URL
databaseUrlSecret:
name: database-url-with-pass
key: dbUrl
databaseUrlEnvVar: TIM_API_DATABASE_URL
# Optional explicit command/args; when empty a sane default runs dbmate up
command: []
args: []
extraEnv: {}
resources: {}

podAnnotations: {}

# Service Account configuration
Expand Down
11 changes: 2 additions & 9 deletions scripts/just/docker.just
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ USE_LATEST_TAG := env_var_or_default("USE_LATEST_TAG", AUTO_USE_LATEST)
AUTO_USE_PR_TAG := if BUILD_CONTEXT == "pr" { if PR_NUMBER == "" { "false" } else { "true" } } else { "false" }
USE_PR_TAG := env_var_or_default("USE_PR_TAG", AUTO_USE_PR_TAG)

# Helper to get discovered components (runs from project root)
[no-cd]
_get-components:
find . -mindepth 2 -maxdepth 2 -type f -name 'Dockerfile' -exec dirname {} \; \
| sed 's#^\./##' \
| LC_ALL=C sort -u

# Helper to get discovered component paths (runs from project root)
[no-cd]
_get-component-paths:
Expand Down Expand Up @@ -347,7 +340,7 @@ push-summary:
if test -s "$PUSHED_FILE"; then
echo "### Images Successfully Pushed:"
while IFS= read -r image; do
echo "- \`$image\`"
printf -- "- \`%s\`\n" "$image"
done < "$PUSHED_FILE"
echo ""
echo "**Total images:** $(wc -l < "$PUSHED_FILE")"
Expand All @@ -365,7 +358,7 @@ component-push-summary:
if test -s "$PUSHED_FILE"; then
echo "### Component Images Successfully Pushed:"
while IFS= read -r image; do
echo "- \\`$image\\`"
printf -- "- \`%s\`\n" "$image"
done < "$PUSHED_FILE"
echo ""
echo "**Total component images:** $(wc -l < "$PUSHED_FILE")"
Expand Down
10 changes: 10 additions & 0 deletions tim-db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# syntax=docker/dockerfile:1-labs

FROM amacneil/dbmate:2.28

ENV CONFIG_ROOT=/config
ENV SCHEMA_SQL_PATH=${CONFIG_ROOT}/tim-db/gen/schema/schema.sql
ENV SCHEMA_MERMAID_PATH=${CONFIG_ROOT}/tim-db/gen/schema/schema.mmd
ENV MIGRATIONS_DIR=${CONFIG_ROOT}/tim-db/migrations

COPY --from=root --parents tim-db/gen/schema tim-db/migrations tim-db/queries tim-db/queries ${CONFIG_ROOT}
Loading