-
-
Notifications
You must be signed in to change notification settings - Fork 129
Development with docker compose
If you don’t want to install node and/or the other tools needed for working on graphile-build, you can use docker-compose to easily set up a development environment
- Install Docker & docker-compose
- Create dir named db.
- In db dir create file named Dockerfile:
FROM postgres:13-alpine AS builder
RUN apk add --no-cache --virtual .build-deps gcc git make musl-dev pkgconf clang clang-dev llvm vim
RUN git clone https://github.com/eulerto/wal2json.git
WORKDIR wal2json
RUN USE_PGXS=1 make && make install
FROM postgres:13-alpine
COPY --from=builder /wal2json/wal2json.so /usr/local/lib/postgresql/
- In main directory put those two files at the repository root:
# docker-compose.yml
version: "3"
services:
js: &js
build: .
volumes:
- .:/gb:rw
working_dir: /gb
depends_on:
- db
environment:
TEST_DATABASE_URL: postgres://gb@db:5432/gb
TEST_PG_URL: postgres://gb@db:5432/postgraphile_test
LDS_TEST_DATABASE_URL: postgres://gb@db:5432/lds_test
yarn:
<<: *js
entrypoint: ["yarn"]
lerna:
<<: *js
entrypoint: ["node_modules/.bin/lerna"]
npm:
<<: *js
entrypoint: ["npm"]
bash:
<<: *js
entrypoint: ["bash"]
db:
build: ./db
command: postgres -c wal_level=logical -c max_wal_senders=10 -c max_replication_slots=10
ports:
- 5432:5432
environment:
POSTGRES_USER: gb
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_PASSWORD: ""
# Dockerfile
FROM node:10
RUN apt-get update && apt-get install -y postgresql-client
To simplify the command I recommend adding this alias:
# ~/.bash_aliases
alias run="docker-compose run --rm"
When in the graphile-repository, you have access to all command defined in defined in docker-compose.yml
like this:
docker-compose build
docker-compose run --rm yarn
docker-compose run --rm lerna bootstrap
docker-compose run --rm npm run watch
Watch will keep monitoring and compiling the babel files. Then to run the tests in another terminal:
All commands will be executed from the repository root regardless on the folder you’re in in the repository, if you want to change directory you can enter the container environment by running run bash
and you then can change directory and run commands as you would without docker.
docker-compose run --rm lerna run test
docker-compose automatically configure and start a postgres server for you to run the tests.
To stop and remove any image and container created with docker-compose, just run docker-compose down