docker-react 0.0.4-2-github-actions.9 → 0.1.0-modernization-hotfix.0

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
@@ -93,10 +93,20 @@ CLI & base image to deploy React applications with docker containers.
93
93
  ```json
94
94
  {
95
95
  "dev": "npm run init-local && vite",
96
- "init-local": "npx docker-react prep -s ./env.schema.js -e local -d public"
96
+ "init-local": "npx docker-react prep -s ./env.schema.js -d public"
97
97
  }
98
98
  ```
99
99
 
100
+ Note if you are using a `.env` file the current recommended way is to use node directly.
101
+ ```json
102
+ {
103
+ "init-local": "node --env-file=.env ./node_modules/.bin/docker-react prep -s ./env.schema.js -d public"
104
+ }
105
+ ```
106
+
107
+ 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.
108
+ https://github.com/npm/cli/issues/7069
109
+
100
110
  7. Replace all references to environment variables with `window.env`, eg.
101
111
  - `process.env` => `window.env` (for create-react-app and others)
102
112
  - `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,17 +1,15 @@
1
1
  import path from 'path';
2
2
  import { promises as fs } from 'fs';
3
- import dotenv from 'dotenv';
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) {
@@ -25,14 +23,7 @@ function validateEnvironmentVariables(schema, environmentVariables) {
25
23
  }
26
24
  return joiResult.value;
27
25
  }
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
- }
26
+ async function generateEnvironmentFile(schemaPath, destinationPath) {
36
27
  // Perform environment variable validation.
37
28
  const schemaLocation = path.join(process.cwd(), schemaPath);
38
29
  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",
33
+ "commander": "^14.0.2",
35
34
  "joi": "^17.5.0"
36
35
  },
37
36
  "peerDependencies": {
38
37
  "joi": "^17.5.0"
39
38
  },
40
- "version": "0.0.4-2-github-actions.9"
39
+ "version": "0.1.0-modernization-hotfix.0"
41
40
  }