Skip to content

Instantly share code, notes, and snippets.

@plmercereau
Last active August 2, 2020 18:55
Show Gist options
  • Save plmercereau/b8503c869ffa2b5d4e42dc9137b56ae1 to your computer and use it in GitHub Desktop.
Save plmercereau/b8503c869ffa2b5d4e42dc9137b56ae1 to your computer and use it in GitHub Desktop.
version: '3.1'
services:
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
postgres:
image: mdillon/postgis:11-alpine
restart: always
volumes:
- db_data:/var/lib/postgresql/data
authentication:
image: platyplus/authentication
restart: always
labels:
- "traefik.frontend.rule=Host:auth.${DOMAIN}"
- "traefik.port=8080"
depends_on:
- "postgres"
environment:
NODE_ENV: production
DATABASE_URL: postgres://postgres:@postgres:5432/postgres
AUTH_PRIVATE_KEY: "${PRIVATE_KEY}"
AUTH_PUBLIC_KEY: "${PUBLIC_KEY}"
graphql-engine:
image: hasura/graphql-engine:v1.0.0-alpha37
labels:
- "traefik.frontend.rule=Host:graphql.${DOMAIN}"
- "traefik.port=8080"
depends_on:
- "postgres"
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "${HASURA_ENABLE_CONSOLE}"
HASURA_GRAPHQL_JWT_SECRET: '{"type":"RS256", "key":"${PUBLIC_KEY}"}'
HASURA_GRAPHQL_ACCESS_KEY: "${HASURA_ACCESS_KEY}"
volumes:
db_data:
@plmercereau
Copy link
Author

note: the authentication service is available in this repo

@plmercereau
Copy link
Author

Environment variables:

DOMAIN=localhost
PRIVATE_KEY=<RSA private PEM key escaped with \n>
PUBLIC_KEY=<RSA public PEM key escaped with \n>
HASURA_ACCESS_KEY=<Your Hasura secret key>
HASURA_ENABLE_CONSOLE=<true/false>

@celvin
Copy link

celvin commented Mar 7, 2019

When I add values to the .env file, for:
HASURA_GRAPHQL_JWT_SECRET: '{"type":"RS256", "key":"${PUBLIC_KEY}"}'

I am getting the error:
graphql-engine_1 | Fatal Error: JWT conf: Error in $: Failed reading: satisfy

@plmercereau
Copy link
Author

When I add values to the .env file, for:
HASURA_GRAPHQL_JWT_SECRET: '{"type":"RS256", "key":"${PUBLIC_KEY}"}'

I am getting the error:
graphql-engine_1 | Fatal Error: JWT conf: Error in $: Failed reading: satisfy

Hello @celvin,
Sorry I only see your message now. I haven't tested this compose file with environment variables defined in a .env file.
However it seems this error is a json parsing error, so my guess is that the PUBLIC_KEY variable is not available in the graphql-engine container.
According to the docker documentation:

Environment variables defined in the .env file are not automatically visible inside containers. To set container-applicable environment variables, follow the guidelines in the topic Environment variables in Compose, which describes how to pass shell environment variables through to containers, define environment variables in Compose files, and more.

So maybe you need to specify a env_file option in the compose file?

@celvin
Copy link

celvin commented May 17, 2019 via email

@plmercereau
Copy link
Author

plmercereau commented May 17, 2019

I think Hasura requires to escape the end of lines in the key variables with "\n" instead. I am not sure this is the issue but I would give it a try. I explain it in this repo. What I did to format the key in the right format:

awk -v ORS='\\n' '1' public_key.pem

@celvin
Copy link

celvin commented May 17, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment