8

Docs

I'm trying to pass multiple commands in a conainter_commands entry and keep getting errors. Yet when I pass the same commands as individual entries it works fine.

Works:

container_commands:
  01_remove_old_dump:
    command: 'rm -f /tmp/db.dump'
  02_get_new_dump:
    command: 'aws s3 cp s3://bucket/db.dump'

Fails with /bin/sh: rm -f /tmp/db.dump: No such file or directory.

container_commands:
  01_remove_old_dump:
    command: ('rm -f /tmp/db.dump' 'aws s3 cp s3://bucket/db.dump')
Ryan Fisher
  • 1,485
  • 1
  • 19
  • 32

1 Answers1

11

Never mind, I just broke the lines up with a YAML block and that works:

01_command:
    command: |
      if [[ ! $ENVIRONMENT = "PROD" ]] && [[ $RDS_HOSTNAME ]]
          rm -f /tmp/db.dump
          aws s3 cp s3://bucket/db.dump
          pg_restore -H $RDS_HOSTNAME dbname /tmp/db.dump
          echo "Refreshing database..."
      else
          Echo "Environment is ${ENVIRONMENT}. Skipping database refresh..."
      fi

NOTE: Removed this, it doesn't seem to work (always returns true):

    test: |
      [[ ! $ENVIRONMENT = "PRODUCTION" ]] && \
      [[ $RDS_HOSTNAME ]] && \
      echo "Refreshing database..."
Ryan Fisher
  • 1,485
  • 1
  • 19
  • 32
  • 3
    Thank you! I was banging my ahead against the wall on this forever. Their docs are wrong. – vcardillo Aug 18 '16 at 22:08
  • 2
    Note, the test syntax here doesn't seem to work. I thought it was working, but found out that it was returning `true` every time. I ended up wrapping my command in an if statement that conducts the same test. – Ryan Fisher Aug 22 '16 at 19:01