Skip to content

Commit

Permalink
re-optimize node builds post prisma fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jyecusch committed May 22, 2023
1 parent 708df10 commit 99c3372
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/docker/distribution v2.7.1+incompatible
github.com/nitrictech/nitric/cloud/common v0.0.0-20230509232736-48f59463930d
github.com/olahol/melody v1.1.3
github.com/samber/lo v1.38.1
github.com/seaweedfs/seaweedfs v0.0.0-20230109022022-51d4a4b28d0e
go.etcd.io/bbolt v1.3.6
google.golang.org/protobuf v1.30.0
Expand Down Expand Up @@ -319,7 +320,6 @@ require (
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect
github.com/ryancurrah/gomodguard v1.3.0 // indirect
github.com/ryanrolds/sqlclosecheck v0.4.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
github.com/sashamelentyev/usestdlibvars v1.23.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/run/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/docker/docker/api/types/container"

"github.com/nitrictech/cli/pkg/containerengine"
"github.com/nitrictech/cli/pkg/project"
"github.com/nitrictech/cli/pkg/runtime"
Expand Down
39 changes: 22 additions & 17 deletions pkg/runtime/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ FROM node:alpine as build
ARG HANDLER
WORKDIR /usr/app
# Python and make are required by certain native package build processes in NPM packages.
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 make g++ && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add g++ make py3-pip
RUN yarn global add typescript @vercel/ncc
COPY . .
WORKDIR /usr/app
RUN yarn import || echo Lockfile already exists
COPY package.json *.lock *-lock.json /
RUN set -ex; yarn install --frozen-lockfile --cache-folder /tmp/.cache; rm -rf /tmp/.cache;
RUN yarn import || echo ""
RUN set -ex && \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache && \
rm -rf /tmp/.cache
RUN test -f tsconfig.json || echo "{\"compilerOptions\":{\"esModuleInterop\":true,\"target\":\"es2015\",\"moduleResolution\":\"node\"}}" > tsconfig.json
COPY . .
# make prisma external to bundle - https://github.com/prisma/prisma/issues/16901#issuecomment-1362940774 \
# TODO: remove when custom dockerfile support is available
RUN ncc build ${HANDLER} -o lib/ -e .prisma/client -e @prisma/client
RUN \
--mount=type=cache,target=/tmp/ncc-cache \
ncc build ${HANDLER} -o lib/ -e .prisma/client -e @prisma/client -t
FROM node:alpine as final
Expand All @@ -67,17 +70,19 @@ RUN apk update && \
apk add --no-cache ca-certificates && \
update-ca-certificates
COPY --from=build /usr/app/lib/ ./lib/
COPY package.json *.lock *-lock.json ./
RUN set -ex && \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache && \
rm -rf /tmp/.cache
COPY . .
RUN set -ex; \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache; \
rm -rf /tmp/.cache; \
# prisma fix for docker installs: https://github.com/prisma/docs/issues/4365
# TODO: remove when custom dockerfile support is available
test -d ./prisma && npx prisma generate || echo "";
COPY --from=build /usr/app/lib/ ./lib/
# prisma fix for docker installs: https://github.com/prisma/docs/issues/4365
# TODO: remove when custom dockerfile support is available
RUN test -d ./prisma && npx prisma generate || echo "";
ENTRYPOINT ["node", "lib/index.js"]`,
},
Expand Down
39 changes: 22 additions & 17 deletions pkg/runtime/typescript.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ FROM node:alpine as build

ARG HANDLER

WORKDIR /usr/app

# Python and make are required by certain native package build processes in NPM packages.
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 make g++ && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add g++ make py3-pip

RUN yarn global add typescript @vercel/ncc

COPY . .
WORKDIR /usr/app

COPY package.json *.lock *-lock.json /

RUN yarn import || echo Lockfile already exists
RUN yarn import || echo ""

RUN set -ex; yarn install --frozen-lockfile --cache-folder /tmp/.cache; rm -rf /tmp/.cache;
RUN set -ex && \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache && \
rm -rf /tmp/.cache

RUN test -f tsconfig.json || echo "{\"compilerOptions\":{\"esModuleInterop\":true,\"target\":\"es2015\",\"moduleResolution\":\"node\"}}" > tsconfig.json

COPY . .

# make prisma external to bundle - https://github.com/prisma/prisma/issues/16901#issuecomment-1362940774 \
# TODO: remove when custom dockerfile support is available
RUN ncc build ${HANDLER} -o lib/ -e .prisma/client -e @prisma/client
RUN \
--mount=type=cache,target=/tmp/ncc-cache \
ncc build ${HANDLER} -o lib/ -e .prisma/client -e @prisma/client -t

FROM node:alpine as final

Expand All @@ -33,16 +36,18 @@ RUN apk update && \
apk add --no-cache ca-certificates && \
update-ca-certificates

COPY --from=build /usr/app/lib/ ./lib/
COPY package.json *.lock *-lock.json ./

RUN set -ex && \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache && \
rm -rf /tmp/.cache

COPY . .

RUN set -ex; \
yarn install --production --frozen-lockfile --cache-folder /tmp/.cache; \
rm -rf /tmp/.cache; \
# prisma fix for docker installs: https://github.com/prisma/docs/issues/4365
# TODO: remove when custom dockerfile support is available
test -d ./prisma && npx prisma generate || echo "";
COPY --from=build /usr/app/lib/ ./lib/

# prisma fix for docker installs: https://github.com/prisma/docs/issues/4365
# TODO: remove when custom dockerfile support is available
RUN test -d ./prisma && npx prisma generate || echo "";

ENTRYPOINT ["node", "lib/index.js"]

0 comments on commit 99c3372

Please sign in to comment.