Skip to content

Commit 435dc7f

Browse files
authored
Move off of Create-React-App (canada-ca#316)
A little while we made the jump from a custom webpack setup to Create React App. The move was prompted by html-webpack-plugin breaking some of the plugins we were using. With a little time behind us, the tradeoffs of this move have become a source of irritation. More control over linting (doing it in CI not just when we are running the app), custom config and direct control over more of our dependencies and build process are motivating factors in moving back to an updated custom setup.
1 parent 104a502 commit 435dc7f

40 files changed

Lines changed: 5032 additions & 7899 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
**/.DS_Store
22

33
platform/**/*.json
4-
frontend/build
4+
frontend/public
55
api/schema.json
66

77
**/node_modules

ci/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ FROM python:3.8-alpine
33
# Python, don't write bytecode!
44
ENV PYTHONDONTWRITEBYTECODE 1
55

6-
RUN apk add -U --no-cache openssl-dev libffi-dev build-base postgresql-libs postgresql-dev musl-dev python3 python3-dev
6+
RUN apk add -U --no-cache openssl-dev libffi-dev build-base postgresql-libs \
7+
postgresql-dev musl-dev python3 python3-dev nodejs-npm
78
RUN pip install pipenv

frontend/.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react",
5+
],
6+
"plugins": [
7+
"macros",
8+
"@babel/plugin-transform-runtime",
9+
"react-hot-loader/babel",
10+
]
11+
}

frontend/.dockerignore

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
*
2-
!build
3-
!lingui.config.js
4-
!package.json
5-
!package-lock.json
6-
!public
7-
!src
8-
!index.js
1+
**/__tests__
2+
cloudbuild.yaml
3+
docker-compose.yaml
4+
Dockerfile
5+
Dockerfile.dev
6+
envoy-dev.yaml
7+
LICENCE
8+
__mocks__
9+
node_modules
10+
README.md
11+
schema.faker.graphql
12+
.eslintrc
13+
.prettierrc

frontend/.eslintrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"extends": [
3+
"standard",
4+
"prettier",
5+
"plugin:react/recommended",
6+
"plugin:import/errors",
7+
"plugin:import/warnings"
8+
],
9+
"plugins": ["jest", "react-hooks"],
10+
"env": {
11+
"jest/globals": true
12+
},
13+
"rules": {
14+
"comma-dangle": ["error", "always-multiline"],
15+
"react-hooks/rules-of-hooks": "error",
16+
"react-hooks/exhaustive-deps": "warn",
17+
"no-unused-vars": [
18+
"error",
19+
{
20+
"vars": "all",
21+
"args": "all",
22+
"varsIgnorePattern": "_",
23+
"argsIgnorePattern": "_"
24+
}
25+
]
26+
},
27+
"settings": {
28+
"react": {
29+
"version": "detect"
30+
}
31+
}
32+
}

frontend/Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
# Node-gyp needs python 🤦
1+
# Node-gyp needs python 🤦 so our build image needs to include it
22
FROM python:alpine as build-env
33
RUN apk add -U npm gcc make g++
44
WORKDIR /app
5+
# Copy in whatever isn't filtered by .dockerignore
56
COPY . .
67

7-
RUN npm ci
8-
RUN npm run extract
9-
RUN npm run compile
10-
RUN npm run build
8+
# Install only what's needed for production
9+
# https://nodesecroadmap.fyi/chapter-1/threat-UIR.html
10+
RUN npm ci --production
1111

12+
# Base the production image on something slimmer
1213
FROM node:13-alpine
13-
LABEL maintainer="mike.williamson@cds-snc.ca"
14+
LABEL maintainer="mike.williamson@tbs-sct.gc.ca"
1415

1516
ENV HOST 0.0.0.0
1617
ENV PORT 3000
1718
ENV NODE_ENV production
1819

20+
# copy built app in
1921
COPY --from=build-env /app /app
2022
WORKDIR /app
2123

2224
USER node
2325
EXPOSE 3000
2426

25-
CMD ["index.js"]
27+
CMD ["npm", "start"]

frontend/cloudbuild.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
steps:
22

3-
- name: node:13-alpine
3+
- name: 'gcr.io/track-compliance/ci'
44
id: install
55
dir: frontend
66
entrypoint: npm
@@ -12,6 +12,24 @@ steps:
1212
entrypoint: npm
1313
args: ['test']
1414

15+
- name: node:13-alpine
16+
id: lingui-extract
17+
dir: frontend
18+
entrypoint: npm
19+
args: ['run', 'extract']
20+
21+
- name: node:13-alpine
22+
id: lingui-compile
23+
dir: frontend
24+
entrypoint: npm
25+
args: ['run', 'compile']
26+
27+
- name: node:13-alpine
28+
id: build-production-bundle
29+
dir: frontend
30+
entrypoint: npm
31+
args: ['run', 'build']
32+
1533
- name: 'gcr.io/cloud-builders/docker'
1634
id: build
1735
dir: frontend

frontend/docker-compose.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
version: "3.7"
22
services:
3-
envoy:
3+
envoy: # proxies localhost:3000 to containers based on rules in config
44
image: envoyproxy/envoy-alpine-dev
55
entrypoint: envoy
66
command: ["-c", "/etc/envoy-dev.yaml", "--service-cluster", "envoy"]
77
volumes:
8-
- ./envoy-dev.yaml:/etc/envoy-dev.yaml
8+
- ./envoy-dev.yaml:/etc/envoy-dev.yaml # Envoy configuration
99
expose:
10-
- "3000"
11-
- "3001"
10+
- "3000" # Forward to proxied apps
11+
- "3001" # Envoy admin page
1212
ports:
1313
- "3000:3000"
1414
- "3001:3001"
15-
frontend:
16-
stdin_open: true
15+
frontend: # localhost:3000/* is sent to frontend
1716
image: node:alpine
1817
working_dir: /app
19-
command: npm start
18+
command: npm run dev
2019
volumes:
2120
- ./:/app
2221
expose:
2322
- "3000"
24-
api:
23+
api: # available at localhost:3000/graphql
2524
image: apisguru/graphql-faker
2625
volumes:
2726
- ./schema.faker.graphql:/workdir/schema.faker.graphql

0 commit comments

Comments
 (0)