Search code examples
pythonflywayaws-codebuild

Running a flyway command is simply printing the help and exiting in python script


So I have a Python script that I'm running via AWS CodeBuild. It's using the flyway command line docker container to execute the following command:

cmd = 'flyway -user=' + connection_items['username'] + ' -password=' + connection_items['password'] + ' migrate'
os.system(cmd) # I know this is insecure... just trying to get a migration to run

What happens is it executes flyway without any of the arguments which just prints the help and exits. Anyone have any suggestions as to what I am doing wrong? I can't run via the subprocess module yet (I'm having path issues)

Thanks!


Solution

  • It looks more like a shell expansion issue than CodeBuild.

    Your buildspec was confusing, I rewrote your buildspec as follows. I hope this helps:

    ---
    version: 0.2
    phases:
      install:
        runtime-versions:
          python: 3.7
        commands:
         - echo "Installing flyway..."
         - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 --storage-driver=overlay&
         - timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
         - echo "docker run --rm flyway/flyway:6.0.4 -url=jdbc:mysql://db -schemas=myschema -user=root -password=P@ssw0rd -connectRetries=60 migrate" > /usr/local/bin/flyway 
         - chmod +x /usr/local/bin/flyway
         - 
      build:
        commands:
          - echo building...
          - /usr/local/bin/flyway
          - python MigrateDatabase.py
    

    Also, I am sure you are already setting the privilege mode to true for the project environment.