Skip to content

Instantly share code, notes, and snippets.

@michael-k
Forked from mixja/Dockerfile
Created March 7, 2017 18:22
Show Gist options
  • Save michael-k/00b36c564a40119e55a9742e423e17aa to your computer and use it in GitHub Desktop.
Save michael-k/00b36c564a40119e55a9742e423e17aa to your computer and use it in GitHub Desktop.

Revisions

  1. @mixja mixja revised this gist Nov 30, 2016. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,10 @@
    # Service health functions
    # Syntax: $(call check_service_health,<docker-compose-environment>,<service-name>)
    get_container_id = $$(docker-compose $(1) ps -q $(2))
    get_container_state = $$(echo $(call get_container_id,$(1),$(2)) | xargs -I ID docker inspect -f '{{ $(3) }}' ID)
    get_service_health = $$(echo $(call get_container_state,$(1),$(2),.State.Health.Status))
    get_service_running = $$(echo $(call get_container_state,$(1),$(2),.State.Running))
    get_container_state = $$(echo $(call get_container_id,$(1),$(2)) | xargs -I ID docker inspect -f '$(3)' ID)
    get_service_health = $$(echo $(call get_container_state,$(1),$(2),{{if .State.Running}}{{ .State.Health.Status }}{{end}}))
    check_service_health = { \
    until [[ $(call get_service_health,$(1),$(2)) != starting ]] \
    || ($(call get_service_running,$(1),$(2)) = false) ]]; \
    until [[ $(call get_service_health,$(1),$(2)) != starting ]]; \
    do sleep 1; \
    done; \
    if [[ $(call get_service_health,$(1),$(2)) != healthy ]]; \
  2. @mixja mixja revised this gist Nov 29, 2016. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    # Service health functions
    # Syntax: $(call check_service_health,<docker-compose-environment>,<service-name>)
    get_container_id = $$(docker-compose $(1) ps -q $(2))
    get_service_health = $$(echo $(call get_container_id,$(1),$(2)) | xargs -I ID docker inspect -f '{{ .State.Health.Status }}' ID)
    get_container_state = $$(echo $(call get_container_id,$(1),$(2)) | xargs -I ID docker inspect -f '{{ $(3) }}' ID)
    get_service_health = $$(echo $(call get_container_state,$(1),$(2),.State.Health.Status))
    get_service_running = $$(echo $(call get_container_state,$(1),$(2),.State.Running))
    check_service_health = { \
    until [[ $(call get_service_health,$(1),$(2)) != starting ]]; \
    until [[ $(call get_service_health,$(1),$(2)) != starting ]] \
    || ($(call get_service_running,$(1),$(2)) = false) ]]; \
    do sleep 1; \
    done; \
    if [[ $(call get_service_health,$(1),$(2)) != healthy ]]; \
  3. @mixja mixja revised this gist Nov 25, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,10 @@ check_service_health = { \
    # $(RELEASE_ARGS) represents the '-p <project> -f <docker-compose-file>' portion of docker-compose command
    release:
    # Start mysql container
    @ docker-compose up $(RELEASE_ARGS) mysql -d
    @ docker-compose $(RELEASE_ARGS) up -d mysql
    # This will wait until mysql container health changes from starting to healthy or unhealthy
    @ $(call check_service_health,$(RELEASE_ARGS),mysql)
    # Start nginx container
    @ docker-compose up $(RELEASE_ARGS) nginx -d
    @ docker-compose $(RELEASE_ARGS) up -d nginx
    # This will wait until nginx container health changes from starting to healthy or unhealthy
    @ $(call check_service_health,$(RELEASE_ARGS),nginx)
  4. @mixja mixja revised this gist Nov 25, 2016. 2 changed files with 9 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions Dockerfile.mysql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    FROM mysql:5.7
    HEALTHCHECK --interval=3s --retries=20 CMD mysqlshow -u ${MYSQL_USER} -p${MYSQL_PASSWORD}
    8 changes: 7 additions & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -13,5 +13,11 @@ check_service_health = { \

    # $(RELEASE_ARGS) represents the '-p <project> -f <docker-compose-file>' portion of docker-compose command
    release:
    # This will wait until container health changes from starting to healthy or unhealthy
    # Start mysql container
    @ docker-compose up $(RELEASE_ARGS) mysql -d
    # This will wait until mysql container health changes from starting to healthy or unhealthy
    @ $(call check_service_health,$(RELEASE_ARGS),mysql)
    # Start nginx container
    @ docker-compose up $(RELEASE_ARGS) nginx -d
    # This will wait until nginx container health changes from starting to healthy or unhealthy
    @ $(call check_service_health,$(RELEASE_ARGS),nginx)
  5. @mixja mixja revised this gist Nov 21, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    FROM nginx
    HEALTHCHECK --interval=3s --retries=20 CMD curl -fs http://localhost:${HTTP_PORT:-8000}
  6. @mixja mixja created this gist Nov 21, 2016.
    17 changes: 17 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # Service health functions
    # Syntax: $(call check_service_health,<docker-compose-environment>,<service-name>)
    get_container_id = $$(docker-compose $(1) ps -q $(2))
    get_service_health = $$(echo $(call get_container_id,$(1),$(2)) | xargs -I ID docker inspect -f '{{ .State.Health.Status }}' ID)
    check_service_health = { \
    until [[ $(call get_service_health,$(1),$(2)) != starting ]]; \
    do sleep 1; \
    done; \
    if [[ $(call get_service_health,$(1),$(2)) != healthy ]]; \
    then echo $(2) failed health check; exit 1; \
    fi; \
    }

    # $(RELEASE_ARGS) represents the '-p <project> -f <docker-compose-file>' portion of docker-compose command
    release:
    # This will wait until container health changes from starting to healthy or unhealthy
    @ $(call check_service_health,$(RELEASE_ARGS),nginx)