Skip to content

Commit

Permalink
feat: run migrations from another image
Browse files Browse the repository at this point in the history
  • Loading branch information
javascriptizer1 committed Jun 15, 2024
1 parent da32456 commit c3ce6d3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
NAMESPACE: ${{ secrets.NAMESPACE }}
IMAGE: andreq21/auth:${{ github.sha }}
IMAGE_MIGRATOR: andreq21/auth-migrator:${{ github.sha }}

jobs:
lint:
Expand Down Expand Up @@ -48,6 +49,7 @@ jobs:
- name: Build Docker image
run: |
docker build -t $IMAGE -f ./service/auth/Dockerfile .
docker build -t $IMAGE_MIGRATOR -f ./service/auth/migration.Dockerfile .
- name: Login to Docker Hub
run: |
Expand All @@ -56,6 +58,7 @@ jobs:
- name: Push Docker image to Docker Hub
run: |
docker push $IMAGE
docker push $IMAGE_MIGRATOR
deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -104,4 +107,4 @@ jobs:
- name: Deploy to Kubernetes
run: |
helm upgrade --install auth ./deploy/helm/auth --namespace=$NAMESPACE --set app.image.tag=$IMAGE
helm upgrade --install auth ./deploy/helm/auth --namespace=$NAMESPACE --set app.image.tag=$IMAGE --set migrator.image.tag=$IMAGE_MIGRATOR
14 changes: 2 additions & 12 deletions deploy/helm/auth/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ spec:
imagePullSecrets:
- name: j11er-docker-registry
initContainers:
- name: migrations
image: {{ .Values.app.image.tag }}
- name: migrator
image: {{ .Values.migrator.image.tag }}
imagePullPolicy: IfNotPresent
envFrom:
- configMapRef:
name: auth-backend-env-config
command: ["/bin/sh"]
args: ["/opt/scripts/run-migrations.sh"]
volumeMounts:
- name: bash-script-migrations
mountPath: /opt/scripts/
subPath: run-migrations.sh
containers:
- name: auth-backend
image: {{ .Values.app.image.tag }}
Expand All @@ -45,7 +39,3 @@ spec:
requests:
cpu: 100m
memory: 256Mi
volumes:
- name: bash-script-migrations
configMap:
name: bash-script-migrations
17 changes: 0 additions & 17 deletions deploy/helm/auth/templates/migration-configmap.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions deploy/helm/auth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ app:
port: 50051
image:
tag: ""

migrator:
image:
tag: ""
13 changes: 13 additions & 0 deletions service/auth/migration.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.20

RUN apk update && apk upgrade && apk add bash && rm -rf /var/cache/apk/*

ADD https://github.com/pressly/goose/releases/download/v3.20.0/goose_linux_x86_64 /bin/goose
RUN chmod +x /bin/goose

WORKDIR /opt

COPY service/auth/migrations ./migrations

ENV GOOSE_DBSTRING=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
RUN /bin/goose -dir ./migrations/postgres postgres up

0 comments on commit c3ce6d3

Please sign in to comment.