There's these instructions from redhat but they're cooking their own flyway.
Here's what I've done:
I have a dockerfile that looks like this:
FROM boxfuse/flyway
ADD ./flyway /flyway
#TODO: pass the username/password in from kubernetes
CMD ["-X", "-url=jdbc:mysql://db-service", "-schemas=myapp", "-user=root", "-password=P@ssw0rd", "migrate"]
And I build it with:
docker build -t flyway-migrate:3 .
Where 3 is the number that the flyway migration is up to.
I then have a kubernetes job to run this script:
apiVersion: batch/v1
kind: Job
metadata:
name: flyway-job
spec:
template:
metadata:
labels:
app: java-app
tier: flyway
track: stable
spec:
containers:
- name: flyway
image: "flyway-migrate:3"
imagePullPolicy: IfNotPresent
restartPolicy: Never
This works fine, but there's a few questions I have.
- Whenever increment the flyway migration number, I have to rebuild the image, and then update the job, and delete the existing job and recreate it.
- Is there a way to rerun jobs?
- Is there a way to run the kubernetes job saying 'Use this image tag'.
flyway-migratate-v1.yaml, flyway-migrate-v2.yamletc? – Mar 26 '18 at 03:51Have one job yaml file in version control. Update it after the build of the migration artifact, to bump the name of the job, and the name of the image used in migration. Commit and test run outside prod, then run in prod.
That approach preserves immutability and yields the most complete history, useful in case something unpleasant happens.
– Jonah Benton Mar 26 '18 at 04:14