Skip to content

Commit de4ec84

Browse files
refactor: clean up docker cmds and improve code blocks (#2041)
1 parent 1a856de commit de4ec84

19 files changed

+137
-130
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ By contributing to this project, you agree to abide by our [Code of Conduct](htt
2424
1. Fork this repository by clicking the "Fork" button at the top right of the `api-platform/docs` repository page.
2525

2626
2. Clone the forked repository to your local machine:
27-
```bash
27+
```console
2828
git clone https://github.com/your-username/repository-name.git
2929
```
3030
3. Create a new branch for your contribution:
31-
```bash
31+
```console
3232
git switch -c docs-your-branch-name
3333
```
3434
4. Commit and push your changes

admin/getting-started.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ nelmio_cors:
5858
Clear the cache to apply this change:
5959
6060
```console
61-
docker compose exec php \
62-
bin/console cache:clear --env=prod
61+
bin/console cache:clear --env=prod
6362
```
6463

6564
Your new administration interface is ready! Type `npm start` to try it!

core/file-upload.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ api_platform:
2525
Install the bundle with the help of Composer:
2626
2727
```console
28-
docker compose exec php \
29-
composer require vich/uploader-bundle
28+
composer require vich/uploader-bundle
3029
```
3130

3231
This will create a new configuration file that you will need to slightly change

core/graphql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Once enabled, you have nothing to do: your schema describing your API is automat
1313
To enable GraphQL and its IDE (GraphiQL and GraphQL Playground) in your API, simply require the `api-platform/graphql` package using Composer:
1414

1515
```console
16-
composer require api-platform/graphql
16+
composer require api-platform/graphql
1717
```
1818

1919
You can now use GraphQL at the endpoint: `https://localhost:8443/graphql`.

core/json-schema.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ The generated schema can be used with libraries such as [react-json-schema-form]
1010
To export the schema corresponding to an API Resource, run the following command:
1111

1212
```console
13-
docker compose exec php \
14-
bin/console api:json-schema:generate 'App\Entity\Book'
13+
bin/console api:json-schema:generate 'App\Entity\Book'
1514
```
1615

1716
To see all options available, try:
1817

1918
```console
20-
docker compose exec php \
21-
bin/console help api:json-schema:generate
19+
bin/console help api:json-schema:generate
2220
```
2321

2422
## Overriding the JSON Schema Specification

core/jwt.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# JWT Authentication
22

3-
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
4-
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
3+
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert
4+
> some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and
5+
> provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
6+
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens
7+
> are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
58
>
69
> [Uncyclopedia](https://en.wikipedia.org/wiki/JSON_Web_Token)
710
@@ -14,11 +17,17 @@ API Platform allows to easily add a JWT-based authentication to your API using [
1417
We begin by installing the bundle:
1518

1619
```console
17-
docker compose exec php \
18-
composer require lexik/jwt-authentication-bundle
20+
composer require lexik/jwt-authentication-bundle
1921
```
22+
Then we need to generate the public and private keys used for signing JWT tokens.
2023

21-
Then we need to generate the public and private keys used for signing JWT tokens. If you're using the [API Platform distribution](../symfony/index.md), you may run this from the project's root directory:
24+
You can generate them by using this command:
25+
26+
```console
27+
php bin/console lexik:jwt:generate-keypair
28+
```
29+
30+
Or if you're using the [API Platform distribution with Symfony](../symfony/index.md), you may run this from the project's root directory:
2231

2332
```console
2433
docker compose exec php sh -c '
@@ -30,13 +39,18 @@ docker compose exec php sh -c '
3039
'
3140
```
3241

33-
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
42+
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform
43+
docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
3444

35-
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the correct permissions on the keys allowing the web server to read them.
45+
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the
46+
correct permissions on the keys allowing the web server to read them.
3647

37-
Since these keys are created by the `root` user from a container, your host user will not be able to read them during the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are skipped from the result image.
48+
If you want the keys to be auto generated in `dev` environment, see an example in the
49+
[docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/a03ce4fb1f0e072c126e8104e42a938bb840bffc/api/docker/php/docker-entrypoint.sh#L16-L17).
3850

39-
If you want the keys to be auto generated in `dev` environment, see an example in the [docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/master/api/docker/php/docker-entrypoint.sh).
51+
Since these keys are created by the `root` user from a container, your host user will not be able to read them during
52+
the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are
53+
skipped from the result image.
4054

4155
The keys should not be checked in to the repository (i.e. it's in `api/.gitignore`). However, note that a JWT token could
4256
only pass signature validation against the same pair of keys it was signed with. This is especially relevant in a production

core/messenger.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Many transports are supported to dispatch messages to async consumers, including
1212
To enable the support of Messenger, install the library:
1313

1414
```console
15-
docker compose exec php \
16-
composer require messenger
15+
composer require symfony/messenger
1716
```
1817

1918
## Dispatching a Resource through the Message Bus

core/mongodb.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the legacy [mongo](https://secure.php.net/manual/en/book.mongo.php) extension.
1818

1919
If the `mongodb` PHP extension is not installed yet, [install it beforehand](https://secure.php.net/manual/en/mongodb.installation.pecl.php).
2020

21-
If you are using the [API Platform Distribution](../symfony/index.md), modify the `Dockerfile` to add the extension:
21+
Or if you are using the [API Platform Distribution with Symfony](../symfony/index.md), modify the `Dockerfile` to add the extension:
2222

2323
```diff
2424
# api/Dockerfile
@@ -64,12 +64,11 @@ services:
6464
# ...
6565
```
6666

67-
Once the extension is installed, to enable the MongoDB support, require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
67+
In all cases, enable the MongoDB support by requiring the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
6868
package using Composer:
6969

7070
```console
71-
docker compose exec php \
72-
composer require doctrine/mongodb-odm-bundle
71+
composer require doctrine/mongodb-odm-bundle
7372
```
7473

7574
Execute the contrib recipe to have it already configured.

core/openapi.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,31 @@ You can also dump an OpenAPI specification for your API.
2020
OpenAPI, JSON format:
2121

2222
```console
23-
docker compose exec php \
24-
bin/console api:openapi:export
23+
bin/console api:openapi:export
2524
```
2625

2726
OpenAPI, YAML format:
2827

2928
```console
30-
docker compose exec php \
31-
bin/console api:openapi:export --yaml
29+
bin/console api:openapi:export --yaml
3230
```
3331

3432
Create a file containing the specification:
3533

3634
```console
37-
docker compose exec php \
38-
bin/console api:openapi:export --output=swagger_docs.json
35+
bin/console api:openapi:export --output=swagger_docs.json
3936
```
4037

4138
If you want to use the old OpenAPI v2 (Swagger) JSON format, use:
4239

4340
```console
44-
docker compose exec php \
45-
bin/console api:swagger:export
41+
bin/console api:swagger:export
4642
```
4743

4844
It is also possible to use OpenAPI v3.0.0 format:
4945

5046
```console
51-
docker compose exec php \
52-
bin/console api:openapi:export --spec-version=3.0.0
47+
bin/console api:openapi:export --spec-version=3.0.0
5348
```
5449

5550
## Overriding the OpenAPI Specification

core/testing.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Reuse them to run, for instance, SQL queries or requests to external APIs direct
1717
Install the `symfony/http-client` and `symfony/browser-kit` packages to enabled the API Platform test client:
1818

1919
```console
20-
docker compose exec php \
21-
composer require symfony/browser-kit symfony/http-client
20+
composer require symfony/browser-kit symfony/http-client
2221
```
2322

2423
To use the testing client, your test class must extend the `ApiTestCase` class:

create-client/nextjs.md

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,42 @@ If you use API Platform, jump to the next section!
1515

1616
Alternatively, create a Next.js application by executing:
1717

18-
```console
19-
# using pnpm (recommended)
20-
pnpm create next-app --typescript
21-
# or using npm
22-
npm init next-app --typescript
23-
# or using yarn
24-
yarn create next-app --typescript
25-
```
18+
- Pnpm (recommended)
19+
```console
20+
pnpm create next-app --typescript
21+
```
22+
- Npm
23+
```console
24+
npm init next-app --typescript
25+
```
26+
- Yarn
27+
```console
28+
yarn reate next-app --typescript
29+
```
30+
2631

2732
Install the required dependencies:
2833

29-
```console
30-
# using pnpm
31-
pnpm install isomorphic-unfetch formik react-query
32-
# or using npm
33-
npm install isomorphic-unfetch formik react-query
34-
# or using yarn
35-
yarn add isomorphic-unfetch formik react-query
36-
```
34+
- Pnpm (recommended)
35+
```console
36+
pnpm install isomorphic-unfetch formik react-query
37+
```
38+
- Npm
39+
```console
40+
npm install isomorphic-unfetch formik react-query
41+
```
42+
- Yarn
43+
```console
44+
yarn add isomorphic-unfetch formik react-query
45+
```
3746

3847
The generated HTML will contain [Tailwind CSS](https://tailwindcss.com) classes.
3948
Optionally, [follow the Tailwind installation guide for Next.js projects](https://tailwindcss.com/docs/guides/nextjs)
4049
(Tailwind is preinstalled in [the API Platform Symfony variant](../symfony/index.md))
4150

4251
## Generating Routes
4352

44-
If you use the API Platform symfony variant, generating all the code you need for a given resource is as simple as running the following command:
53+
If you are using the [API Platform Distribution with Symfony](../symfony/index.md) generating all the code you need for a given resource is as simple as running the following command:
4554

4655
```console
4756
docker compose exec pwa \
@@ -50,16 +59,20 @@ docker compose exec pwa \
5059

5160
Omit the resource flag to generate files for all resource types exposed by the API.
5261

53-
If you don't use the standalone installation, run the following command instead:
54-
55-
```console
56-
# using pnpm
57-
pnpm create @api-platform/client https://demo.api-platform.com . --generator next --resource book
58-
# or using npm
59-
npm init @api-platform/client https://demo.api-platform.com . -- --generator next --resource book
60-
# or using yarn
61-
yarn create @api-platform/client https://demo.api-platform.com . --generator next --resource book
62-
```
62+
Or if you don't use the standalone installation, run the following command instead:
63+
64+
- Pnpm (recommended)
65+
```console
66+
pnpm create @api-platform/client https://demo.api-platform.com . --generator next --resource book
67+
```
68+
- Npm
69+
```console
70+
npm init @api-platform/client https://demo.api-platform.com . -- --generator next --resource book
71+
```
72+
- Yarn
73+
```console
74+
yarn create @api-platform/client https://demo.api-platform.com . --generator next --resource book
75+
```
6376

6477
Replace the URL by the entrypoint of your Hydra-enabled API.
6578
You can also use an OpenAPI documentation with `-f openapi3`.
@@ -85,22 +98,26 @@ export default App;
8598

8699
## Starting the Project
87100

88-
You can launch the server with
89-
90-
```console
91-
# using pnpm
92-
pnpm dev
93-
# or using npm
94-
npm run dev
95-
# or using yarn
96-
yarn dev
97-
```
98-
101+
You can launch the server with:
102+
103+
- Pnpm (recommended)
104+
```console
105+
pnpm dev
106+
```
107+
- Npm
108+
```console
109+
npm run dev
110+
```
111+
- Yarn
112+
```console
113+
yarn dev
114+
```
115+
99116
Go to `http://localhost:3000/books/` to start using your app.
100117

101118
## Generating a production build locally with docker compose
102119

103-
If you want to generate a production build locally with docker compose, follow [these instructions](../deployment/docker-compose.md)
120+
If you want to generate a production build locally with docker compose, follow [these instructions](../deployment/docker-compose.md).
104121

105122
## Screenshots
106123

deployment/docker-compose.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Go to `https://your-domain-name.example.com` and enjoy!
8989

9090
Alternatively, if you don't want to expose an HTTPS server but only an HTTP one, run the following command:
9191

92-
```bash
92+
```console
9393
SERVER_NAME=http://localhost \
9494
MERCURE_PUBLIC_URL=http://localhost/.well-known/mercure \
9595
TRUSTED_HOSTS='^localhost|php$' \
@@ -142,7 +142,7 @@ pwa:
142142
143143
Begin by starting the php service container:
144144
145-
```bash
145+
```console
146146
SERVER_NAME=http://localhost \
147147
MERCURE_PUBLIC_URL=http://localhost/.well-known/mercure \
148148
TRUSTED_HOSTS='^localhost|php$' \
@@ -162,13 +162,13 @@ NEXT_PUBLIC_ENTRYPOINT=http://php
162162

163163
#### 4. Build the pwa service
164164

165-
```bash
165+
```console
166166
docker compose -f compose.yaml -f compose.prod.yaml build pwa
167167
```
168168

169169
#### 5. Finally, bring up the full project
170170

171-
```bash
171+
```console
172172
SERVER_NAME=http://localhost \
173173
MERCURE_PUBLIC_URL=http://localhost/.well-known/mercure \
174174
TRUSTED_HOSTS='^localhost|php$' \

0 commit comments

Comments
 (0)