Dockerize postgraphile

This commit is contained in:
Taka Goto 2019-01-31 21:27:23 -06:00 committed by Edvard
parent e6e66d58dd
commit 85cec480dc
7 changed files with 71 additions and 28 deletions

View File

@ -7,10 +7,7 @@ S
By default, vDB is configured towards the Kovan deploy. The configuration values can be overridden using environment variables, using the same hierarchical naming pattern but in CAPS and using underscores. For example, the contract address for the `Pit` can be set with the variable `CONTRACT_ADDRESS_PIT="0x123..."`. By default, vDB is configured towards the Kovan deploy. The configuration values can be overridden using environment variables, using the same hierarchical naming pattern but in CAPS and using underscores. For example, the contract address for the `Pit` can be set with the variable `CONTRACT_ADDRESS_PIT="0x123..."`.
## To use the container: ## To use the container:
1. Setup a postgres database with owner `vulcanize` 1. Setup a postgres database with superuser `vulcanize`
* `vulcanize` does not _have_ to be owner, but otherwise permissions for
connection, tables, and sequences need to be added for the `public` and
`maker` schemas manually when the migrations have been run.
2. Set the env variables `DATABASE_NAME`, `DATABASE_HOSTNAME`, 2. Set the env variables `DATABASE_NAME`, `DATABASE_HOSTNAME`,
`DATABASE_PORT`, `DATABASE_USER` & `DATABASE_PASSWORD` `DATABASE_PORT`, `DATABASE_USER` & `DATABASE_PASSWORD`
3. Run the DB migrations: 3. Run the DB migrations:
@ -26,7 +23,9 @@ e`
* `rc-service continuousLogSync start` * `rc-service continuousLogSync start`
### Automated ### Automated
The steps above have been rolled into a script: `/app/startup_script.sh`, which just assumes the DB env variables have been set, and defaults the rest to Kovan according to `environments/staging.toml`. The steps above have been rolled into a script: `/app/startup_script.sh`, which just assumes the DB env variables have been set, and defaults the rest to Kovan according to `environments/staging.toml`. This can be called with something like:
`docker run -d -e DATABASE_NAME=vulcanize_pubic -e DATABASE_HOSTNAME=localhost -e DATABASE_PORT=5432 -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize ./startup_script.sh`
### Logging ### Logging
When running, vDB services log to `/vulcanizedb.log`. When running, vDB services log to `/vulcanizedb.log`.

View File

@ -0,0 +1,7 @@
package-lock.json
yarn.lock
node_modules
Dockerfile
README.md
spec
.dockerignore

9
postgraphile/Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM mhart/alpine-node:10
RUN apk --update --no-cache add make g++ python findutils postgresql-dev
WORKDIR /app
COPY . /app
run yarn install
RUN ["./node_modules/typescript/bin/tsc"]
EXPOSE 3000
CMD ["node", "/app/build/dist/src/index.js"]

View File

@ -2,6 +2,18 @@
This application utilizes Postgraphile to expose GraphQL endpoints for exposure of the varied data that VulcanizeDB tracks. This application utilizes Postgraphile to expose GraphQL endpoints for exposure of the varied data that VulcanizeDB tracks.
## Docker use
_Note: currently this image is ~500MB large (unpacked)_
Build the docker image in this directory. Start the `GraphiQL` frontend by:
* Setting the env variables for the database connection: `DATABASE_HOST`,
`DATABASE_NAME`, `DATABASE_USER`, `DATABASE_PASSWORD` (and optionally
`DATABASE_PORT` if running on non-standard port).
* The specified user needs to be `superuser` on the vulcanizeDB database
* Run the container (ex. `docker run -e DATABASE_HOST=localhost -e DATABASE_NAME=vulcanize_public -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize -d postgraphile:latest`)
* GraphiQL is available at `:3000/graphiql`
## Building ## Building
*This application assumes the use of the [Yarn package manager](https://yarnpkg.com/en/). The use of npm may produce unexpected results.* *This application assumes the use of the [Yarn package manager](https://yarnpkg.com/en/). The use of npm may produce unexpected results.*

View File

@ -22,22 +22,22 @@
"homepage": "https://github.com/vulcanize/vulcanizedb", "homepage": "https://github.com/vulcanize/vulcanizedb",
"dependencies": { "dependencies": {
"express-session": "1.15.6", "express-session": "1.15.6",
"graphql-subscriptions": "0.5.8",
"lodash": "4.17.10", "lodash": "4.17.10",
"passport": "0.4.0", "passport": "0.4.0",
"pg": "6.4.2",
"pg-native": "3.0.0", "pg-native": "3.0.0",
"postgraphile": "4.0.0-rc.4", "postgraphile": "4.0.0-rc.4",
"graphql-subscriptions": "0.5.8",
"subscriptions-transport-ws": "0.9.14", "subscriptions-transport-ws": "0.9.14",
"toml": "2.3.3", "toml": "2.3.3"
"pg": "6.4.2"
}, },
"devDependencies": { "devDependencies": {
"@types/graphql": "^0.13.4",
"@types/express": "4.16.0", "@types/express": "4.16.0",
"@types/express-session": "1.15.10", "@types/express-session": "1.15.10",
"@types/graphql": "^0.13.4",
"@types/jasmine": "2.8.8", "@types/jasmine": "2.8.8",
"@types/lodash": "4.14.116", "@types/lodash": "4.14.116",
"@types/node": "10.9.3", "@types/node": "^10.12.21",
"@types/passport": "0.4.6", "@types/passport": "0.4.6",
"awesome-typescript-loader": "5.2.0", "awesome-typescript-loader": "5.2.0",
"jasmine": "3.2.0", "jasmine": "3.2.0",

View File

@ -6,34 +6,49 @@ export const MISSING_PATH_MESSAGE = `No path to config toml file provided, `
+ `please check the value of ${CONFIG_PATH_KEY} in your environment`; + `please check the value of ${CONFIG_PATH_KEY} in your environment`;
export const MISSING_HOST_MESSAGE = 'No database host provided in config toml'; export const MISSING_HOST_MESSAGE = 'No database host provided in config toml';
export const MISSING_DATABASE_MESSAGE = 'No database name provided in config ' export const MISSING_USER_MESSAGE = 'No database user & password provided in config toml';
+ 'toml'; export const MISSING_DATABASE_MESSAGE = 'No database name provided in config toml';
export function parseConfig( export function parseConfig(
readCallback: ReadFileSyncCallback, readCallback: ReadFileSyncCallback,
tomlParseCallback: TomlParseCallback, tomlParseCallback: TomlParseCallback,
configPath?: string configPath?: string
): DatabaseConfig { ): DatabaseConfig {
if (!configPath || configPath.length < 1) { let host = '';
throw new Error(MISSING_PATH_MESSAGE); let port = '';
} let database = '';
let user = '';
let password = '';
if (configPath) {
const tomlContents = readCallback(`${configPath}`).toString(); const tomlContents = readCallback(`${configPath}`).toString();
const parsedToml = tomlParseCallback(tomlContents); const parsedToml = tomlParseCallback(tomlContents);
const host = parsedToml['database']['hostname']; host = parsedToml['database']['hostname'];
const port = parsedToml['database']['port']; port = parsedToml['database']['port'];
const database = parsedToml['database']['name']; database = parsedToml['database']['name'];
const user = parsedToml['database']['user'] || ''; user = parsedToml['database']['user'];
const password = parsedToml['database']['password'] || ''; password = parsedToml['database']['password'];
}
if (!host || host.length < 1) { // Overwrite config values with env. vars if such are set
host = process.env.DATABASE_HOST || host;
port = process.env.DATABASE_PORT || port;
database = process.env.DATABASE_NAME || database;
user = process.env.DATABASE_USER || user;
password = process.env.DATABASE_PASSWORD || password;
if (!host) {
throw new Error(MISSING_HOST_MESSAGE); throw new Error(MISSING_HOST_MESSAGE);
} }
if (!database || database.length < 1) { if (!database) {
throw new Error(MISSING_DATABASE_MESSAGE); throw new Error(MISSING_DATABASE_MESSAGE);
} }
if (!user || !password) {
throw new Error(MISSING_USER_MESSAGE);
}
return { host: `postgres://${user}:${password}@${host}:${port}`, database }; return { host: `postgres://${user}:${password}@${host}:${port}`, database };
} }

View File

@ -108,9 +108,10 @@
version "10.9.4" version "10.9.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897"
"@types/node@10.9.3": "@types/node@^10.12.21":
version "10.9.3" version "10.12.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.3.tgz#85f288502503ade0b3bfc049fe1777b05d0327d5" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.21.tgz#7e8a0c34cf29f4e17a36e9bd0ea72d45ba03908e"
integrity sha512-CBgLNk4o3XMnqMc0rhb6lc77IwShMEglz05deDcn2lQxyXEZivfwgYJu7SMha9V5XcrP6qZuevTHV/QrN2vjKQ==
"@types/passport@0.4.6": "@types/passport@0.4.6":
version "0.4.6" version "0.4.6"