kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

default docker ARG values ignored when defined after a FROM declaration

Open SamStenton opened this issue 2 years ago • 0 comments

Actual behavior When making use of ARGs in a docker file with a default value, the variable default isn't evaluated if defined after a 'FROM' instruction.

Expected behavior Default variables to be evaluated no matter where they're put.

To Reproduce Steps to reproduce the behavior:

This doesn't work

ARG DOCKERFILE_NODE_BUILD_IMAGE_NAME=node
ARG DOCKERFILE_NODE_BUILD_IMAGE_VERSION=alpine

FROM ${DOCKERFILE_NODE_BUILD_IMAGE_NAME}:${DOCKERFILE_NODE_BUILD_IMAGE_VERSION} as node

ARG DOCKERFILE_NGINX_IMAGE_NAME=nginx
ARG DOCKERFILE_NGINX_IMAGE_VERSION=alpine
FROM ${DOCKERFILE_NGINX_IMAGE_NAME}:${DOCKERFILE_NGINX_IMAGE_VERSION} as nginx 

This does work when passing --build-arg DOCKERFILE_NGINX_IMAGE_NAME=otherimage --build-arg DOCKERFILE_NGINX_IMAGE_VERSION=otherversion

ARG DOCKERFILE_NODE_BUILD_IMAGE_NAME=node
ARG DOCKERFILE_NODE_BUILD_IMAGE_VERSION=alpine

FROM ${DOCKERFILE_NODE_BUILD_IMAGE_NAME}:${DOCKERFILE_NODE_BUILD_IMAGE_VERSION} as node

ARG DOCKERFILE_NGINX_IMAGE_NAME=nginx
ARG DOCKERFILE_NGINX_IMAGE_VERSION=alpine
FROM ${DOCKERFILE_NGINX_IMAGE_NAME}:${DOCKERFILE_NGINX_IMAGE_VERSION} as nginx 

This also works without needing to use --build-arg

ARG DOCKERFILE_NODE_BUILD_IMAGE_NAME=node
ARG DOCKERFILE_NODE_BUILD_IMAGE_VERSION=alpine
ARG DOCKERFILE_NGINX_IMAGE_NAME=nginx
ARG DOCKERFILE_NGINX_IMAGE_VERSION=alpine

FROM ${DOCKERFILE_NODE_BUILD_IMAGE_NAME}:${DOCKERFILE_NODE_BUILD_IMAGE_VERSION} as node

FROM ${DOCKERFILE_NGINX_IMAGE_NAME}:${DOCKERFILE_NGINX_IMAGE_VERSION} as nginx 

Additional Information

  • Running within VmWare Tanzu Kubernetes 1.22.6
  • Environment: Gitlab CI
  • Image: gcr.io/kaniko-project/executor:debug

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [ ]
Please check if the build works in docker but not in kaniko
  • - [ ]
Please check if this error is seen when you use --cache flag
  • - [ ]
Please check if your dockerfile is a multistage dockerfile
  • - [ ]

SamStenton avatar Aug 16 '22 14:08 SamStenton