fredrikhgrelland / docker-hive

Apache License 2.0
2 stars 3 forks source link

Add prestart tasks waiting for dependent services. #7

Closed fredrikhgrelland closed 4 years ago

fredrikhgrelland commented 4 years ago

closes https://github.com/fredrikhgrelland/data-mesh/issues/33

This PR adds two consul-checks as prestart tasks. It utilize the consul docker image ( but it really could be any image containing jq ). and it works as follows:

task "waitfor-hive-metastore" {
      lifecycle {
        hook = "prestart"
      }
      driver = "docker"
      resources {
        memory = 32  #reduced memory footprint
      }

      template { 
        destination = "tmp/service.json"
        # Render a template containing information on service as a json file
        data = <<EOH
          {{- service "hive-metastore" | toJSON -}}
        EOH
      }
      config {
        image = "consul:latest"  #Consul image contains jq.
        entrypoint = ["/bin/sh"] # Run a shell
        volumes = ["tmp/service.json:/local/service.json" ] #Mount the templated file into the container
        # run jq on file created by the template stanza
        # -e exits 0 if filter succedes. In this case "all service status is passing"
        args = ["-c", "jq </local/service.json -e '.[].Status|select(. == \"passing\")'"]
      }
zhenik commented 4 years ago

Ref: https://github.com/fredrikhgrelland/data-mesh/issues/33