Flyway job is not executing command

9/13/2021

The problem

I have a flyway job that is meant to be performing migrations on a postgres database. The job doesn't seem to be running the command and inspection of the jobs logs only output flyway documentation.

Expectations

I expect the log inspection to be a synopsis of the migrations occurred. I also have installed pgweb to allow for observability and after connecting to my postgres pod, it is clear no tables have been created at all.

Here is a photo of the expected output from kubectl logs flyway-pod Migrations expected output

What I get

This is the output of kubectl logs flyway-pod Flyway Logs output As you can see it prints the usage guide rather than a sign that the migration occurred.

What I have tried -explanation

I have so far been moving the connection command around.

I have commented out the locations where I have tried placing the command. I have tried it in 3 locations. 1. Inside the original Flyway Dockerfile and nowhere else. 2. Inside the docker compose file near the flyway service and nowhere else. 3. Inside the Kubernetes Flyway job and nowhere else.

Code

Here are my files and setup.

Kubernetes files

What follows are the relevant Kubernetes files used to setup my cluster.

Flyway Job:

Here is the Flyway job:

kind: Job
metadata:
  name: flyway-migration-job
spec:
  template:
    spec:
      containers:
      - name: flyway
        image: flyway/flyway:6.3.1
        command: ["flyway", "-url=jdbc:postgresql://postgres-master:5432/wallet", "-user=test_user", "-password=testuser1234", "-schemas=wallet", "-connectRetries=60 migrate"]
      restartPolicy: OnFailure

Postgres Deployment and Service

Postgres Deployment file

kind: Deployment
metadata:
  name: postgres-master
  labels:
    app: postgres-master
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres-master
  template:
    metadata:
      labels:
        app: postgres-master
    spec:
      containers:
        - name: postgres-master
          image: postgres:13
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: wallet
            - name: POSTGRES_USER
              value: test_user
            - name: POSTGRES_PASSWORD
              value: testuser1234
      

Postgres service

apiVersion: v1
kind: Service
metadata:
  name: postgres-master
  labels: 
    app: postgres-master
spec: 
  type: NodePort
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
  selector: 
    app: postgres-master

Docker files

As I am building my images locally and pulling them into my cluster using kind, I will attach my relevant Dockerfiles.

Flyway Dockerfile

FROM flyway/flyway:7.7.3-alpine

COPY ./migrations/sql /flyway/sql/

#CMD ["flyway -url=jdbc:postgresql://postgres-master:5432/wallet -user=test_user -password=testuser1234  -connectRetries=60 -schemas=wallet migrate"]

Flyway SQL script

This script is stored inside migrations/sql

CREATE TABLE wallet.transaction_events (
    transaction_version int,
    transaction_type VARCHAR(200),
    coins int,
    transaction_id VARCHAR(500),
    wallet_id VARCHAR(500)
)

Docker compose

Here is the docker compose file that I use to build my images before pulling into kind/my cluster.

version: '3.5'
services:
  web:
    build:
      dockerfile: ./Dockerfile
    container_name: wallet-api-web
    depends_on: 
      - flyway
    ports: 
      - "8080:8080"
  postgres-db:
    build:
      dockerfile: ./utils/db.Dockerfile
    container_name: postgres-db
    environment:
      POSTGRES_PASSWORD: testuser1234
      POSTGRES_USER: test_user
      POSTGRES_DB: wallet
    image: postgres:13
    ports:
      - "5432:5432"
    restart: always

  flyway:
    build:
      dockerfile: ./migrations/Dockerfile
    #command: -url=jdbc:postgresql://postgres-master:5432/wallet -user=test_user -password=testuser1234 -schemas=wallet -connectRetries=60 migrate 
    container_name: flyway-migrations
    depends_on:
      - db
    image: flyway/flyway:6.3.1
    volumes:
      - ${PWD}/migrations/sql:/flyway/sql

I think I have covered everything required to provide context to my problem but if any clarifications are required feel free to ask.

I really appreciate any help with getting these migrations working. Thank you

-- befoca1956
docker
flyway
kubernetes
migration
postgresql

1 Answer

9/13/2021

You command is in array syntax, that means that each parameter must be a separate element. You have two parameters in the last element, which flyway does not understand.

To fix:

"-connectRetries=60 migrate"]

change to

"-connectRetries=60", "migrate"]
-- Thomas
Source: StackOverflow