Service dependent on other services - wercker ci

130 Views Asked by At

I'm using wercker to automate test and deploy of an API client by running the API server as a private service alongside redis and postgres services (all application level) for integration testing of the client. This setup theoretically allows my client to interact with the api server and for both the client and server to be able to use the same postgres and redis services.

My private service is dependent on the database services and therefore needs the host and port of those services (exposed environment variables) injected as environment variables into its container at start up. However, I've been unable to access these exposed connection variables from within the same service block that they're declared.

I've posted a section of my wercker.yml below:

 - id: postgres
   env:
       POSTGRES_PASSWORD: $POSTGRES_PASSWORD
       POSTGRES_USER: $POSTGRES_USER
       POSTGRES_DB: $POSTGRES_DB

 - redis

 # - spotify/cassandra

 - name: realtime
   id: quay.io/ndustrialio/realtime-api-service
   username: $QUAY_USERNAME
   password: $QUAY_PASSWORD
   tag: latest
   registry: https://quay.io
   env:
       CLIENT_ID: $CLIENT_ID
       CLIENT_SECRET: $CLIENT_SECRET
       POSTGRES_USER: $POSTGRES_USER
       POSTGRES_PASSWORD: $POSTGRES_PASSWORD
       POSTGRES_DB: $POSTGRES_DB
       POSTGRES_HOST: $POSTGRES_PORT_5432_TCP_ADDR
       NODE_ENV: wercker_test
       REDIS_HOST: $REDIS_PORT_6379_TCP_ADDR
       REDIS_PORT: 6379
       REDIS_DB: 0
       CASSANDRA_HOSTS: cassandra

The environment variables $REDIS_PORT_6379_TCP_ADDR and $POSTGRES_PORT_5432_TCP_ADDR are empty in the realtime service container. How can I access these variables in my realtime service?

1

There are 1 best solutions below

0
On

The solution is to rely on the Service Container Networking

The IP of your postgres service has the hostname derived from its id so you just need to replace POSTGRES_HOST: $POSTGRES_PORT_5432_TCP_ADDR by POSTGRES_HOST: postgres