Support Docker Multistage target in render.yaml
Log In
r
robdimarco
Merged in a post:
Allow choosing Docker target
M
Matei Trandafir
Currently, the Docker options are:
- Dockerfile path
- Docker Build Context Directory
Then, the docker command executed is:
docker build "$DOCKER_CONTEXT_DIR" -f "$DOCKERFILE_PATH"
But when using multi-stage builds (https://docs.docker.com/build/building/multi-stage/) it is impossible to select the target image. All I want is an additional text field in service settings, named "Docker target build stage", and it would use this command:
docker build "$DOCKER_CONTEXT_DIR" -f "$DOCKERFILE_PATH" --target "$DOCKER_TARGET"
My use case: I have a complex gradle-based monorepo. There are a few Docker stages:
- base: copies everything over and runs gradle build
- frontend: copies relevant build output files from base stage and configures the frontend app
- backend: copies relevant build output files from base stage and configures the backend app
The current workaround is to have 2 separarate Dockerfiles, with the base stage duplicated.
A
Alexey Panteleev
Does Render's Docker use BuildKit?
>The legacy Docker Engine builder processes all stages of a Dockerfile leading up to the selected --target. It will build a stage even if the selected target doesn't depend on that stage.
>BuildKit only builds the stages that the target stage depends on.
We could leverage this BuildKit feature to optimize our builds for different services from the same monorepo and the same Dockerfile.
M
Mitchel Cabuloy
For anyone using multi-stage builds, one workaround for not being able to set a target is to ensure that your "production" stage is the last build stage in your Dockerfile.
For example:
# Base stage
FROM python:3.9 as base
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
RUN python manage.py collectstatic --noinput
# Development stage
FROM base as dev
ENV DJANGO_SETTINGS_MODULE=config.settings.dev
RUN pip install -r requirements-dev.txt
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# Production stage
FROM base as production
CMD ["gunicorn", "config.wsgi", "--bind", "0.0.0.0:8000"]