diff --git a/.github/workflows/deploy-postgres.yml b/.github/workflows/deploy-postgres.yml index 4537e45..f30a5c3 100644 --- a/.github/workflows/deploy-postgres.yml +++ b/.github/workflows/deploy-postgres.yml @@ -1,19 +1,16 @@ -name: Deploy DB Infrastructure +name: Deploy DEV DB Infrastructure on: push: branches: - - main - + - "feature/*" jobs: deploy: runs-on: mealcraft-runners steps: - - name: Checkout repo - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - # Install kubectl - name: Install kubectl run: | sudo apt-get update @@ -21,72 +18,38 @@ jobs: curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -m 0755 kubectl /usr/local/bin/kubectl - # Configure kubeconfig (ARC in-cluster) - - name: Configure kubeconfig + - name: Configure kubeconfig (in-cluster) run: | KUBE_HOST="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT" SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) - kubectl config set-cluster microk8s \ - --server="$KUBE_HOST" \ - --certificate-authority="$CA_CERT" - - kubectl config set-credentials runner \ - --token="$SA_TOKEN" - - kubectl config set-context runner-context \ - --cluster=microk8s \ - --user=runner \ - --namespace="$NAMESPACE" - + kubectl config set-cluster microk8s --server="$KUBE_HOST" --certificate-authority="$CA_CERT" + kubectl config set-credentials runner --token="$SA_TOKEN" + kubectl config set-context runner-context --cluster=microk8s --user=runner --namespace="$NAMESPACE" kubectl config use-context runner-context - # 1️⃣ Secrets - - name: Apply DB secrets - run: | - kubectl apply -f db/k8s/secrets/ + - name: Apply DEV secrets + run: kubectl apply -f db/k8s/dev/secrets/ - # 2️⃣ PostgreSQL - - name: Deploy Postgres - run: | - kubectl apply -f db/k8s/postgres/ + - name: Deploy DEV Postgres + run: kubectl apply -f db/k8s/dev/postgres/ - # 3️⃣ Backups (CronJob) - - name: Deploy Postgres backups - run: | - kubectl apply -f db/k8s/backups/ + - name: Deploy DEV backups + run: kubectl apply -f db/k8s/dev/backups/ migrate: runs-on: mealcraft-runners needs: deploy steps: - - name: Checkout repo - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - # Install Atlas - - name: debug - run: | - ls -la - pwd + - name: Install Atlas + run: curl -sSf https://atlasgo.sh | sh - - name: Install kubectl - run: | - sudo apt-get update - sudo apt-get install -y curl ca-certificates - curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" - sudo install -m 0755 kubectl /usr/local/bin/kubectl - - - # Install Atlas - - name: Install Atlas CLI - run: | - curl -sSf https://atlasgo.sh | sh - - # Load DB creds from Kubernetes secret - - name: Load Postgres credentials + - name: Load DEV DB creds 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) @@ -94,10 +57,8 @@ jobs: echo "POSTGRES_USER=$POSTGRES_USER" >> $GITHUB_ENV echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $GITHUB_ENV - - name: Run Atlas migrations (dev) + - name: Run Atlas migrations (DEV) run: | atlas migrate apply \ --config file://./db/atlas/atlas.hcl \ --env stripe_invoice_dev - - \ No newline at end of file diff --git a/db/k8s/migrations/stripe-to-invoice-dev-migrate.yaml b/db/k8s/migrations/stripe-to-invoice-dev-migrate.yaml index f0e8384..d18c7ac 100644 --- a/db/k8s/migrations/stripe-to-invoice-dev-migrate.yaml +++ b/db/k8s/migrations/stripe-to-invoice-dev-migrate.yaml @@ -9,7 +9,8 @@ spec: containers: - name: atlas image: arigaio/atlas:latest - command: ["atlas", "migrate", "apply", "--env", "stripe_invoice_dev"] + command: ["/atlas"] + args: ["migrate", "apply", "--env", "stripe_invoice_dev"] envFrom: - secretRef: name: postgres-secret diff --git a/db/k8s/migrations/stripe-to-invoice-prod-migrate.yaml b/db/k8s/migrations/stripe-to-invoice-prod-migrate.yaml index 728da8e..ab2b1c0 100644 --- a/db/k8s/migrations/stripe-to-invoice-prod-migrate.yaml +++ b/db/k8s/migrations/stripe-to-invoice-prod-migrate.yaml @@ -9,7 +9,7 @@ spec: containers: - name: atlas image: arigaio/atlas:latest - command: ["atlas", "migrate", "apply", "--env", "stripe_invoice_prod"] + command: ["migrate", "apply", "--env", "stripe_invoice_prod"] envFrom: - secretRef: name: postgres-secret