Skip to content

Commit

Permalink
Merge pull request #1449 from serlo/staging
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
hugotiburtino authored May 6, 2024
2 parents e4313f7 + 594e630 commit 145e80c
Show file tree
Hide file tree
Showing 178 changed files with 14,120 additions and 3,351 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/push-version-image.yml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ejs-npm-3.1.9-e201b2088c-af6f10eb81.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 62 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export NODE_OPTIONS=--dns-result-order=ipv4first

By default, while developing, the caching won't work. If you want to have caching, change the value `CACHE_TYPE` in `.env` to any other
value besides 'empty'.
To check the cache locally, run `yarn cache:cli`.
With `GET <key>` you get the cache value of the key that is defined in [serlo.ts](https://github.com/serlo/api.serlo.org/blob/staging/packages/server/src/model/serlo.ts).
See in `package.json` for other scripts regarding cache.
To check the cache locally, run `yarn cache:cli`.

Some other useful commands:
`redis:empty` removes the whole cache
`redis:list` lists all cached keys

### Run tests

Expand Down Expand Up @@ -101,16 +103,71 @@ We have `~` as an absolute path alias for `./src` in place, e.g. `~/internals` r
### Other commands

- `yarn build:server` builds the server (only needed for deployment)
- `yarn deploy:images` deploys the docker images to our Container Registry (only needed for deployment)
- `yarn format` formats all source code
- `yarn lint` lints all source code
- `yarn license` updates license headers in source files
- `yarn pacts` runs the contract tests
- `yarn test` runs the unit tests
- `yarn codegen` generates TypeScript types from GraphQL schema
- `yarn start` spins up the development environment
- `yarn update-version` starts the process for adding a new version (only needed for deployment)

## Changelog

Via filtering PRs by [`base:production`](https://github.com/serlo/api.serlo.org/pulls?q=is%3Apr+base%3Aproduction+) you can access the changelog of production.

## Developing with Ory Kratos

We use Ory Kratos for our user management.
Usually you won't need it, but if you do, run first:

`yarn start:kratos`

In the folder `./kratos` you find all important configuration files.
Emails sent by Kratos are going to be found at `http://localhost:4436`.

For more info about it see its [documentation](https://www.ory.sh/docs/kratos).

### Integrating Keycloak

First of all add `nbp` as host
`sudo bash -c "echo '127.0.0.1 nbp'" >> /etc/hosts`

_why do I need it? Kratos makes a request to the url of the oauth2 provider, but since it is running inside a container, it cannot easily use the host port. nbp is a dns that is discoverable for the kratos container, so the host can also use it._

Run `yarn start:nbp`.

Keycloak UI is available on `nbp:11111` (username: admin, pw: admin).
There you have to configure Serlo as a client.

> Client -> Create Client
>
> ```
> id: serlo
> home and root url: http://localhost:3000
> redirect uri: http://localhost:4433/self-service/methods/oidc/callback/nbp
> ```
Get the credentials and go to `kratos/config.yml`:
```yaml
selfservice:
methods:
oidc:
enabled: true
config:
providers:
- id: nbp
provider: generic
client_id: serlo
client_secret: <put secret here>
```
Run the local frontend (not forgetting to change environment in its `.env` to local) to test.

### Email templates

Kratos has to be rebuilt every time you change an email template. Use the following workflow:

1. Edit templates. See at `kratos/config.yml` where they are.
2. Run `yarn kratos:rebuild`
3. Test the verification or the recovery email at `localhost:4436`. Repeat the process.
Empty file.
2 changes: 2 additions & 0 deletions __tests__/__utils__/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class Client {
cache: global.cache,
swrQueue: emptySwrQueue,
authServices,
timer: global.timer,
database: global.database,
}),
},
service: this.context?.service ?? Service.SerloCloudflareWorker,
Expand Down
9 changes: 0 additions & 9 deletions __tests__/__utils__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ const ForDefinitions = {
given('EventQuery').withPayload({ id: event.id }).returns(event)
})
},
SubjectsQuery(terms: Model<'TaxonomyTerm'>[]) {
given('SubjectsQuery')
.withPayload({})
.returns({
subjects: terms.map((term) => {
return { taxonomyTermId: term.id, instance: term.instance }
}),
})
},
UnrevisedEntitiesQuery(entities: Model<'AbstractEntity'>[]) {
given('UnrevisedEntitiesQuery')
.withPayload({})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/internals/create-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
createEvent,
toGraphQLModel,
DatabaseEventRepresentation,
} from '~/schema/notification/event'
} from '~/schema/events/event'
import { Instance } from '~/types'

const basePayload = {
Expand Down
36 changes: 0 additions & 36 deletions __tests__/internals/sentry.ts

This file was deleted.

11 changes: 8 additions & 3 deletions __tests__/schema/entity/checkout-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
taxonomyTermSubject,
} from '../../../__fixtures__'
import { getTypenameAndId, nextUuid, given, Client } from '../../__utils__'
import { emptySubjects } from '../subject'
import { Instance } from '~/types'

const user = { ...baseUser, roles: ['de_reviewer'] }
Expand Down Expand Up @@ -121,7 +122,6 @@ test('checkout revision has trashed == false for following queries', async () =>
})

test('after the checkout mutation the cache is cleared for unrevisedEntities', async () => {
given('SubjectsQuery').for(taxonomyTermSubject)
given('UuidQuery').for(article)

const unrevisedEntitiesQuery = new Client()
Expand All @@ -145,7 +145,10 @@ test('after the checkout mutation the cache is cleared for unrevisedEntities', a

await unrevisedEntitiesQuery.shouldReturnData({
subject: {
subjects: [{ unrevisedEntities: { nodes: [getTypenameAndId(article)] } }],
subjects: [
{ unrevisedEntities: { nodes: [getTypenameAndId(article)] } },
...emptySubjects,
],
},
})

Expand All @@ -154,7 +157,9 @@ test('after the checkout mutation the cache is cleared for unrevisedEntities', a
})

await unrevisedEntitiesQuery.shouldReturnData({
subject: { subjects: [{ unrevisedEntities: { nodes: [] } }] },
subject: {
subjects: [{ unrevisedEntities: { nodes: [] } }, ...emptySubjects],
},
})
})

Expand Down
12 changes: 9 additions & 3 deletions __tests__/schema/entity/reject-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
user as baseUser,
} from '../../../__fixtures__'
import { given, getTypenameAndId, nextUuid, Client } from '../../__utils__'
import { emptySubjects } from '../subject'
import { Instance } from '~/types'

const user = { ...baseUser, roles: ['de_reviewer'] }
Expand All @@ -21,6 +22,7 @@ const currentRevision = {
id: nextUuid(articleRevision.id),
trashed: false,
}

const mutation = new Client({ userId: user.id })
.prepareQuery({
query: gql`
Expand All @@ -37,7 +39,6 @@ const mutation = new Client({ userId: user.id })

beforeEach(() => {
given('UuidQuery').for(user, article, articleRevision, currentRevision)
given('SubjectsQuery').for(taxonomyTermSubject)
given('UnrevisedEntitiesQuery').for([article])

given('EntityRejectRevisionMutation')
Expand Down Expand Up @@ -104,7 +105,10 @@ test('after the reject mutation the cache is cleared for unrevisedEntities', asy

await unrevisedEntitiesQuery.shouldReturnData({
subject: {
subjects: [{ unrevisedEntities: { nodes: [getTypenameAndId(article)] } }],
subjects: [
{ unrevisedEntities: { nodes: [getTypenameAndId(article)] } },
...emptySubjects,
],
},
})

Expand All @@ -113,7 +117,9 @@ test('after the reject mutation the cache is cleared for unrevisedEntities', asy
})

await unrevisedEntitiesQuery.shouldReturnData({
subject: { subjects: [{ unrevisedEntities: { nodes: [] } }] },
subject: {
subjects: [{ unrevisedEntities: { nodes: [] } }, ...emptySubjects],
},
})
})

Expand Down
Loading

0 comments on commit 145e80c

Please sign in to comment.