Want to run migrations as kubernetes jobs using automig so that you don't have to manually define up
and down
steps? You're in the right place.
The stuff in this folder should guide you through attaching automig to your git repo & kube cluster.
Bear in mind:
- Warts are to be expected, raise issues if these docs are incomplete / unclear / wrong
- That being said, such support is not guaranteed
- Loss of data or undesired extra data are among the many possible bad outcomes of using this
- Be familiar with kustomize (the kube-native helm replacement)
- Be using postgres -- the toolchain will need some tweaks to work with mysql
- Set up your repo to build a docker image for migration
- add automig.Dockerfile to your project repo (it's named that way to avoid colliding with your existing
Dockerfile
) - edit the
COPY schema schema/
line in automig.Dockerfile to the folder where you store your SQL schema file(s) - update your CI spec to write to your container registry (there's a sample .gitlab-ci.yml in this folder)
- add automig.Dockerfile to your project repo (it's named that way to avoid colliding with your existing
- Wire up kustomize
- in theory this will work whether or not you're currently using kustomize, but no promises
- in kustomization.yml, edit
name
andnewTag
to match your image name - in migrate.yml, edit
image
to match your image name - still in migrate.yml, update the names of the secrets to match what you're using
database-credentials
is a secret that has a postgres connection string (postgres://
or whatever) in the libpq-url keyregcred
has a dockerconfigjson for your container registry; you may not need this if your registry is integrated with your cloud host
- in migrate.yml, update
AUTOMIG_GLOB
to whatever you're using - Run kustomize to apply this to your cluster, fix / report any errors
(Todo: add instructions for attaching automig to an existing database).
- In migrate.yml, change
update
in thecommand
toinit
- Run kustomize to apply this to your cluster
- Run a copy of the migration job with:
kubectl create job mig-$(shell whoami)-$(shell date -u +%Y%m%d-%H%M) --from=cronjob/migrate
- Use
kubectl get job
andkubectl logs job/whatever -f
to wait for success - Important: once this works, change
init
back toupdate
and rerun kustomize
- In kustomize.yml, change
newTag
to your desired sha - Run customize to apply this to your cluster
- Run and watch the migration job with steps 3 & 4 above