hi. does anybody know how to use multistage docker...
# 🌱|help-and-getting-started
r
Here is original attempt with
kapa
, but its even more confusing now: https://discord.com/channels/817392104711651328/1286475762114887680
main idea - for deploying use
scratch
image, while for testing regular. In some cases we do not want to have whole toolchain in container
normally for unit/integration testing we have some extra tools installed, while for e2e
scratch
image is way to go without any building testing/toolchain
c
Hi @refined-ghost-4478, I wrote a quick example to explain the idea. Let me know if this is what you are looking for. Essentially to do what you want to do, you have to create two actions, one for building the testing image (
dev
) and one for the production deploy (
prod
). In here I use a service called
frontend
as an example but it should be easy to port to your case. We then describe a Test action that uses the
dev
image, specified as output of the
dev
build action.
Copy code
kind: Build
name: frontend
type: container
description: Build the frontend image.

[...]

spec:
  dockerfile: frontend.dockerfile
  targetStage: prod

---
kind: Build
name: frontend-dev
type: container
description: Build the frontend image using the dev stage.

[...]

spec:
  dockerfile: frontend.dockerfile
  targetStage: dev

---

kind: Test
type: container
name: frontend-test

dependencies:
  - build.frontend-dev

spec:
  image: ${actions.build.frontend-dev.outputs.deploymentImageId}
  args: [npm, run, test]
I hope this helps!
And sorry about Kapa, it's of course not perfect. 🙂
r
yeah, I got idea. I should have different builds for each stage if plan to reference
c
Yes, I think that's the way to go. Let me know if that works! 😉
10 Views