0

I have 3 services. DB, API, Liquibase. API is dependant on DDB and Liquibase. Below is my compose.yml. The issue I am facing is, even though I have wait-for.sh script under API service which waits for DB port to be available for connections, it comes up as soon as the port is ready for connections. But liquibase which creates Db schema and applies DB related changes is still under process. So the API service is not able to connect to DB as the schema is still not created by the liquibase service. how do I make API service to wait until liquibase applies all the changes on DB.

version: '3'
services:
   db:
    build: drs-db
    user: "1000:50"
    volumes:
      - /data/mysql:/var/lib/mysql
    container_name: drs-db
    environment:  
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    ports:
      - "3307:3306"

   drs-api:
    container_name: drs-api
    hostname: drs-api
    domainname: XX.com
    build:
      context:  ./drs-api
      args:
        DRS_API_URL: XX/${DRS_API_VERSION}
        DRS_API_WAR: drs-web-${DRS_API_VERSION}.war
        DRS_CLIENT_URL: CC/drs-client/${DRS_CLIENT_VERSION}
        DRS_CLIENT_WAR: drs-client-${DRS_CLIENT_VERSION}.war
    ports:  
      - "8096:8443"
    depends_on:
      - db
      - drs-liquibase
    command: [/usr/local/bin/wait-for-it.sh]
    links:
      - "drs-liquibase"

   drs-liquibase:
     container_name: drs-liquibase
     build:
       context: ./drs-liquibase
     environment:
       DRS_CLIENT_VERSION : ${DRS_LIQUIBASE_VERSION}
     depends_on: 
      - db
     links:
       - "db"
     command: ["/usr/local/bin/wait_for_liquibase.sh"]
Abhi.G
  • 1,801
  • 5
  • 20
  • 35

1 Answers1

1

You could use some kind of temporary file via shared volume.

Adjust wait-for to check for the presence of a file created when migrations are ready or wait until file is deleted by migration service.

opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143
  • Do you know how can I share volume across containers? I tried Volume tag under compose.yml but it did not work. – Abhi.G Jul 31 '18 at 08:39
  • check this answer: https://stackoverflow.com/questions/37000341/sharing-volume-between-docker-containers – opHASnoNAME Jul 31 '18 at 09:18
  • 1
    Thank you and it works. I can mark this as an answer. Let me know if there is a docker way of doing this. Like sharing environment variables across containers. – Abhi.G Aug 01 '18 at 08:34