Skip to content

Docker container that blocks until given endpoints return a JSON response

Notifications You must be signed in to change notification settings

FusionAuth/docker-wait-for-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Example usage:

Sample docker-compose.yml:

version: '3'

services:
  startup_services:
    image: fusionauth/wait-for-json
    depends_on:
      - fusionauth
    networks:
      - fusionauth
    command: fusionauth:9011/api/status

  db:
    image: postgres:9.6
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - 54320:5432
    networks:
      - db
    restart: unless-stopped

  search:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.3.1
    environment:
      cluster.name: fusionauth
      bootstrap.memory_lock: "true"
      ES_JAVA_OPTS: "${ES_JAVA_OPTS}"
    ports:
    - 9200:9200
    - 9300:9300
    networks:
      - search
    restart: unless-stopped
    ulimits:
      memlock:
        soft: -1
        hard: -1

  fusionauth:
    image: fusionauth/fusionauth-app:latest
    depends_on:
      - db
      - search
    environment:
      DATABASE_URL: jdbc:postgresql://db:5432/fusionauth
      DATABASE_ROOT_USER: ${POSTGRES_USER}
      DATABASE_ROOT_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_USER: ${DATABASE_USER}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      FUSIONAUTH_MEMORY: ${FUSIONAUTH_MEMORY}
      FUSIONAUTH_SEARCH_SERVERS: http://search:9200
      FUSIONAUTH_URL: http://fusionauth:9010
      FUSIONAUTH_KICKSTART: /usr/local/fusionauth/kickstart.json
    networks:
     - db
     - fusionauth
     - search
    restart: unless-stopped
    ports:
      - 9010:9011
    volumes:
      - ./kickstart.json:/usr/local/fusionauth/kickstart.json

networks:
  db:
    driver: bridge
  fusionauth:
    driver: bridge
  search:
    driver: bridge

Then, to guarantee that fusionauth and its dependencies are ready before running proceeding by waiting on a JSON response from fusionauth:9011/api/status:

$ docker-compose run --rm startup_services

You may specify multiple endpoints to wait for JSON response from by seperating them with spaces in the command directive:

  startup_services:
    image: fusionauth/wait-for-json
    depends_on:
      - fusionauth
    networks:
      - fusionauth
    command: fusionauth:9011/api/foo fusionauth:9011/api/bar fusionauth:9011/api/baz
  start_dependencies:
    image: fusionauth/wait-for-json
    environment:
      - SLEEP_LENGTH: 1
      - TIMEOUT_LENGTH: 60
      - JSON_TYPE: array

By default, there will be a 2 second sleep time between each check. You can modify this by setting the SLEEP_LENGTH environment variable:

  start_dependencies:
    image: fusionauth/wait-for-json
    environment:
      - SLEEP_LENGTH: 0.5

By default, there will be a 300 seconds timeout before cancelling the wait_for. You can modify this by setting the TIMEOUT_LENGTH environment variable:

  start_dependencies:
    image: fusionauth/wait-for-json
    environment:
      - SLEEP_LENGTH: 1
      - TIMEOUT_LENGTH: 60

By default, we will wait for a JSON object to be returned from the specified endpoints. You can modify this by setting the JSON_TYPE environment variable to one of null, boolean, number, string, array or object:

  start_dependencies:
    image: fusionauth/wait-for-json
    environment:
      - SLEEP_LENGTH: 1
      - TIMEOUT_LENGTH: 60
      - JSON_TYPE: array

About

Docker container that blocks until given endpoints return a JSON response

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 84.5%
  • Dockerfile 15.5%