diff --git a/.github/workflows/atlas-migratie-dev.yml b/.github/workflows/atlas-migratie-dev.yml new file mode 100644 index 0000000..ba1e351 --- /dev/null +++ b/.github/workflows/atlas-migratie-dev.yml @@ -0,0 +1,35 @@ +name: Atlas Migrate (dev) + +on: + push: + branches: + - main + +jobs: + migrate: + runs-on: mealcraft-runners + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + # Install Atlas + - name: Install Atlas CLI + run: | + curl -sSf https://atlasgo.sh | sh + + # Load DB creds from Kubernetes secret + - name: Load Postgres credentials + run: | + export POSTGRES_USER=$(kubectl get secret postgres-secret -o jsonpath='{.data.POSTGRES_USER}' | base64 -d) + export POSTGRES_PASSWORD=$(kubectl get secret postgres-secret -o jsonpath='{.data.POSTGRES_PASSWORD}' | base64 -d) + + echo "POSTGRES_USER=$POSTGRES_USER" >> $GITHUB_ENV + echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $GITHUB_ENV + + # Run Atlas migrations (DEV only) + - name: Run Atlas migrations (dev) + run: | + atlas migrate apply \ + --env stripe_invoice_dev \ + --dir file://db/atlas/stripe_invoice/migrations diff --git a/db/atlas/atlas.hcl b/db/atlas/atlas.hcl index 34a9cd9..27a427e 100644 --- a/db/atlas/atlas.hcl +++ b/db/atlas/atlas.hcl @@ -1,6 +1,13 @@ -env "k8s" { - url = "postgres://$DB_USER:$DB_PASSWORD@postgres:5432/stripe_invoice?sslmode=disable" +env "stripe_invoice_dev" { + url = "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/stripe_invoice_dev?sslmode=disable" migration { - dir = "file://atlas/migrations" + dir = "file://atlas/stripe_invoice/migrations" + } +} + +env "stripe_invoice_prod" { + url = "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/stripe_invoice_prod?sslmode=disable" + migration { + dir = "file://atlas/stripe_invoice/migrations" } } \ No newline at end of file diff --git a/db/k8s/migrations/atlas-job.yaml b/db/k8s/migrations/atlas-job.yaml index 6c1e3b0..247e09c 100644 --- a/db/k8s/migrations/atlas-job.yaml +++ b/db/k8s/migrations/atlas-job.yaml @@ -9,7 +9,7 @@ spec: containers: - name: atlas image: arigaio/atlas:latest - command: ["atlas", "migrate", "apply", "--env", "k8s"] + command: ["atlas", "migrate", "apply", "--env", "stripe_invoice"] envFrom: - secretRef: name: postgres-secret diff --git a/db/k8s/postgres/deployment.yaml b/db/k8s/postgres/deployment.yaml index ce76d3c..b17f542 100644 --- a/db/k8s/postgres/deployment.yaml +++ b/db/k8s/postgres/deployment.yaml @@ -1,19 +1,4 @@ # -------------------------------------------------- -# PostgreSQL Secret -# -------------------------------------------------- -apiVersion: v1 -kind: Secret -metadata: - name: postgres-secret - namespace: default -type: Opaque -stringData: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgrespassword - POSTGRES_DB: stripe_invoice - ---- -# -------------------------------------------------- # PersistentVolume (local disk on mist) # -------------------------------------------------- apiVersion: v1