Skip to content

Instantly share code, notes, and snippets.

pivot gRPC REST
payload size **protobuf**: smaller and binary **json**: bigger in size cuz text
underlying protocol http/2 http/1
comm bidirectional cuz http/2 and async one way - client to server only (no server push)
integration just call autogenerated methods use http clients and painstakingly create the request object manually
api spec protofiles and autogenerated code bug the backend dev, or hope for a swagger link and lastly trial and error
speed 20-25 times faster: less payload and less CPU to convert from binary format slow due to text based payloads and new connection for each request; no multi-plexing available
nginx:
build:
context: ./nginx
depends_on:
- app
ports:
- 80:80
FROM base as dev
WORKDIR /docker-react-nginx
# add node deps to path so that you don't have
# to do ./node_modules/.bin/something
ENV PATH=./node_modules/.bin:$PATH
CMD ["yarn", "start"]
version: '2.4'
services:
app:
build:
context: .
target: dev
expose:
- 3000
volumes:
process.on("SIGTERM", () => {
server.close(err => {
if (err) {
// if there's an error
// exit with a non-zero code
// which signifies failure
process.exit(1)
}
process.exit()
})
FROM gcr.io/distroless/nodejs as prod
USER nonroot
WORKDIR /docker-react-nginx
COPY --from=test --chown=nonroot:nonroot /docker-react-nginx/build .
CMD ["server.js"]
$ docker history docker-react
IMAGE CREATED CREATED BY SIZE COMMENT
13999baf2bca 6 minutes ago /bin/sh -c #(nop) CMD ["node" "server.js"] 0B
249865c763d2 6 minutes ago /bin/sh -c #(nop) COPY --chown=node:nodedir:… 2.29MB
4c42bb1ab0ee 8 minutes ago /bin/sh -c #(nop) WORKDIR /docker-react-nginx 0B
6bfe6580eb2f 8 minutes ago /bin/sh -c #(nop) USER node 0B
40af99c028bd 8 minutes ago /bin/sh -c mkdir -p /docker-react-nginx && c… 0B
5f9b3855deed 7 weeks ago /bin/sh -c #(nop) CMD ["node"] 0B
<missing> 7 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry… 0B
<missing> 7 weeks ago /bin/sh -c #(nop) COPY file:238737301d473041… 116B
$ docker build . -t docker-react
Sending build context to Docker daemon 1.333MB
Step 1/19 : FROM node:12-stretch-slim as base
---> 5f9b3855deed
Step 2/19 : FROM base as test
---> 5f9b3855deed
Step 3/19 : RUN mkdir -p /docker-react-nginx && chown -R node:node /docker-react-nginx
---> Running in cfca6e721a4e
Removing intermediate container cfca6e721a4e
---> 40af99c028bd
FROM node:12-stretch-slim as base
FROM base as test
# least privilege user
RUN mkdir -p /docker-react-nginx && chown -R node:node /docker-react-nginx
USER node
WORKDIR /docker-react-nginx
FROM node:12-stretch-slim as test
WORKDIR /docker-react-nginx
COPY package.json yarn.*lock ./
RUN yarn install --frozen-lockfile
COPY . .
# env CI as I'm using create react app