Skip to content

Commit

Permalink
Merge pull request #102 from codfish/cli-to-module-migration
Browse files Browse the repository at this point in the history
feat: bash -> node/zx, bump node to v20.9
  • Loading branch information
codfish authored Oct 28, 2023
2 parents df08012 + 02fd13a commit 286ac9d
Show file tree
Hide file tree
Showing 13 changed files with 1,889 additions and 2,371 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v5
with:
images: codfish/json-server

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,33 @@ jobs:
- name: lint js
run: npm run lint

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: codfish/json-server

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: codfish/json-server

- name: Build and push
uses: docker/build-push-action@v4
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 PR build published. Run \`docker run -p 9999:80 codfish/json-server@${{ steps.build.outputs.digest }}\``
})
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,4 @@ typings/
# DynamoDB Local files
.dynamodb/

# Custom
dist
build
api
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.2.0
v20.9.0
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
FROM node:20.2.0-slim
FROM node:20.9.0-slim

RUN mkdir /app
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci --omit=dev
RUN npm install -g --save-exact [email protected] [email protected]
RUN npm install -g --save-exact [email protected]

# copy in files
COPY ./tsconfig.json \
./db.js \
./middleware.js \
./routes.json \
./server.sh \
./main.sh ./
./server.mjs ./

EXPOSE 80

CMD [ "./main.sh" ]
ENTRYPOINT [ "nodemon", "server.mjs" ]
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# json-server-docker

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

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

## Getting Started

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

### Docker cli

Expand All @@ -107,18 +107,17 @@ docker run -d -p 9999:80 \
-v ./my-db.js:/app/db.js \
-v ./my-middleware.js:/app/middleware.json \
-v ./my-routes.json:/app/routes.json \
codfish/json-server:0.17.3 npm run dev
codfish/json-server:0.17.3
```

### Advanced

Set configuration
Set configuration via environment variables.

```yaml
services:
json-server:
image: codfish/json-server:0.17.3
command: npm run dev
volumes:
- ./db.ts:/app/db.ts:delegated
- ./middleware.ts:/app/middleware.ts:delegated
Expand Down Expand Up @@ -152,8 +151,6 @@ See all the [available options below](#options).
- `/app/routes.json` - Custom
[routes file](https://github.com/typicode/json-server#add-custom-routes).
- `/public` - Static files directory.
- Use `npm run dev` as the Docker `command` to enable hot reloading the server on any changes to
mounted files.

## Database File

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

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

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

For details on the options
Expand Down
10 changes: 0 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ version: '3'
services:
basic:
build: .
command: npm run dev
volumes:
- ./db.js:/app/db.js
- ./routes.json:/app/routes.json
- ./middleware.js:/app/middleware.js:delegated
ports:
- 9999:80
environment:
VIRTUAL_HOST: json-server.docker

typescript:
build: .
command: npm run dev
volumes:
- ./examples/typescript/db.ts:/app/db.ts
- ./examples/typescript/middleware.ts:/app/middleware.ts:delegated
Expand All @@ -26,7 +20,6 @@ services:

json-db:
build: .
command: npm run dev
volumes:
- ./examples/json/db.json:/app/db.json
ports:
Expand All @@ -36,7 +29,6 @@ services:

middlewares:
build: .
command: npm run dev
volumes:
- ./examples/middlewares/db.json:/app/db.json
- ./examples/middlewares/middleware_a.ts:/app/middleware_a.ts:delegated
Expand All @@ -49,7 +41,6 @@ services:

deps:
build: .
command: npm run dev
volumes:
- ./examples/deps/db.js:/app/db.js
ports:
Expand All @@ -60,7 +51,6 @@ services:

dags:
build: .
command: npm run dev
volumes:
- ./examples/support-files/db.ts:/app/db.ts
- ./examples/support-files/fixtures:/app/fixtures
Expand Down
42 changes: 0 additions & 42 deletions main.sh

This file was deleted.

Loading

0 comments on commit 286ac9d

Please sign in to comment.