Multi-app with root build tasks
The information in this post is accurate as of the published date . Please make sure to check any linked documentation within the post for changes/updates.
Hi! I'm looking to host my project on Platform. Currently it is running on a Docker-based hosting.
The Dockerfile looks something like this:
# Builder
FROM node as builder
COPY . /app
RUN pnpm i && pnpm build
RUN pnpm deploy --filter "@project/backend" /tmp/.deploy/backend --prod
RUN pnpm deploy --filter "@project/frontend" /tmp/.deploy/frontend --prod
# Backend
FROM php as backend
COPY --from=builder /tmp/.deploy/backend /app
# Do additional backend tasks
# Frontend
FROM node as frontend
COPY --from=builder /tmp/.deploy/frontend /app
# Do additional frontend tasks
The system uses Docker BuildKit, so different containers use the same Dockerfile targeting relevant parts - backend or frontend.
The cool thing is that the Builder part is executed only once (it is cached by Docker). I wonder if it is possible to set it up the same way on Platform.
The actual project has more than two apps and also have several internal packages. They are all interlinked, so “pnpm build” makes sense only at the root level. Also, “pnpm build” takes quite some time, so it would be great to not re-run it for every app.
Is there a way to arrange this on Platform?
-
Hi Alexander. I've been experimenting with this recently, but I'm not sure. To start I would recommend:
# applications.yaml - name: frontend type: "nodejs:XX" build: flavor: none hooks: build: | pnpm i pnpm build deploy: | pnpm deploy --filter "@project/frontend" --prod ... - name: backend type: "php:XX" build: flavor: none hooks: build: | pnpm i pnpm build deploy: | pnpm deploy --filter "@project/backend" --prod ...
1. Both apps do go through the same build hook steps, which I know is not what you're looking to do. That said, our build system tracks changes to trees, so if (for example) after a longer initial build of both apps you pushed changes just to the frontend app, our platform is smart enough to only rebuild the frontend app (reusing the build image that has not changed for the backend).
2. What you can explore is the Build cache. Similar to what you have here there is a cache directory (
/.tmp
) that is accessible during and between builds. (Here is a gist leveraging it for installing node versions using nvm, and the variables docs for it). That could be a path to explore here. I will say that in my experiments I have found two things that might block you. First,PLATFORM_CACHE_DIR
is shared across all environments. It's not an unfixable problem, but you may need an identifier in place to say “this build belongs to this environment/state” if needed. Second,PLATFORM_CACHE_DIR
does not appear to be shared between applications. This is where I hit a speedbump in what I was trying to do recently, and the thing to experiment with on your specific problem.Hope this at least helps you get started, feel free to let me know how it goes.
Chad C.
0
Please sign in to leave a comment.
Comments
1 comment