Created
August 31, 2019 00:03
-
-
Save anaisbetts/2244d6517dc2cc09b4470e6f68c2bec1 to your computer and use it in GitHub Desktop.
Create a PostgreSQL + Hasura database in Docker with Pulumi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from '@pulumi/pulumi'; | |
import * as docker from '@pulumi/docker'; | |
import * as pg from '@pulumi/postgresql'; | |
const cfg = new pulumi.Config(); | |
const network = new docker.Network('net'); | |
const pgImg = new docker.RemoteImage('postgresql-image', { | |
name: 'postgres:11', | |
keepLocally: true | |
}); | |
const pgVol = new docker.Volume('pgdata'); | |
export const pgContainer = new docker.Container('postgres', { | |
image: pgImg.name, | |
networksAdvanced: [{ name: network.name }], | |
restart: 'on-failure', | |
volumes: [{ volumeName: pgVol.name, containerPath: '/var/lib/postgresql/data' }], | |
envs: [ | |
`POSTGRES_USER=${cfg.require('pguser')}`, | |
cfg.requireSecret('pgpass').apply(p => `POSTGRES_PASSWORD=${p}`), | |
], | |
ports: [{ internal: 5432, external: 5432 }] | |
}); | |
const pgProvider = new pg.Provider('pg', { | |
host: pgContainer.ipAddress, | |
username: cfg.require('pguser'), | |
password: cfg.requireSecret('pgpass'), | |
sslmode: 'disable' | |
}); | |
const db = new pg.Database('MyCoolDatabase', {}, { provider: pgProvider }); | |
const hasuraImage = new docker.RemoteImage('hasura-image', { | |
name: 'hasura/graphql-engine:v1.0.0-beta.6', | |
keepLocally: true | |
}); | |
export const hasuraContainer = new docker.Container('hasura', { | |
image: hasuraImage.name, | |
networksAdvanced: [{ name: network.name }], | |
restart: 'on-failure', | |
envs: [ | |
cfg.requireSecret('pgpass').apply(p => { | |
const u = cfg.require('pguser'); | |
return pgContainer.name.apply(hn => | |
`HASURA_GRAPHQL_DATABASE_URL=postgres://${u}:${p}@${hn}:5432/MyCoolDatabase`); | |
}), | |
cfg.requireSecret('pgpass').apply(p => | |
`HASURA_GRAPHQL_ADMIN_SECRET=${p}`), | |
`HASURA_GRAPHQL_JWT_SECRET={'type':'RS512', 'jwk_url': 'https://www.googleapis.com/service_accounts/v1/jwk/[email protected]'}`, | |
`HASURA_GRAPHQL_UNAUTHORIZED_ROLE=anonymous` | |
], | |
ports: [{ internal: 8080, external: 8080 }] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PGPASSWORD=`pulumi config get pgpass` exec pgcli -u `pulumi config get pguser` -h localhost -w $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment