Skip to content

Commit

Permalink
chore(#2514): change dockerfile for productionization (#9)
Browse files Browse the repository at this point in the history
* chore: change dockerfile for productionization

* chore: fix files
  • Loading branch information
kleyow authored Oct 12, 2021
1 parent be74d11 commit 0d1422b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
21 changes: 7 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
FROM node:lts-alpine as builder

WORKDIR /opt/reporting-hub-bop-shell
ENV PATH /opt/reporting-hub-bop-shell/node_modules/.bin:$PATH
WORKDIR /opt/reporting-hub-bop-role-ui
ENV PATH /opt/reporting-hub-bop-role-ui/node_modules/.bin:$PATH

RUN apk add --no-cache -t build-dependencies git make gcc g++ python libtool autoconf automake \
&& cd $(npm root -g)/npm \
&& npm config set unsafe-perm true \
&& npm install -g node-gyp

COPY package.json /opt/reporting-hub-bop-shell/
COPY yarn.lock /opt/reporting-hub-bop-shell/
COPY package.json /opt/reporting-hub-bop-role-ui/
COPY yarn.lock /opt/reporting-hub-bop-role-ui/

RUN yarn --frozen-lockfile

COPY ./ /opt/reporting-hub-bop-shell/
COPY ./ /opt/reporting-hub-bop-role-ui/

# Adds the package version and commit hash
ARG REACT_APP_NAME
Expand All @@ -25,19 +24,13 @@ ENV REACT_APP_VERSION=$REACT_APP_VERSION
ARG REACT_APP_COMMIT
ENV REACT_APP_COMMIT=$REACT_APP_COMMIT

# Public Path - Placeholder that is overwritten at runtime
ARG PUBLIC_PATH
ENV PUBLIC_PATH=__PUBLIC_PATH__

RUN yarn build

# Second part, create a config at boostrap via entrypoint and and serve it
FROM nginx:1.16.0-alpine
WORKDIR /usr/share/nginx/html

# JQ is used to convert from JSON string to json file in bash
RUN apk add --no-cache jq

COPY --from=builder /opt/reporting-hub-bop-shell/dist/ /usr/share/nginx/html
COPY --from=builder /opt/reporting-hub-bop-role-ui/dist/ /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf /etc/nginx/nginx.conf
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/start.sh /usr/share/nginx/start.sh
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
cache_from:
- mojaloop/reporting-hub-bop-role-ui
environment:
- PUBLIC_PATH=http://localhost:8081/
- REACT_APP_API_BASE_URL=http://localhost:3008/
- REACT_APP_MOCK_API=false
ports:
Expand Down
4 changes: 0 additions & 4 deletions docker/loadRuntimeConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
sed -i 's#__REACT_APP_API_BASE_URL__#'"$REACT_APP_API_BASE_URL"'#g' /usr/share/nginx/html/runtime-env.js
sed -i 's#__REACT_APP_MOCK_API__#'"$REACT_APP_MOCK_API"'#g' /usr/share/nginx/html/runtime-env.js

sed -i 's#__PUBLIC_PATH__#'"$PUBLIC_PATH"'#g' /usr/share/nginx/html/index.html
sed -i 's#__PUBLIC_PATH__#'"$PUBLIC_PATH"'#g' /usr/share/nginx/html/main.js
sed -i 's#__PUBLIC_PATH__#'"$PUBLIC_PATH"'#g' /usr/share/nginx/html/app.js

exec "$@"
9 changes: 5 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ require('dotenv').config({
path: './.env',
});

const { DEV_PORT, VERCEL_URL, PUBLIC_PATH, ROLE_API_URL } = process.env;
const { DEV_PORT } = process.env;

const config = {
DEV_PORT,
PUBLIC_PATH: VERCEL_URL ? `https://${VERCEL_URL}/` : PUBLIC_PATH,
ROLE_API_URL,
};

const { ModuleFederationPlugin } = webpack.container;
Expand Down Expand Up @@ -52,7 +50,10 @@ module.exports = {
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: config.PUBLIC_PATH, // Where it's going to be expected to be published for being externally loaded
// It automatically determines the public path from either
// `import.meta.url`, `document.currentScript`, `<script />`
// or `self.location`.
publicPath: 'auto',
},
resolve: {
alias: {
Expand Down

0 comments on commit 0d1422b

Please sign in to comment.