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mzzvxww08Iz2QTw6egNP1SpRlID0xp30ZkRWSi1M7KZWm61tRjI0rXG8HobFmSW3okmKfy7qbk4hHPx9n7ot39YoFTjezJitd+pmZn9p4nPa/FEbUFg0pcBHLfrGM8mXI5sAQPXlJpRlTx9AUq+VuMlY4d4ewOXaOXC/AfQzb+WPWgMQFQXk6Bdse5Vx5giET41I+v3fTUT5Ig+6X7Is8zZeZ21XOn0Q2CuE3Wj/cAtpIxEgi1mOaa05A6W6aZ35fbKJhekV+Z5DkowjriZx/w6BnOsIfopGn4aU/CdjOAkixe9qavn1KFdApW/g3zcbKqTcSpgk2XdB/JwwcWCbOd+Nc15CM=

before_install:
  - sudo apt-get update
  - sudo apt-get install -qy -o Dpkg::Options::="--force-confold" docker-ce coreutils
  - sudo apt-get install -y zlib1g-dev

script:
  # Bring up the postgres, redis, and app containers
  - docker-compose up --build -d

  - timeout $GREP_TIMEOUT grep -m 1 'Running migrations' <(docker-compose logs --follow app 2>&1)
  - timeout $GREP_TIMEOUT grep -m 1 'spawned uWSGI http 1' <(docker-compose logs --follow app 2>&1)
  - docker-compose run app /bin/sh -c "/venv/bin/pip install flake8 && /venv/bin/flake8 ."
  - docker-compose run app /venv/bin/python /code/manage.py check
  - docker-compose run app /venv/bin/python /code/manage.py makemigrations --check
  - docker-compose run app /venv/bin/python /code/manage.py load_initial_data
  # Check for broken image links (wget will have a non-zero exit code if it encounters a 404)
  - wget -m http://localhost:8000

after_script:
  - docker-compose logs
  - docker images

deploy:
  provider: script
  script: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin && docker tag bakerydemo_app wagtail/bakerydemo:latest && docker tag bakerydemo_app wagtail/bakerydemo:release-$(git rev-parse --short ${TRAVIS_COMMIT}) && docker push wagtail/bakerydemo
  on:
    branch: master
