Skip to content

Commit 6438a47

Browse files
authored
Merge pull request #100 from codfish/upgrades
Bump to node v18.15 and json-server v0.17.3, migrate to new faker
2 parents 082113a + 65b32ca commit 6438a47

File tree

9 files changed

+10277
-25799
lines changed

9 files changed

+10277
-25799
lines changed

.github/workflows/release.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
publish-to-dockerhub:
11+
name: Push Docker image to Docker Hub
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out the repo
15+
uses: actions/checkout@v3
16+
17+
- name: Log in to Docker Hub
18+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
19+
with:
20+
username: ${{ secrets.DOCKERHUB_USERNAME }}
21+
password: ${{ secrets.DOCKERHUB_TOKEN }}
22+
23+
- name: Extract metadata (tags, labels) for Docker
24+
id: meta
25+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
26+
with:
27+
images: codfish/json-server
28+
29+
- name: Build and push Docker image
30+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
31+
with:
32+
context: .
33+
push: true
34+
tags: ${{ steps.meta.outputs.tags }}
35+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/validate.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v1
10+
- uses: actions/checkout@v3
1111

12-
- uses: actions/setup-node@v1
12+
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 12.x
14+
node-version-file: .nvmrc
1515

1616
- name: install dependencies
1717
run: npm ci

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.15.0

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM node:14.15-slim
1+
FROM node:18.15.0-slim
22

33
RUN mkdir /app
44
WORKDIR /app
55

6-
ENV JSON_SERVER_VERSION=0.16.3
6+
ENV JSON_SERVER_VERSION=0.17.3
77

88
RUN npm install -g json-server@${JSON_SERVER_VERSION}
99
COPY package.json package-lock.json ./

README.md

+16-20
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ cd json-server-docker
5151
docker-compose up -d
5252
```
5353

54-
I highly recommend installing [`dotdocker`](https://github.com/aj-may/dotdocker) first. The
55-
container will then be accessible at <http://json-server.docker>.
54+
Visit <http://localhost:9999/> to see your running JSON Server.
55+
56+
If you have [`dotdocker`](https://github.com/aj-may/dotdocker) installed the server will also be
57+
accessible at <http://json-server.docker>.
5658

5759
### Options
5860

@@ -109,22 +111,22 @@ services:
109111
## Database File
110112
111113
When building your mock api's you'll most like want to generate some fake data and return a number
112-
of items for a specific collection. I've included [Lodash](https://lodash.com/) &
113-
[faker.js](https://github.com/Marak/faker.js) in the image to help facilitate doing these sorts of
114-
things inside your source file, or middleware for that matter. Here's an example of what I mean:
114+
of items for a specific collection. [Faker](https://github.com/faker-js/faker) is included in the
115+
image to help facilitate doing these sorts of things inside your db or middleware files. For
116+
example:
115117
116118
```js
117-
const faker = require('faker');
118-
const times = require('lodash/times');
119-
const startCase = require('lodash/startCase');
119+
const faker = require('@faker-js/faker');
120120

121121
module.exports = () => ({
122-
posts: times(100, index => ({
123-
id: index,
124-
title: startCase(faker.lorem.words(3)),
125-
body: faker.lorem.paragraphs(3),
126-
// and so on...
127-
})),
122+
posts: faker.helpers.multiple(
123+
() => ({
124+
id: faker.datatype.uuid(),
125+
title: faker.lorem.words(3),
126+
body: faker.lorem.paragraphs(3),
127+
}),
128+
{ count: 100 },
129+
),
128130
});
129131
```
130132

@@ -159,9 +161,3 @@ feature change with our implementation but the `json-server` version doesn't cha
159161
```sh
160162
git tag -fa v0.16.1 -m "Update v0.16.1 tag" && git push origin v0.16.1 --force
161163
```
162-
163-
Docker Hub is configured to automatically build on new tags pushed to GitHub.
164-
165-
## Todo
166-
167-
- Add examples of using this with docker cli, without a compose file

db.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
const { faker } = require('@faker-js/faker');
2+
13
/**
24
* This is a the main database file. It's meant to be mounted over.
35
*/
46
module.exports = () => ({
5-
posts: [{ id: 10, title: 'json-server', author: 'typicode' }],
7+
posts: faker.helpers.multiple(
8+
() => ({
9+
id: faker.datatype.uuid(),
10+
title: faker.lorem.words(3),
11+
body: faker.lorem.paragraphs(3),
12+
}),
13+
{ count: 100 },
14+
),
615
comments: [{ id: 1, body: 'some comment', postId: 1 }],
716
profile: { name: 'typicode' },
817
});

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ services:
88
- ./db.js:/app/db.js
99
- ./routes.json:/app/routes.json:delegated
1010
- ./middleware.js:/app/middleware.js:delegated
11+
ports:
12+
- 9999:80
1113
environment:
1214
VIRTUAL_HOST: json-server.docker

0 commit comments

Comments
 (0)