Skip to content

Commit 8daeebb

Browse files
aeneasrory-bot
authored andcommitted
docs: update readmes
GitOrigin-RevId: 936016692123f481c9addb607355ac326edee206
1 parent fc32cb5 commit 8daeebb

File tree

2 files changed

+381
-506
lines changed

2 files changed

+381
-506
lines changed

DEVELOP.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Development
2+
3+
This document explains how to develop Ory Hydra, run tests, and work with the tooling around it.
4+
5+
## Upgrading and changelog
6+
7+
New releases might introduce breaking changes. To help you identify and incorporate those changes, we document these changes in [CHANGELOG.md](./CHANGELOG.md).
8+
9+
## Command line documentation
10+
11+
To see available commands and flags, run:
12+
13+
```shell
14+
hydra -h
15+
# or
16+
hydra help
17+
```
18+
19+
## Contribution guidelines
20+
21+
We encourage all contributions. Before opening a pull request, read the [contribution guidelines](./CONTRIBUTING.md).
22+
23+
## Prerequisites
24+
25+
You need Go 1.13+ with `GO111MODULE=on` and, for the test suites:
26+
27+
- Docker and Docker Compose
28+
- Makefile
29+
- Node.js and npm
30+
31+
It is possible to develop Ory Hydra on Windows, but please be aware that all guides assume a Unix shell like bash or zsh.
32+
33+
## Formatting code
34+
35+
Format all code using:
36+
37+
```shell
38+
make format
39+
```
40+
41+
The continuous integration pipeline checks code formatting.
42+
43+
## Running tests
44+
45+
There are three types of tests:
46+
47+
- Short tests that do not require a SQL database
48+
- Regular tests that require PostgreSQL, MySQL, and CockroachDB
49+
- End to end tests that use real databases and a test browser
50+
51+
### Short tests
52+
53+
Short tests run fairly quickly and use SQLite in-memory.
54+
55+
All tests run against a sqlite in-memory database, thus it is required to use the `-tags sqlite` build tag.
56+
57+
Run all short tests:
58+
59+
```shell
60+
go test -v -failfast -short -tags sqlite ./...
61+
```
62+
63+
Run short tests in a specific module:
64+
65+
```shell
66+
go test -v -failfast -short -tags sqlite ./client
67+
```
68+
69+
Run a specific test:
70+
71+
```shell
72+
go test -v -failfast -short -tags sqlite -run ^TestName$ ./...
73+
```
74+
75+
### Regular tests
76+
77+
Regular tests require a database setup.
78+
79+
The test suite can use [ory/dockertest](https://github.com/ory/dockertest) to work with docker directly, but we encourage using the Makefile instead. Using dockertest can bloat the number of Docker Images on your system and are quite slow.
80+
81+
Run the full test suite:
82+
83+
```shell
84+
make test
85+
```
86+
87+
> Note: `make test` recreates the databases every time. This can be annoying if you are trying to fix something very specific and need the database tests all the time.
88+
89+
If you want to reuse databases across test runs, initialize them once:
90+
91+
```shell
92+
make test-resetdb
93+
export TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true&multiStatements=true'
94+
export TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/postgres?sslmode=disable'
95+
export TEST_DATABASE_COCKROACHDB='cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable'
96+
```
97+
98+
Then you can run Go tests directly as often as needed:
99+
100+
```shell
101+
go test -p 1 ./...
102+
103+
# or in a module:
104+
cd client
105+
go test .
106+
```
107+
108+
### End-to-end tests
109+
110+
The E2E tests use [Cypress](https://www.cypress.io) to run full browser tests.
111+
112+
Run e2e tests:
113+
114+
```
115+
make e2e
116+
```
117+
118+
The runner will not show the Browser window, as it runs in the CI Mode (background). That makes debugging these type of tests very difficult, but thankfully you can run the e2e test in the browser which helps with debugging:
119+
120+
```shell
121+
./test/e2e/circle-ci.bash memory --watch
122+
123+
# Or for the JSON Web Token Access Token strategy:
124+
# ./test/e2e/circle-ci.bash memory-jwt --watch
125+
```
126+
127+
Or if you would like to test one of the databases:
128+
129+
```shell
130+
make test-resetdb
131+
export TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true&multiStatements=true'
132+
export TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/postgres?sslmode=disable'
133+
export TEST_DATABASE_COCKROACHDB='cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable'
134+
135+
# You can test against each individual database:
136+
./test/e2e/circle-ci.bash postgres --watch
137+
./test/e2e/circle-ci.bash memory --watch
138+
./test/e2e/circle-ci.bash mysql --watch
139+
# ...
140+
```
141+
142+
Once you run the script, a Cypress window will appear. Hit the button "Run all Specs"!
143+
144+
The code for these tests is located in [./cypress/integration](./cypress/integration) and [./cypress/support](./cypress/support) and [./cypress/helpers](./cypress/helpers). The website you're seeing is located in [./test/e2e/oauth2-client](./test/e2e/oauth2-client).
145+
146+
#### OpenID Connect conformity tests
147+
148+
To run Ory Hydra against the OpenID Connect conformity suite, run:
149+
150+
```shell
151+
./test/conformity/start.sh --build
152+
```
153+
154+
and then in a separate shell:
155+
156+
```shell
157+
./test/conformity/test.sh
158+
```
159+
160+
Running these tests will take a significant amount of time which is why they are not part of the CI pipeline.
161+
162+
## Build Docker image
163+
164+
To build a development Docker Image:
165+
166+
```shell
167+
make docker
168+
```
169+
170+
> [!WARNING] If you already have a production image (e.g. `oryd/hydra:v2.2.0`) pulled, the above `make docker` command will replace it with a local build of the image that is more equivalent to the `-distroless` variant on Docker Hub.
171+
>
172+
> You can pull the production image any time using `docker pull`
173+
174+
## Run the Docker Compose quickstarts
175+
176+
If you wish to check your code changes against any of the docker-compose quickstart files, run:
177+
178+
```shell
179+
docker compose -f quickstart.yml up --build
180+
```
181+
182+
## Add a new migration
183+
184+
1. `mkdir persistence/sql/src/YYYYMMDD000001_migration_name/`
185+
2. Put the migration files into this directory, following the standard naming conventions. If you wish to execute different parts of a migration in separate transactions, add split marks (lines with the text `--split`) where desired. Why this might be necessary is explained in https://github.com/gobuffalo/fizz/issues/104.
186+
3. Run `make persistence/sql/migrations/<migration_id>` to generate migration fragments.
187+
4. If an update causes the migration to have fewer fragments than the number already generated, run `make persistence/sql/migrations/<migration_id>-clean`. This is equivalent to a `rm` command with the right parameters, but comes with better tab completion.
188+
5. Before committing generated migration fragments, run the above clean command and generate a fresh copy of migration fragments to make sure the `sql/src` and `sql/migrations` directories are consistent.

0 commit comments

Comments
 (0)