From 5433641234abf02dabfbb330a8dae615633481bc Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 20 Jun 2019 12:57:36 +0200 Subject: [PATCH] set up simpler dockerized dev env for node apps --- .circleci/config.yml | 3 ++ .npmrc | 1 + Makefile | 25 +++++++++++++ README.md | 18 ++++++++- docker-compose.yml | 88 +++++++++++++++++++++++++++----------------- 5 files changed, 99 insertions(+), 36 deletions(-) create mode 100644 .npmrc create mode 100644 Makefile diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d162e9..662eed3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,8 @@ jobs: kms: docker: - image: circleci/golang:1.12 + environment: + - PORT=8081 working_directory: ~/offen/kms steps: - checkout: @@ -29,6 +31,7 @@ jobs: - image: circleci/golang:1.12 environment: - POSTGRES_CONNECTION_STRING=postgres://circle:test@localhost:5432/circle_test?sslmode=disable + - PORT=8080 - image: circleci/postgres:11.2-alpine environment: - POSTGRES_USER=circle diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6d92848 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +help: + @echo " setup" + @echo " Build the containers and install dependencies." + @echo " bootstrap" + @echo " Create a KMS key and initialize the database." + @echo " IMPORTANT: this wipes any existing data in your local database." + @echo " build" + @echo " Build all applications." + +setup: + @docker-compose build + @docker-compose run script npm install + @docker-compose run vault npm install + @docker-compose run auditorium npm install + @docker-compose run server go mod download + @docker-compose run kms go mod download + @echo "Successfully built containers and installed dependencies." + @echo "If this is your initial setup, you can run 'make bootstrap' next" + @echo "to create the needed local keys and seed the database." + +bootstrap: + @docker-compose run kms make bootstrap + @docker-compose run server make bootstrap + +.PHONY: setup bootstrap diff --git a/README.md b/README.md index 2683180..6f6928f 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,27 @@ Project planning and issue tracking is done using [Pivotal Tracker](https://www. ### Developing the application -You can test setup by starting the application: +The development setup requires `docker` and `docker-compose` to be installed. +After cloning the repository, you can build the containers and install dependencies using: + +```sh +$ make setup ``` + +Next, create a local encryption key for the `kms` service and seed the database for the `server` application: + +```sh +$ make bootstrap +``` + +You can test your setup by starting the application: + +```sh $ docker-compose up ``` -Now you should be able to access seeing a successful response. +which should enable you to access seeing a successful response. ### License diff --git a/docker-compose.yml b/docker-compose.yml index e5df372..0ffdd3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,47 +1,54 @@ version: '3' services: - kms: - image: golang:1.12 - working_dir: /code/kms - volumes: - - .:/code - - $GOPATH/pkg/mod:/go/pkg/mod - environment: - - GOPATH=/go - - KEY_FILE=key.txt - ports: - - 8081:8081 - command: go run cmd/kms/main.go -port 8081 -origin http://localhost:9977 - - server: - image: golang:1.12 - working_dir: /code/server - volumes: - - .:/code - - $GOPATH/pkg/mod:/go/pkg/mod - environment: - - GOPATH=/go - - POSTGRES_CONNECTION_STRING=postgres://postgres:develop@database:5432/postgres?sslmode=disable - - KMS_ENCRYPTION_ENDPOINT=http://kms:8081/encrypt - ports: - - 8080:8080 - command: go run cmd/server/main.go -origin http://localhost:9977 -conn postgres://postgres:develop@database:5432/postgres?sslmode=disable -level debug - links: - - database - depends_on: - - kms - database: image: postgres:11.2 environment: - POSTGRES_PASSWORD=develop + kms: + build: + context: '.' + dockerfile: Dockerfile.golang + working_dir: /offen/kms + volumes: + - .:/offen + - kmsdeps:/go/pkg/mod + environment: + - KEY_FILE=key.txt + - PORT=8081 + ports: + - 8081:8081 + command: refresh run + + server: + build: + context: '.' + dockerfile: Dockerfile.golang + working_dir: /offen/server + volumes: + - .:/offen + - serverdeps:/go/pkg/mod + environment: + - POSTGRES_CONNECTION_STRING=postgres://postgres:develop@database:5432/postgres?sslmode=disable + - KMS_ENCRYPTION_ENDPOINT=http://kms:8081/encrypt + - PORT=8080 + ports: + - 8080:8080 + command: refresh run + links: + - database + depends_on: + - kms + vault: - image: timbru31/node-chrome:slim + build: + context: '.' + dockerfile: Dockerfile.node working_dir: /offen/vault volumes: - .:/offen + - vaultdeps:/offen/vault/node_modules command: npm start -- --port 9977 ports: - 9977:9977 @@ -51,10 +58,13 @@ services: - AUDITORIUM_HOST=http://localhost:9955 script: - image: timbru31/node-chrome:slim + build: + context: '.' + dockerfile: Dockerfile.node working_dir: /offen/script volumes: - .:/offen + - scriptdeps:/offen/script/node_modules command: npm start -- --port 9966 ports: - 9966:9966 @@ -62,12 +72,22 @@ services: - VAULT_HOST=http://localhost:9977 auditorium: - image: timbru31/node-chrome:slim + build: + context: '.' + dockerfile: Dockerfile.node working_dir: /offen/auditorium volumes: - .:/offen + - auditoriumdeps_2:/offen/auditorium/node_modules command: npm start -- --port 9955 ports: - 9955:9955 environment: - VAULT_HOST=http://localhost:9977 + +volumes: + kmsdeps: + serverdeps: + scriptdeps: + auditoriumdeps_2: + vaultdeps: