Devpod build fails when using Multi-Stage build with a Feature
What happened?
In my dev environment I use a multistage build, like this
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm AS builder
# ...
FROM builder AS final
# ...
I also have in my devcontainer.json a features clause to add node
"features": {
"ghcr.io/devcontainers/features/node:1": {
"installYarnUsingApt": true,
"version": "lts",
"nvmVersion": "latest"
}
},
When I try to start a workspace (debug on) it fails. this debug log indicates that an incorrect dockerfile is generated:
Note line 3 FROM AS final.
{"type":"data","data":{"time":"2024-11-29T11:14:54.363901867+09:00","message":"Creating extended Dockerfile /var/home/josh/.devpod/agent/contexts/default/workspaces/education-git-rc-2-0/content/.devcontainer/python/.devpod-internal/Dockerfile-with-features with content:
# syntax=docker.io/docker/dockerfile:1.4
ARG _DEV_CONTAINERS_BASE_IMAGE=placeholder
FROM AS final
FROM $_DEV_CONTAINERS_BASE_IMAGE AS dev_containers_target_stage
USER root
COPY ./.devpod-internal/ /tmp/build-features/
RUN chmod -R 0755 /tmp/build-features && ls /tmp/build-features
RUN \\
echo \"_CONTAINER_USER_HOME=$(getent passwd root | cut -d: -f6)\" >> /tmp/build-features/devcontainer-features.builtin.env && \\
echo \"_REMOTE_USER_HOME=$(getent passwd vscode | cut -d: -f6)\" >> /tmp/build-features/devcontainer-features.builtin.env
ENV NVM_DIR=/usr/local/share/nvm
ENV NVM_SYMLINK_CURRENT=true
ENV PATH=/usr/local/share/nvm/current/bin:${PATH}
RUN cd /tmp/build-features/0 \\
&& chmod +x ./devcontainer-features-install.sh \\
&& ./devcontainer-features-install.sh
ARG _DEV_CONTAINERS_IMAGE_USER=root
USER $_DEV_CONTAINERS_IMAGE_USER","level":"debug"}}
{"type":"data","data":{"time":"2024-11-29T11:14:54.365453753+09:00","message":"Creating docker-compose build /var/home/josh/.devpod/agent/contexts/default/workspaces/education-git-rc-2-0/.docker-compose/docker-compose.devcontainer.build-54.yml with content:
services:
django:
build:
context: /var/home/josh/.devpod/agent/contexts/default/workspaces/education-git-rc-2-0/content/.devcontainer/python
dockerfile: /var/home/josh/.devpod/agent/contexts/default/workspaces/education-git-rc-2-0/content/.devcontainer/python/.devpod-internal/Dockerfile-with-features
args:
_DEV_CONTAINERS_BASE_IMAGE: final
_DEV_CONTAINERS_IMAGE_USER: root
BUILDKIT_INLINE_CACHE: \"1\"","level":"debug"}}
What did you expect to happen instead?
Multistage builds work correctly with features. I tested
How can we reproduce the bug? (as minimally and precisely as possible)
- Create a multistage dockerfile
- Add a feature to a
devcontainer.jsonreferencing that dockerfile
My devcontainer.json:
{
"name": "Education",
"dockerComposeFile": ["../compose.yml"],
"service": "django",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"shutdownAction": "none",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff",
"Vue.volar",
"eamodio.gitlens",
"ms-python.vscode-pylance"
]
}
},
// Make npm features available in this python dev container
"features": {
"ghcr.io/devcontainers/features/node:1": {
"installYarnUsingApt": true,
"version": "lts",
"nvmVersion": "latest"
}
}
}
Local Environment:
- DevPod Version: 0.6.0
- Operating System: linux
- ARCH of the OS: AMD64
DevPod Provider:
- Local/remote provider: docker
Anything else we need to know?
As workarounds, commenting out features or removing the multistage build requirement both work.
Hey @joshbrooks, thanks for opening the issue. We'll look into it.
Just to get the complete picture here, could you also provide your compose.yml file please?