From 8b580b787fd31c8d293f8dcdf500968127ffeed4 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 12 Apr 2019 09:04:31 +0200 Subject: [PATCH 1/4] add initial postgres database connector --- .circleci/config.yml | 6 ++++++ docker-compose.yml | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8edaa05..8ccaaa1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,12 @@ jobs: server: docker: - image: circleci/golang:1.12 + environment: + - POSTGRES_CONNECTION_STRING=postgres://circle:test@localhost:5432/circle_test?sslmode=disable + - image: circleci/postgres:11.2-alpine + environment: + - POSTGRES_USER=circle + - POSTGRES_PASSWORD=test working_directory: ~/offen/server steps: - checkout: diff --git a/docker-compose.yml b/docker-compose.yml index 04c45f3..d171cf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,14 @@ server: - $GOPATH/pkg/mod:/go/pkg/mod environment: - GOPATH=/go + - POSTGRES_CONNECTION_STRING=postgres://postgres:develop@database:5432/postgres?sslmode=disable ports: - 8080:8080 command: go run cmd/server/main.go + links: + - database + +database: + image: postgres:11.2 + environment: + - POSTGRES_PASSWORD=develop From 01589e3055075f4ae8c6c77a2561f76846b7bd59 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 19 Apr 2019 18:37:19 +0200 Subject: [PATCH 2/4] clean up responsibilities in query methods, make sql backend configurable --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d171cf4..44013ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,9 @@ server: - $GOPATH/pkg/mod:/go/pkg/mod environment: - GOPATH=/go - - POSTGRES_CONNECTION_STRING=postgres://postgres:develop@database:5432/postgres?sslmode=disable ports: - 8080:8080 - command: go run cmd/server/main.go + command: go run cmd/server/main.go -conn postgres://postgres:develop@database:5432/postgres?sslmode=disable links: - database From 65323a1597095196a7316ee101503832bc8a4fe3 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 19 Apr 2019 18:56:24 +0200 Subject: [PATCH 3/4] clean up router package --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 1e495bc..1d1ebc8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,30 @@ Development of __offen__ has just started, so instructions are rare and things w Guidelines for running and developing the Software will be added when it makes sense to do so. Feel free to open an issue if you have a question. +### Developing the application + +#### `server` + +To work on the `server` you will need to install `docker-compose` and Go 1.12+. + +First, bootstrap the dockerized Postgres database used for development: + +``` +docker-compose run server go run cmd/bootstrap/main.go +``` + +Run the server: + +``` +docker-compose up +``` + +Run the tests: + +``` +docker-compose run server make +``` + ### License MIT © [Frederik Ring](https://www.frederikring.com), [Hendrik Niefeld](http://niefeld.com/) From 48b91e13d245759194f8f7a8c970830d36f7341f Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 19 Apr 2019 17:37:26 -0600 Subject: [PATCH 4/4] correctly handle flags in main test --- .circleci/config.yml | 12 +++++++++++- README.md | 2 +- docker-compose.yml | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8ccaaa1..4cf0c84 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,9 +23,19 @@ jobs: paths: - /go/pkg/mod key: offen-server-{{ checksum "go.mod" }} + - run: + name: Waiting for Postgres to be ready + command: | + for i in `seq 1 10`; + do + nc -z localhost 5432 && echo Success && exit 0 + echo -n . + sleep 1 + done + echo Failed waiting for Postgres && exit 1 - run: name: Run tests - command: make test + command: make test-ci workflows: version: 2 diff --git a/README.md b/README.md index 1d1ebc8..9a2104c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ To work on the `server` you will need to install `docker-compose` and Go 1.12+. First, bootstrap the dockerized Postgres database used for development: ``` -docker-compose run server go run cmd/bootstrap/main.go +docker-compose run server make bootstrap ``` Run the server: diff --git a/docker-compose.yml b/docker-compose.yml index 44013ba..d8104e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ server: - $GOPATH/pkg/mod:/go/pkg/mod environment: - GOPATH=/go + - POSTGRES_CONNECTION_STRING=postgres://postgres:develop@database:5432/postgres?sslmode=disable ports: - 8080:8080 command: go run cmd/server/main.go -conn postgres://postgres:develop@database:5432/postgres?sslmode=disable