version: "2.1"

services:
  database:
    image: postgres:10-alpine
    environment:
      - POSTGRES_DB=budget
      - POSTGRES_PASSWORD=budget
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "5432"
    healthcheck:
      test: ["CMD-SHELL", "psql -U postgres -c 'SELECT 1;'"]
      interval: 10s
      timeout: 30s
      retries: 3

  liquibase:
    image: kilna/liquibase-postgres
    depends_on:
      database:
        condition: service_healthy
    links:
      - database
    environment:
      - LIQUIBASE_DATABASE=budget
      - LIQUIBASE_HOST=database
      - LIQUIBASE_USERNAME=budget
      - LIQUIBASE_PASSWORD=budget
      - LIQUIBASE_CHANGELOG=/changelogs/changelog-master.xml
      - LIQUIBASE_URL=jdbc:postgresql://database:5432/postgres
    volumes:
      - $PWD/liquibase/changelogs/:/workspace
    command:
      - liquibase
      - --defaultsFile=/workspace/liquibase.properties
      - update
