diff --git a/.github/workflows/packages-migrations.yaml b/.github/workflows/packages-migrations.yaml index 530b16bf0..99abaafe9 100644 --- a/.github/workflows/packages-migrations.yaml +++ b/.github/workflows/packages-migrations.yaml @@ -4,15 +4,13 @@ on: pull_request: branches: ["*"] paths: - - packages/db/** + - packages/db/drizzle/** - .github/workflows/packages-migrations.yaml - - pnpm-lock.yaml push: branches: ["main"] paths: - - packages/db/** + - packages/db/drizzle/** - .github/workflows/packages-migrations.yaml - - pnpm-lock.yamlaa jobs: build: diff --git a/deploy/ctrlplane/Chart.lock b/deploy/ctrlplane/Chart.lock index 3a376f005..bd5189664 100644 --- a/deploy/ctrlplane/Chart.lock +++ b/deploy/ctrlplane/Chart.lock @@ -5,5 +5,8 @@ dependencies: - name: job-policy-checker repository: file://charts/job-policy-checker version: 0.1.0 -digest: sha256:f886849879773b410f68b2d3293065605b5c82987ad285d9c974b9f9ee0f3bd2 -generated: "2024-08-23T23:39:43.317846-04:00" +- name: migrations + repository: file://charts/migrations + version: 0.1.0 +digest: sha256:7009169bab87614dc2bf33508ac69a2ce674c4565a6fdc0f3b571ad461c7d991 +generated: "2024-08-24T23:49:27.165058-04:00" diff --git a/deploy/ctrlplane/Chart.yaml b/deploy/ctrlplane/Chart.yaml index 4e52fb19a..fd877f44b 100644 --- a/deploy/ctrlplane/Chart.yaml +++ b/deploy/ctrlplane/Chart.yaml @@ -14,3 +14,7 @@ dependencies: version: "*.*.*" repository: file://charts/job-policy-checker condition: job-policy-checker.install + - name: migrations + version: "*.*.*" + repository: file://charts/migrations + condition: migrations.install diff --git a/deploy/ctrlplane/charts/migrations/.helmignore b/deploy/ctrlplane/charts/migrations/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deploy/ctrlplane/charts/migrations/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deploy/ctrlplane/charts/migrations/Chart.yaml b/deploy/ctrlplane/charts/migrations/Chart.yaml new file mode 100644 index 000000000..5eb75799d --- /dev/null +++ b/deploy/ctrlplane/charts/migrations/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: migrations +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/deploy/ctrlplane/charts/migrations/templates/_helpers.tpl b/deploy/ctrlplane/charts/migrations/templates/_helpers.tpl new file mode 100644 index 000000000..1fa90a0f1 --- /dev/null +++ b/deploy/ctrlplane/charts/migrations/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "migrations.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "migrations.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "migrations.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "migrations.labels" -}} +helm.sh/chart: {{ include "migrations.chart" . }} +{{ include "migrations.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "migrations.selectorLabels" -}} +app.kubernetes.io/name: {{ include "migrations.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "migrations.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "migrations.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/ctrlplane/charts/migrations/templates/job.yaml b/deploy/ctrlplane/charts/migrations/templates/job.yaml new file mode 100644 index 000000000..0dcc0efc3 --- /dev/null +++ b/deploy/ctrlplane/charts/migrations/templates/job.yaml @@ -0,0 +1,35 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "migrations.fullname" . }} + labels: + {{- include "migrations.labels" . | nindent 4 }} + {{- if .Values.job.labels }} + {{- toYaml .Values.job.labels | nindent 4 }} + {{- end }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded + {{- if .Values.job.annotations }} + {{- toYaml .Values.job.annotations | nindent 4 }} + {{- end }} +spec: + activeDeadlineSeconds: {{ .Values.activeDeadlineSeconds }} + backoffLimit: {{ .Values.backoffLimit }} + template: + metadata: + name: "database" + labels: + {{- include "migrations.labels" . | nindent 8 }} + spec: + restartPolicy: OnFailure + automountServiceAccountToken: false + containers: + - name: migrations + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{- include "ctrlplane.extraEnv" . | nindent 12 }} + {{- include "ctrlplane.extraEnvFrom" (dict "root" $ "local" .) | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} diff --git a/deploy/ctrlplane/charts/migrations/values.yaml b/deploy/ctrlplane/charts/migrations/values.yaml new file mode 100644 index 000000000..9589d73ce --- /dev/null +++ b/deploy/ctrlplane/charts/migrations/values.yaml @@ -0,0 +1,28 @@ +nameOverride: "" +fullnameOverride: "" + +activeDeadlineSeconds: 3600 +backoffLimit: 6 + +image: + repository: ctrlplane/migrations + tag: latest + pullPolicy: Always + +extraEnv: {} +extraEnvFrom: {} + +tolerations: [] +pod: {} + +job: + labels: {} + annotations: {} + +resources: + requests: + cpu: 500m + memory: 1Gi + limits: + cpu: 1000m + memory: 4Gi diff --git a/deploy/ctrlplane/values.yaml b/deploy/ctrlplane/values.yaml index b87797e73..41340e75a 100644 --- a/deploy/ctrlplane/values.yaml +++ b/deploy/ctrlplane/values.yaml @@ -12,6 +12,9 @@ webservice: job-policy-checker: install: true +migrations: + install: true + ingress: create: true class: "" diff --git a/deploy/docker-compose.yaml b/deploy/docker-compose.yaml new file mode 100644 index 000000000..d4aed6e7a --- /dev/null +++ b/deploy/docker-compose.yaml @@ -0,0 +1,50 @@ +version: "3.8" + +services: + postgres: + image: postgres:15 + container_name: postgres + environment: + POSTGRES_USER: ctrlplane + POSTGRES_PASSWORD: ctrlplane + POSTGRES_DB: ctrlplane + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + rabbitmq: + image: rabbitmq:3-management + container_name: rabbitmq + environment: + RABBITMQ_DEFAULT_USER: ctrlplane + RABBITMQ_DEFAULT_PASS: ctrlplane + ports: + - "5672:5672" + - "15672:15672" + + webservice: + image: ctrlplane/webservice + container_name: webservice + environment: + AUTH_SECRET: "" + DATABASE_URL: postgres://ctrlplane:ctrlplane@postgres:5432/ctrlplane + RABBITMQ_URL: amqp://ctrlplane:ctrlplane@rabbitmq:5672 + depends_on: + - postgres + - rabbitmq + ports: + - "8080:8080" + + job-policy-checker: + image: ctrlplane/my-job-policy-checker-image + container_name: job-policy-checker + environment: + POSTGRES_URL: postgres://ctrlplane:ctrlplane@postgres:5432/ctrlplane + RABBITMQ_URL: amqp://ctrlplane:ctrlplane@rabbitmq:5672 + depends_on: + - postgres + - rabbitmq + +volumes: + postgres_data: