← Back
docker gist graphql hasura

Hasura for development

Hasura is an instant graphQL backend over a postgres database.

Setup hasura for development with docker compose:

version: "3.6"
services:
postgres:
image: postgres:12
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: secret

auth:
build:
context: ./authentication
command: yarn start
depends_on:
- postgres
ports:
- "3030:3030"
environment:
DATABASE_URL: postgres://postgres:secret@postgres:5432/postgres
PORT: 3030
volumes:
- ./authentication:/app
- ./authentication/package.json:/app/package.json
- ./authentication/yarn.lock:/app/yarn.lock

graphql-engine:
image: hasura/graphql-engine:v1.1.1
ports:
- "8080:8080"
depends_on:
- postgres
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:secret@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # we are using migrations
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: anonymous
HASURA_GRAPHQL_JWT_SECRET: '{"type": "RS512", "key": "-----BEGIN CERTIFICATE-----\..."}'
## uncomment next line to set an admin secret
HASURA_GRAPHQL_ADMIN_SECRET: secret
volumes:
db_data:

(*) postgres 12 requires a password

Local authentication #

Is taken from this repo:

With this Dockerfile:

FROM mhart/alpine-node:11.1.0

RUN mkdir /app

WORKDIR /app

RUN apk upgrade --update-cache --available && apk add openssl && apk add --no-cache bash git && rm -rf /var/cache/apk/*

ENV PATH /app/node_modules/.bin:$PATH

COPY . /app

RUN yarn install

CMD ["yarn", "start"]

And this setup:

yarn install
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout > public.pem

# Print the key in an escaped format, to include in ENV variables:
# HASURA_GRAPHQL_JWT_SECRET={"type": "RS256", "key": "-----BEGIN PUBLIC...." }
awk -v ORS='\\n' '1' public.pem

yarn knex migrate:latest

The scripts #

  "scripts": {
"docker:start": "docker-compose up -d",
"docker:pgadmin": "docker-compose up -d pgadmin",
"docker:stop": "docker-compose down",
"docker:purge": "docker-compose down --volumes",
"client": "yarn client:start",
"client:start": "cd client && yarn start",
"hasura": "yarn run hasura:start",
"hasura:start": "HASURA_GRAPHQL_ADMIN_SECRET=secret hasura console"
},

Sources #

🖖