docker-react 0.0.4 → 0.1.0-modernization-hotfix.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Dockerfile ADDED
@@ -0,0 +1,23 @@
1
+ FROM node:24.11.1 as node
2
+
3
+ FROM nginx
4
+ ARG DOCKER_REACT_VERSION
5
+
6
+ # Grab and link the node binaries from the node image.
7
+ COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
8
+ COPY --from=node /usr/local/bin/node /usr/local/bin/node
9
+ RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
10
+ RUN ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
11
+
12
+ # Override default nginx config
13
+ COPY ./nginx.conf /etc/nginx/conf.d/default.conf
14
+
15
+ # Set working directory
16
+ WORKDIR /usr/app
17
+
18
+ # Install docker-react package globally
19
+ RUN npm install -g docker-react@"${DOCKER_REACT_VERSION}"
20
+ COPY ./node_modules ./node_modules
21
+
22
+ # Prepare startup script
23
+ COPY ./docker-react-entrypoint.sh /docker-entrypoint.d
package/README.md CHANGED
@@ -21,14 +21,11 @@ CLI & base image to deploy React applications with docker containers.
21
21
 
22
22
  ## Supported Tooling
23
23
 
24
- - [ ] Create React App
25
- - [x] Vite
26
- - [ ] React Static
24
+ - Vite
27
25
 
28
26
  ## Supported Validation
29
27
 
30
- - [x] Joi
31
- - [ ] Yup
28
+ - Zod
32
29
 
33
30
  ## Other TODOs
34
31
 
@@ -43,23 +40,23 @@ CLI & base image to deploy React applications with docker containers.
43
40
 
44
41
  ## Implementation Instructions
45
42
 
46
- 1. Install `docker-react` and `joi`
43
+ 1. Install `docker-react` and `zod` (zod version should match the peer dependency version exactly)
47
44
 
48
45
  ```sh
49
- npm i -S docker-react joi
46
+ npm i -S docker-react zod@4.1.12
50
47
  ```
51
48
 
52
- 2. Create environment variable schema (currently only Joi supported but the future others will be available)
49
+ 2. Create environment variable schema (currently only Zod supported but the future others will be available)
53
50
 
54
51
  ```js
55
52
  // env.schema.js
56
- const Joi = require('joi');
53
+ const { z } = require('zod');
57
54
 
58
- module.exports = Joi.object()
59
- .keys({
60
- VITE_API_URL: Joi.string().uri().required(),
61
- })
62
- .required();
55
+ const envSchema = z.object({
56
+ VITE_API_URL: z.string().uri().required(),
57
+ });
58
+
59
+ module.exports = envSchema;
63
60
  ```
64
61
 
65
62
  3. Add env import to your `index.html` head (in a future version this will be generated for you)
@@ -93,10 +90,20 @@ CLI & base image to deploy React applications with docker containers.
93
90
  ```json
94
91
  {
95
92
  "dev": "npm run init-local && vite",
96
- "init-local": "npx docker-react prep -s ./env.schema.js -e local -d public"
93
+ "init-local": "npx docker-react prep -s ./env.schema.js -d public"
97
94
  }
98
95
  ```
99
96
 
97
+ Note if you are using a `.env` file the current recommended way is to use node directly.
98
+ ```json
99
+ {
100
+ "init-local": "node --env-file=.env ./node_modules/.bin/docker-react prep -s ./env.schema.js -d public"
101
+ }
102
+ ```
103
+
104
+ There is a pending feature request for npx commands to support loading .env files directly, once it's implemented these docs will be updated accordingly.
105
+ https://github.com/npm/cli/issues/7069
106
+
100
107
  7. Replace all references to environment variables with `window.env`, eg.
101
108
  - `process.env` => `window.env` (for create-react-app and others)
102
109
  - `import.meta.env` => `window.env` (for vite)
package/dist/options.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export declare type Environment = 'local' | 'docker';
2
1
  export interface Options {
3
- environment: Environment;
4
2
  schema: string;
5
3
  destination: string;
6
4
  }
package/dist/prep.js CHANGED
@@ -1,38 +1,25 @@
1
- import path from 'path';
2
1
  import { promises as fs } from 'fs';
3
- import dotenv from 'dotenv';
2
+ import path from 'path';
4
3
  const ENVIRONMENT_DEFINITION_FILE_NAME = 'window.env.js';
5
4
  export function addPrepCommand(program) {
6
5
  return program
7
6
  .command('prep')
8
7
  .description('Prepare the application for serving')
9
- .option('-e, --environment [string]', 'The environment to run preparation over', 'docker')
10
8
  .option('-s, --schema [string]', 'The path to the schema file')
11
9
  .option('-d, --destination [string', 'The path to the destination')
12
10
  .action((options) => {
13
- const { environment, schema = './env.schema.js', destination = './', } = options;
14
- generateEnvironmentFile(environment, schema, destination);
11
+ const { schema = './env.schema.js', destination = './', } = options;
12
+ generateEnvironmentFile(schema, destination);
15
13
  });
16
14
  }
17
15
  function validateEnvironmentVariables(schema, environmentVariables) {
18
- const joiResult = schema.validate(environmentVariables, {
19
- allowUnknown: true,
20
- abortEarly: false,
21
- stripUnknown: true,
22
- });
23
- if (joiResult.error) {
24
- throw new Error(joiResult.error.message);
16
+ const zodResult = schema.safeParse(environmentVariables);
17
+ if (zodResult.error) {
18
+ throw new Error(zodResult.error.message);
25
19
  }
26
- return joiResult.value;
20
+ return zodResult.data;
27
21
  }
28
- async function generateEnvironmentFile(environment, schemaPath, destinationPath) {
29
- // For local environments attempt to load from `.env` files if available.
30
- if (environment === 'local') {
31
- const result = dotenv.config();
32
- if (result.error) {
33
- console.warn('Unable to load values from .env - all environment variables must be set', result.error);
34
- }
35
- }
22
+ async function generateEnvironmentFile(schemaPath, destinationPath) {
36
23
  // Perform environment variable validation.
37
24
  const schemaLocation = path.join(process.cwd(), schemaPath);
38
25
  console.log(`Attempting to load schema from ${schemaLocation}`);
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ docker-react prep -d ../share/nginx/html -s ./env.schema.js
package/nginx.conf ADDED
@@ -0,0 +1,19 @@
1
+ server {
2
+ listen 80;
3
+ server_name localhost;
4
+
5
+ root /usr/share/nginx/html;
6
+ index index.html;
7
+
8
+ location / {
9
+ # First attempt to serve request as file, then
10
+ # as directory, then fall back to redirecting to index.html
11
+ try_files $uri $uri/ $uri.html /index.html;
12
+ }
13
+
14
+ # redirect server error pages to the static page /50x.html
15
+ error_page 500 502 503 504 /50x.html;
16
+ location = /50x.html {
17
+ root /usr/share/nginx/html;
18
+ }
19
+ }
package/package.json CHANGED
@@ -26,16 +26,15 @@
26
26
  "homepage": "https://github.com/danielemery/docker-react#readme",
27
27
  "devDependencies": {
28
28
  "@danielemeryau/prettier-config": "^0.0.6",
29
- "@types/node": "^16.0.0",
30
- "typescript": "^4.5.4"
29
+ "@types/node": "^24.10.1",
30
+ "typescript": "^5.9.3"
31
31
  },
32
32
  "dependencies": {
33
- "commander": "^8.3.0",
34
- "dotenv": "^10.0.0",
35
- "joi": "^17.5.0"
33
+ "commander": "^14.0.2",
34
+ "zod": "4.1.12"
36
35
  },
37
36
  "peerDependencies": {
38
- "joi": "^17.5.0"
37
+ "zod": "4.1.12"
39
38
  },
40
- "version": "0.0.4"
39
+ "version": "0.1.0-modernization-hotfix.1"
41
40
  }