Skip to content

Commit 02fd13a

Browse files
committedOct 28, 2023
feat: bash -> node/zx, bump node to v20.9
1 parent df08012 commit 02fd13a

13 files changed

+1889
-2371
lines changed
 

‎.github/workflows/release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ jobs:
1515
uses: actions/checkout@v3
1616

1717
- name: Log in to Docker Hub
18-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
18+
uses: docker/login-action@v3
1919
with:
2020
username: ${{ secrets.DOCKERHUB_USERNAME }}
2121
password: ${{ secrets.DOCKERHUB_TOKEN }}
2222

2323
- name: Extract metadata (tags, labels) for Docker
2424
id: meta
25-
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
25+
uses: docker/metadata-action@v5
2626
with:
2727
images: codfish/json-server
2828

2929
- name: Build and push Docker image
30-
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
30+
uses: docker/build-push-action@v5
3131
with:
3232
context: .
3333
push: true

‎.github/workflows/validate.yml

+19-8
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,33 @@ jobs:
1919
- name: lint js
2020
run: npm run lint
2121

22-
- name: Docker meta
23-
id: meta
24-
uses: docker/metadata-action@v4
25-
with:
26-
images: codfish/json-server
27-
2822
- name: Login to DockerHub
29-
uses: docker/login-action@v2
23+
uses: docker/login-action@v3
3024
with:
3125
username: ${{ secrets.DOCKERHUB_USERNAME }}
3226
password: ${{ secrets.DOCKERHUB_TOKEN }}
3327

28+
- name: Docker meta
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: codfish/json-server
33+
3434
- name: Build and push
35-
uses: docker/build-push-action@v4
35+
id: build
36+
uses: docker/build-push-action@v5
3637
with:
3738
context: .
3839
push: true
3940
tags: ${{ steps.meta.outputs.tags }}
4041
labels: ${{ steps.meta.outputs.labels }}
42+
43+
- uses: actions/github-script@v6
44+
with:
45+
script: |
46+
github.rest.issues.createComment({
47+
issue_number: context.issue.number,
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
body: `🚀 PR build published. Run \`docker run -p 9999:80 codfish/json-server@${{ steps.build.outputs.digest }}\``
51+
})

‎.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,4 @@ typings/
9090
# DynamoDB Local files
9191
.dynamodb/
9292

93-
# Custom
9493
dist
95-
build
96-
api

‎.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.2.0
1+
v20.9.0

‎Dockerfile

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
FROM node:20.2.0-slim
1+
FROM node:20.9.0-slim
22

33
RUN mkdir /app
44
WORKDIR /app
55

66
COPY package.json package-lock.json ./
77
RUN npm ci --omit=dev
8-
RUN npm install -g --save-exact json-server@0.17.3 typescript@4.9.5
8+
RUN npm install -g --save-exact nodemon@3.0.1
99

1010
# copy in files
1111
COPY ./tsconfig.json \
1212
./db.js \
1313
./middleware.js \
1414
./routes.json \
15-
./server.sh \
16-
./main.sh ./
15+
./server.mjs ./
1716

1817
EXPOSE 80
1918

20-
CMD [ "./main.sh" ]
19+
ENTRYPOINT [ "nodemon", "server.mjs" ]

‎README.md

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# json-server-docker
22

3-
Docker image for building a full fake REST API with
4-
[json-server](https://github.com/typicode/json-server).
3+
Dockerized [json-server](https://github.com/typicode/json-server) for building a full fake RESTful
4+
API.
55

66
[![version](https://img.shields.io/docker/v/codfish/json-server/0.17.3)](https://hub.docker.com/r/codfish/json-server)
77
[![pulls](https://img.shields.io/docker/pulls/codfish/json-server.svg)](https://hub.docker.com/r/codfish/json-server)
@@ -43,6 +43,7 @@ Docker image for building a full fake REST API with
4343
[`jwt-decode`](https://github.com/auth0/jwt-decode) in any of the files powering your mock api.
4444
- 🧳 **Install your own dependencies** - Use the `DEPENDENCIES` envvar to pass a list of additional
4545
npm dependencies to use in your server files.
46+
- 🔂 **Hot reloading** the server on any changes.
4647

4748
## Getting Started
4849

@@ -52,7 +53,7 @@ Docker image for building a full fake REST API with
5253
> image, which might break. Image tags are based off of the
5354
> [release versions for json-server](https://github.com/typicode/json-server/releases). However
5455
> there is not an image for every version. See the available versions
55-
> [here](https://hub.docker.com/r/codfish/json-server).
56+
> [here](https://hub.docker.com/r/codfish/json-server/tags).
5657
5758
By default, the image runs an instance of `json-server` with some dummy data for show. Spin up the
5859
example mock api in seconds.
@@ -89,7 +90,6 @@ version: '3'
8990
services:
9091
api:
9192
image: codfish/json-server:0.17.3
92-
command: npm run dev
9393
ports:
9494
- 9999:80
9595
volumes:
@@ -98,7 +98,7 @@ services:
9898
- ./my-routes.json:/app/routes.json:delegated
9999
```
100100
101-
Run `docker-compose up api`. Visit <http://localhost:9999/> to see your running JSON Server.
101+
Run `docker-compose up api`. Visit <http://localhost:9999/> to see your API.
102102

103103
### Docker cli
104104

@@ -107,18 +107,17 @@ docker run -d -p 9999:80 \
107107
-v ./my-db.js:/app/db.js \
108108
-v ./my-middleware.js:/app/middleware.json \
109109
-v ./my-routes.json:/app/routes.json \
110-
codfish/json-server:0.17.3 npm run dev
110+
codfish/json-server:0.17.3
111111
```
112112

113113
### Advanced
114114

115-
Set configuration
115+
Set configuration via environment variables.
116116

117117
```yaml
118118
services:
119119
json-server:
120120
image: codfish/json-server:0.17.3
121-
command: npm run dev
122121
volumes:
123122
- ./db.ts:/app/db.ts:delegated
124123
- ./middleware.ts:/app/middleware.ts:delegated
@@ -152,8 +151,6 @@ See all the [available options below](#options).
152151
- `/app/routes.json` - Custom
153152
[routes file](https://github.com/typicode/json-server#add-custom-routes).
154153
- `/public` - Static files directory.
155-
- Use `npm run dev` as the Docker `command` to enable hot reloading the server on any changes to
156-
mounted files.
157154

158155
## Database File
159156

@@ -291,19 +288,19 @@ upper snake-case (i.e. `--no-cors` -> `NO_CORS`).
291288

292289
`` = Custom option. Not an official `json-server` option.
293290

294-
| Option | Description | Default |
295-
| -------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
296-
| `MIDDLEWARES` | Path to middleware file | `middleware.js` (Stored in image, optionally mount over it or provide your own) |
297-
| `CONFIG` | Path to config file | Defers to `json-server` default |
298-
| `SNAPSHOTS` | Set snapshots directory | Defers to `json-server` default |
299-
| `ID` | Set database id property (e.g. `address`) | Defers to `json-server` default |
300-
| `FKS` | Set foreign key suffix, (e.g. `_id` as in `user_id`) | Defers to `json-server` default |
301-
| `DELAY` | Add delay to responses (ms) | — |
302-
| `STATIC` | Set static files directory | Defers to `json-server` default |
303-
| `QUIET` | Suppress log messages from output | Boolean flag only true if set to "true" |
304-
| `NO_GZIP` | Disable GZIP Content-Encoding | Boolean flag only true if set to "true" |
305-
| `NO_CORS` | Disable Cross-Origin Resource Sharing | Boolean flag only true if set to "true" |
306-
| `READ_ONLY` | Allow only GET requests | Boolean flag only true if set to "true" |
291+
| Option | Description | Default |
292+
| ---------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
293+
| `MIDDLEWARES` | Path to middleware file | `middleware.js` (Stored in image, optionally mount over it or provide your own) |
294+
| `CONFIG` | Path to config file | Defers to `json-server` default |
295+
| `SNAPSHOTS` | Set snapshots directory | Defers to `json-server` default |
296+
| `ID` | Set database id property (e.g. `address`) | Defers to `json-server` default |
297+
| `FKS` | Set foreign key suffix, (e.g. `_id` as in `user_id`) | Defers to `json-server` default |
298+
| `DELAY` | Add delay to responses (ms) | — |
299+
| `STATIC` | Set static files directory | Defers to `json-server` default |
300+
| `QUIET` | Suppress log messages from output | Boolean flag only true if set to "true" |
301+
| `NO_GZIP` | Disable GZIP Content-Encoding | Boolean flag only true if set to "true" |
302+
| `NO_CORS` | Disable Cross-Origin Resource Sharing | Boolean flag only true if set to "true" |
303+
| `READ_ONLY` | Allow only GET requests | Boolean flag only true if set to "true" |
307304
| ⋆ `DEPENDENCIES` | Install extra npm dependencies in the container for you to use in your server files. | — |
308305

309306
For details on the options

‎docker-compose.yml

-10
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@ version: '3'
33
services:
44
basic:
55
build: .
6-
command: npm run dev
7-
volumes:
8-
- ./db.js:/app/db.js
9-
- ./routes.json:/app/routes.json
10-
- ./middleware.js:/app/middleware.js:delegated
116
ports:
127
- 9999:80
138
environment:
149
VIRTUAL_HOST: json-server.docker
1510

1611
typescript:
1712
build: .
18-
command: npm run dev
1913
volumes:
2014
- ./examples/typescript/db.ts:/app/db.ts
2115
- ./examples/typescript/middleware.ts:/app/middleware.ts:delegated
@@ -26,7 +20,6 @@ services:
2620

2721
json-db:
2822
build: .
29-
command: npm run dev
3023
volumes:
3124
- ./examples/json/db.json:/app/db.json
3225
ports:
@@ -36,7 +29,6 @@ services:
3629

3730
middlewares:
3831
build: .
39-
command: npm run dev
4032
volumes:
4133
- ./examples/middlewares/db.json:/app/db.json
4234
- ./examples/middlewares/middleware_a.ts:/app/middleware_a.ts:delegated
@@ -49,7 +41,6 @@ services:
4941

5042
deps:
5143
build: .
52-
command: npm run dev
5344
volumes:
5445
- ./examples/deps/db.js:/app/db.js
5546
ports:
@@ -60,7 +51,6 @@ services:
6051

6152
dags:
6253
build: .
63-
command: npm run dev
6454
volumes:
6555
- ./examples/support-files/db.ts:/app/db.ts
6656
- ./examples/support-files/fixtures:/app/fixtures

‎main.sh

-42
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.