Skip to content

Commit

Permalink
Merge pull request #241 from developmentseed/fix/dev-instructions
Browse files Browse the repository at this point in the history
Update development instructions
  • Loading branch information
vgeorge authored Feb 23, 2022
2 parents 552c9fa + 275df13 commit be2f5bf
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:12.16
- image: circleci/node:14

environment:
DATABASE_URL: postgres://postgres@localhost/osm-teams-test
Expand Down
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OSM_CONSUMER_KEY=<osm-consumer-key>
OSM_CONSUMER_SECRET=<osm-consumer-secret>
DSN=postgres://postgres@host.docker.internal/osm-teams?sslmode=disable
DSN=postgres://postgres@dev-db/osm-teams?sslmode=disable
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ node_modules.nosync
.idea
hydra-config/prod/prod.yml
.nyc_output
coverage
coverage
docker-data/*
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12.16
14
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:lts
FROM node:14

# Create app directory
WORKDIR /usr/src/app
Expand Down
61 changes: 27 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,30 @@
Check the beta 👉 <!-- markdownlint-disable MD034 -->https://mapping.team
<!-- markdownlint-enable MD034 -->

## Development

## Installation
Install requirements:

### Requirements
- [nvm](https://github.com/creationix/nvm)
- [Docker](https://www.docker.com)

- [PostgreSQL](https://www.postgresql.org). On OS X, the easiest is to install [Postgres.app](https://postgresapp.com/).
- [Node.js](https://nodejs.org) v12.16+
- [Docker](https://www.docker.com/) & Docker Compose
Visit your [OpenStreetMap settings](https://www.openstreetmap.org/account/edit) page and register an OAuth1 Client App:

### Setting up Hydra
![OSM Client App](oauth1-osm-client-app.png "OAuth1 page at OSM Website")

1. Create the database for tokens

```bash
createdb osm-teams
createdb osm-teams-test
```

For the rest of this documentation, we will assume that the database location is `postgres://postgres@localhost/osm-teams?sslmode=disable` on your local machine. Inside docker, that location is `postgres://[email protected]/osm-teams?sslmode=disable`

1. Create an `.env` file by copying `.env.sample` and replacing the values as needed. `OSM_CONSUMER_KEY` and `OSM_CONSUMER_SECRET` are values obtained by creating a new OAuth app on openstreetmap.org. The .env file can contain:
Create an `.env` file by copying `.env.sample` and replacing the values as needed. `OSM_CONSUMER_KEY` and `OSM_CONSUMER_SECRET` are values available at the OAuth app page on openstreetmap.org. The .env file should contain:

```bash
OSM_CONSUMER_KEY=<osm-teams-app>
OSM_CONSUMER_SECRET=<osm-teams-app-secret>
DSN=postgres://[email protected]/osm-teams?sslmode=disable
```

1. Build the docker images:

```bash
docker-compose -f compose.yml build
```

1. Start Hydra and the server

```bash
docker-compose -f compose.yml -f compose.dev.yml up
DSN=postgres://postgres@dev-db/osm-teams?sslmode=disable
```

⚠️ In development, `docker-compose -f compose.yml -f compose.dev.yml up` enables hot module reloading while you make modifications to the code. `docker-compose up` should be used for production/staging deployments.

This will start hydra where the token issuer is at `http://localhost:4444` and the admin interface is at `http://localhost:4445`. This also sets up the consent and login interface at `http://localhost:8989` (where we will create a first-party oauth app)
Start Hydra and PostgreSQL with Docker:

### Setting up the OSM-teams app
docker-compose -f compose.dev.yml up --build

Create the [first-party](https://auth0.com/docs/applications/concepts/app-types-first-third-party) "manage" app
On a separate terminal, create the [first-party](https://auth0.com/docs/applications/concepts/app-types-first-third-party) "manage" app:

```bash
docker-compose exec hydra hydra clients create --endpoint http://localhost:4445 \
Expand All @@ -74,6 +51,22 @@ docker-compose exec hydra hydra clients create --endpoint http://localhost:4445
--callbacks http://localhost:8989/login/accept
```

Install Node.js the required version (see [.nvmrc](.nvmrc) file):

nvm i

Install Node.js modules:

yarn

Migrate `dev-db` database:

yarn migrate

Start development server:

yarn dev

<!-- markdownlint-disable MD034 -->
✨ You can now login to the app at http://localhost:8989
<!-- markdownlint-enable MD034 -->
Expand Down
18 changes: 7 additions & 11 deletions app/db/knexfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
let DATABASE_URL
let DATABASE_URL = process.env.DSN || process.env.DATABASE_URL

if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development'
}

if (process.env.DSN) {
DATABASE_URL = process.env.DSN
} else {
if (process.env.NODE_ENV === 'development') {
DATABASE_URL = 'postgres://postgres@localhost/osm-teams?sslmode=disable'
// Apply defaults if no connection string is passed
if (!DATABASE_URL) {
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
DATABASE_URL =
'postgres://postgres:postgres@localhost:5433/osm-teams?sslmode=disable'
} else if (process.env.NODE_ENV === 'test') {
DATABASE_URL = 'postgres://postgres@localhost/osm-teams-test?sslmode=disable'
DATABASE_URL = 'postgres://postgres:postgres@localhost:5434/osm-teams-test?sslmode=disable'
}
}

Expand Down
62 changes: 55 additions & 7 deletions compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
version: '3.7'

services:
teams:
build: .
hydra:
image: oryd/hydra:v1.9.2
ports:
- 8989:8989
- 3007:3007
- 4444:4444
- 4445:4445
- 5555:5555
command:
serve -c /etc/config/hydra/hydra.yml all --dangerous-force-http
volumes:
- .:/usr/src/app
- ./node_modules:/usr/src/app/node_modules
-
type: bind
source: ./hydra-config/dev
target: /etc/config/hydra
env_file:
.env
depends_on:
- hydra-migrate
restart: always

hydra-migrate:
image: oryd/hydra:v1.9.2
command:
npm run dev
migrate -c /etc/config/hydra/hydra.yml sql -e --yes
volumes:
-
type: bind
source: ./hydra-config/dev
target: /etc/config/hydra
env_file:
.env
restart: on-failure

dev-db:
platform: linux/amd64
image: mdillon/postgis:9.6-alpine
restart: 'always'
ports:
- 5433:5432
environment:
- ALLOW_IP_RANGE=0.0.0.0/0
- POSTGRES_DB=osm-teams
- PGDATA=/opt/postgres/data
volumes:
- ./docker-data/dev-db:/opt/postgres/data

test-db:
platform: linux/amd64
image: mdillon/postgis:9.6-alpine
restart: 'always'
ports:
- 5434:5432
environment:
- ALLOW_IP_RANGE=0.0.0.0/0
- POSTGRES_DB=osm-teams-test
- PGDATA=/opt/postgres/data
volumes:
- ./docker-data/test-db:/opt/postgres/data

Binary file added oauth1-osm-client-app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit be2f5bf

Please sign in to comment.