Skip to content

Commit

Permalink
Merge pull request #345 from developmentseed/develop
Browse files Browse the repository at this point in the history
Release v2.0.0
  • Loading branch information
kamicut authored Dec 15, 2022
2 parents 2ee9c1c + 9cc5fd1 commit 7d06172
Show file tree
Hide file tree
Showing 235 changed files with 11,715 additions and 12,779 deletions.
31 changes: 0 additions & 31 deletions .circleci/config.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXTAUTH_URL=http://127.0.0.1:3000
DATABASE_URL=postgres://postgres:postgres@localhost:5433/osm-teams?sslmode=disable
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXTAUTH_SECRET=next-auth-development-secret
3 changes: 0 additions & 3 deletions .env.sample

This file was deleted.

4 changes: 4 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXTAUTH_URL=http://127.0.0.1:3000
NEXTAUTH_SECRET=next-auth-cypress-secret
DATABASE_URL=postgres://postgres:postgres@localhost:5434/osm-teams-test
TESTING=true
17 changes: 9 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"root": true,
"extends": ["devseed-standard"],
"rules": {
"camelcase": "off",
"node/no-deprecated-api": ["error", {
"ignoreModuleItems": ["url.parse"]
}]
}
"env": {
"es6": true
},
"extends": [
"eslint:recommended",
"next/core-web-vitals",
"plugin:prettier/recommended",
"plugin:cypress/recommended"
]
}
58 changes: 58 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Test

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
test:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
timeout-minutes: 30
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Checkout
uses: actions/checkout@v2

- name: Setup node from node version file
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install

- name: Lint
run: yarn lint

- name: Docker - Pull
run: docker-compose pull

- name: Docker - Start Test DB
run: docker-compose up --build -d test-db

- name: Migrate database
run: for i in {1..6}; do yarn migrate:test && break || sleep 10; done # retries up to 6 times every 10 s if db is not available

- name: Run API tests
run: yarn test

- name: Run Cypress tests
run: yarn e2e

- name: Docker Cleanup
run: docker-compose kill
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ node_modules
tmp
*.log*
.next
*.env
.vscode
*.db
# ignore node_modules symlink
Expand All @@ -12,4 +11,6 @@ node_modules.nosync
hydra-config/prod/prod.yml
.nyc_output
coverage
docker-data/*
docker-data/*
public/swagger.json
.env*.local
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"tabWidth": 2,
"jsxSingleQuote": true,
"semi": false
}
24 changes: 18 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## beta2
## [v2.0.0] - 2022-11-22

### Added

- Model for collections of teams called "organizations"
- New roles for organizations, "organization owner" and "organization manager"
- Shell scripts for managing organizations, owners, and managers
- Middleware to catch errors consistently with Boom module
- Cypress configuration
- Authentication with next-auth
### Changed

## beta1
- Upgraded Next.js to v13
- Upgraded Node.js to v18
- ESLint rules
- Make table rows slightly more compact #291
- Use Next.js default port instead of `:8989`

### TODO complete this
### Fixed

- Scroll bar
- Reinstate API docs with `next-swagger-doc`

### Breaking

- Hydra configuration is temporarily broken, meaning it is not possible to create new clients
21 changes: 16 additions & 5 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Production Deployment Documentation
# Production Deployment Documentation

## Requirements
In production, you will need either a subdomain or a namespace for the hydra token issuer. Nginx, Apache or Caddyserver could be used as a reverse proxy server to capture the URL and forward to either the OSM Teams application or hydra. For this example, let's take the use case of mapping.team.

In production, you will need either a subdomain or a namespace for the hydra token issuer. Nginx, Apache or Caddyserver could be used as a reverse proxy server to capture the URL and forward to either the OSM Teams application or hydra. For this example, let's take the use case of mapping.team.

## Setting up Hydra URLs

1. Copy over `hydra-config/dev/hydra.yml` to `hydra-config/prod/hydra.yml`
2. Modify the `urls` values in `hydra.yml`
2. Modify the `urls` values in `hydra.yml`

For example, for `mapping.team` we modify the urls to be the following:

```yaml
urls:
self:
Expand All @@ -18,6 +21,7 @@ urls:
```
This is because we set the token provider at `https://mapping.team/hyauth` and use a reverse proxy (nginx):

```nginx
server {
server_name mapping.team dev.mapping.team;
Expand All @@ -30,17 +34,19 @@ This is because we set the token provider at `https://mapping.team/hyauth` and u
location / {
proxy_set_header host $host;
proxy_pass http://127.0.0.1:8989/;
proxy_pass http://127.0.0.1:3000/;
}
}
```

3. Modify `hydra.yml` system secret and others according to the [configuration spec](https://www.ory.sh/hydra/docs/reference/configuration/)

### Env variables

Similarly to local development, we have to add `OSM_CONSUMER_KEY`, `OSM_CONSUMER_SECRET` and `DSN` to `.env`

We also have to add a few environment variables so that the tokens are issued by the proper URL:

```bash
HYDRA_ADMIN_HOST=http://hydra:4445
HYDRA_TOKEN_HOST=http://hydra:4444
Expand All @@ -56,12 +62,16 @@ HYDRA_AUTHZ_PATH=/hyauth/oauth2/auth

Finally we should set `APP_URL` to be the new domain, for example `https://mapping.team`

If you are using a sub-path of a domain you should set the `BASE_PATH` environment variable

`.env` will now look like:

```sh
OSM_CONSUMER_KEY=<redacted>
OSM_CONSUMER_SECRET=<redacted>
APP_URL=https://mapping.team
DSN=<redacted>
BASE_PATH=/example
HYDRA_ADMIN_HOST=http://hydra:4445
HYDRA_TOKEN_HOST=http://hydra:4444
HYDRA_TOKEN_PATH=/oauth2/token
Expand All @@ -70,8 +80,9 @@ HYDRA_AUTHZ_PATH=/hyauth/oauth2/auth
```

## Deployment

Once the environment variables, `hydra.yml` and the reverse proxy are created, we can then run:

```docker
docker-compose -f compose.yml -f compose.prod.yml up
```
```
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ COPY . .

RUN npm run build

EXPOSE 8989
EXPOSE 3000
CMD [ "npm", "start"]
80 changes: 42 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# osm-teams 🤝

<div>
<a href="https://circleci.com/gh/developmentseed/osm-teams">
<img src="https://circleci.com/gh/developmentseed/osm-teams.png" />
</a>
<a href="https://standardjs.com">
<img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"
alt="Standard" />
</a>
<a href="http://validator.swagger.io/validator/debug?url=https://raw.githubusercontent.com/developmentseed/osm-teams/master/docs/api.yml">
<img src="http://validator.swagger.io/validator?url=https://raw.githubusercontent.com/developmentseed/osm-teams/master/docs/api.yml">
</a>
</div>

Check the beta 👉 <!-- markdownlint-disable MD034 -->https://mapping.team
<!-- markdownlint-enable MD034 -->
# OSM Teams 🤝

## Development

Expand All @@ -23,33 +7,25 @@ Install requirements:
- [nvm](https://github.com/creationix/nvm)
- [Docker](https://www.docker.com)

Visit your [OpenStreetMap settings](https://www.openstreetmap.org/account/edit) page and register an OAuth1 Client App:
Visit your [OpenStreetMap settings](https://www.openstreetmap.org/account/edit) page and [register an OAuth2 app](https://www.openstreetmap.org/oauth2/applications) with the following settings:

![OSM Client App](oauth1-osm-client-app.png "OAuth1 page at OSM Website")
- Name: `OSM Teams Dev` (or another name of your preference)
- Redirect URIs: `http://127.0.0.1:3000/api/auth/callback/openstreetmap`
- Confidential application: `false`
- Permissions: `Read user preferences` only

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:
Example:

```bash
OSM_CONSUMER_KEY=<osm-teams-app>
OSM_CONSUMER_SECRET=<osm-teams-app-secret>
DSN=postgres://postgres@dev-db/osm-teams?sslmode=disable
```
![OSM Client App](oauth2-osm-client-app.png "OAuth 2 page at OSM Website")

Start Hydra and PostgreSQL with Docker:
Create an `.env.local` file and add environment variables `OSM_CONSUMER_KEY` and `OSM_CONSUMER_SECRET` obtained at OAuth2 page at OpenStreetMap website. The `.env.local` file should be like the following:

docker-compose -f compose.dev.yml up --build
OSM_CONSUMER_KEY=<osm-oauth2-client-id>
OSM_CONSUMER_SECRET=<osm-oauth2-client-secret>

On a separate terminal, create the [first-party](https://auth0.com/docs/applications/concepts/app-types-first-third-party) "manage" app:
Start development and test databases with Docker:

```bash
docker-compose exec hydra hydra clients create --endpoint http://localhost:4445 \
--id manage \
--secret manage-secret \
--response-types code,id_token \
--grant-types refresh_token,authorization_code \
--scope openid,offline,clients \
--callbacks http://localhost:8989/login/accept
```
docker-compose up --build

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

Expand All @@ -68,9 +44,37 @@ Start development server:
yarn dev

<!-- markdownlint-disable MD034 -->
✨ You can now login to the app at http://localhost:8989
✨ You can now login to the app at http://127.0.0.1:3000
<!-- markdownlint-enable MD034 -->

## Testing

Migrate `test-db` database:

yarn migrate:test

This project uses Cypress for end-to-end testing. To run once:

yarn e2e

To open Cypress dashboard for interactive development:

yarn e2e:dev

## API

The API docs can be accessed at <http://127.0.0.1:3000/docs/api>.

All API routes should include descriptions in [OpenAPI 3.0 format](https://swagger.io/specification).

Run the following command to validate the API docs:

yarn docs:validate

## Acknowledgments

- This app is based off of [OSM/Hydra](https://github.com/kamicut/osmhydra)

## LICENSE

[MIT](LICENSE)
12 changes: 0 additions & 12 deletions app/db/index.js

This file was deleted.

Loading

1 comment on commit 7d06172

@vercel
Copy link

@vercel vercel bot commented on 7d06172 Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

osm-teams – ./

osm-teams-git-main-developmentseed.vercel.app
osm-teams-developmentseed.vercel.app

Please sign in to comment.