blitz-js / blitz-js/legacy-framework

Decrease the size of built Dockerfiles

Open
#19 1 comment 3 reactions 0 assignees View on GitHub
kind/bad-experience kind/bug legacy-framework status/ready-to-work-on
Dominant language
JavaScript
Stars
3
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### What do you want and why?

Thank you for your excellent project. I'm really stoked to see something like this gaining traction and I am keen to help out where I can. However, this issue goes beyond my skill as a speculative contributor -

As discussed in https://github.com/blitz-js/legacy-framework/issues/44, the Docker image when running the following multi-stage Dockerfile is roughly 600MB on a pretty conventional setup (Blitz, Material-UI, some AWS stuff).

`Dockerfile`
```dockerfile
# Install all node_modules and build the project
FROM mhart/alpine-node:14 as builder
WORKDIR /app

COPY package.json yarn.lock ./
RUN apk add --no-cache make gcc g++ python3 libtool autoconf automake
RUN yarn install --pure-lockfile

COPY . .
RUN NODE_ENV=production yarn blitz prisma generate && yarn build

# Install node_modules for production
FROM mhart/alpine-node:14 as production
WORKDIR /app

COPY package.json yarn.lock ./
RUN apk add --no-cache make gcc g++ python3 libtool autoconf automake
RUN NODE_ENV=production yarn install --frozen-lockfile --production

# Copy the above into a slim container
FROM mhart/alpine-node:slim-14
WORKDIR /app

COPY . .
COPY --from=production /app/node_modules ./node_modules
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/.blitz ./.blitz

EXPOSE 3000
#
# If possible, run your container using `docker run --init`
# Otherwise, you can use `tini`:
# RUN apk add --no-cache tini

# ENTRYPOINT ["/sbin/tini", "--"]

CMD ["/bin/sh", "./container-init.sh"]

```

`container-init.sh`
```bash
./node_modules/.bin/blitz prisma migrate deploy
./node_modules/.bin/blitz start
```

This causes problems during deploys, especially on Azure App Service, some deploys time out due to the size of the image.

### Possible implementation(s)

It seems that the main reason the resulting image is so large is due to the inclusion of the `blitz` dependency in the production dependencies tree in `package.json`. Ostensibly, this seems to be due to the `blitz start` command necessary to bring the solution up.

I did try and mess around with a lightweight init js file which tried to load the neccesary `server` components from the `blitz` package but it didn't work and I ran out of time.

Could a `blitz build` or similar yield a lightweight runtime file/package that allows for the system to be brought up without the burden of the entire `blitz` cli tool and all of its dependencies in the production image?

### Additional context
The production image contains references to the following node modules, which are not referenced anywhere in my own `package.json` and I don't believe are required in a production image for any application. I believe they are referenced by the `blitz` bin file, and are therefore in my production image.

```
jest-*
prisma (120mb+ !!)
typescript (60mb+)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.