Skip to content

Instantly share code, notes, and snippets.

@renepardon
Created July 8, 2022 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renepardon/87dd2d523c3db7d2c392389c44e1e9d9 to your computer and use it in GitHub Desktop.
Save renepardon/87dd2d523c3db7d2c392389c44e1e9d9 to your computer and use it in GitHub Desktop.
Simple react application Docker image
#!/bin/bash
set -e
cat <<EOF >>/usr/share/nginx/html/__ENV.js
window.__ENV = {
"REACT_APP_PUBLIC_URL":"${REACT_APP_PUBLIC_URL:-''}",
"REACT_APP_ADMIN_URL":"${REACT_APP_ADMIN_URL:-'/admin'}",
"REACT_APP_API_BASE_URI":"${REACT_APP_API_BASE_URI:-'/api'}",
"REACT_APP_GRAPHQL_URI":"${REACT_APP_GRAPHQL_URI:-'/graphql'}",
"REACT_APP_UPLOAD_URI":"${REACT_APP_UPLOAD_URI:-'/files'}",
"REACT_APP_BROADCAST_URI":"${REACT_APP_BROADCAST_URI:-'/socket.io'}",
};
EOF
nginx -g "daemon off;"
FROM node:16-alpine3.16 as build
WORKDIR /app
COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock
RUN yarn install --silent
COPY . /app
RUN cp .env.build .env \
&& yarn react-env \
&& yarn build
FROM nginx:1.17
WORKDIR /usr/share/nginx/html
COPY --from=build /app/build /usr/share/nginx/html
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
COPY ./docker/docker-entrypoint.sh /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
RUN chmod +x /usr/local/bin/entrypoint.sh
server_tokens off;
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment