Skip to content

variables not expanded with buildkit + too many build stages executed #484

@laur89

Description

@laur89

Attempting to trigger only specific intermediate build stages (step-two in our example), but arg DEFINED_IN_SECOND_STEP defined in intermediary step is not visible to our final stage, as witnessed by logged out "in final stage FINAL_ARG=[-extra-value]" message.

Additionally, both step-one & step-two stages are executed, that should not happen.

drone.yml:

kind: pipeline
type: docker
name: default

steps:
- name: publish-image
  image: plugins/docker
  settings:
    target: final
    build_args:
    - COMMON_STEP_VAR=common-step-value
    - OPTIONAL_STEP=two  # one | two
    dry_run: true
    debug: true

trigger:
  ref:
  - refs/heads/master
  - refs/heads/develop
  - refs/heads/feature/*
  - refs/tags/*

Dockerfile:

ARG OPTIONAL_STEP

FROM alpine:3 AS base

ARG COMMON_STEP_VAR=common-step-default
RUN echo "start, COMMON_STEP_VAR=[$COMMON_STEP_VAR]"

FROM base AS step-one
ARG DEFINED_IN_SECOND_STEP=step-one-${COMMON_STEP_VAR}
RUN echo "in stage one,  DEFINED_IN_SECOND_STEP=[$DEFINED_IN_SECOND_STEP]"


FROM base AS step-two
ARG DEFINED_IN_SECOND_STEP=step-two-${COMMON_STEP_VAR}
RUN echo "in stage two,  DEFINED_IN_SECOND_STEP=[$DEFINED_IN_SECOND_STEP]"


FROM step-${OPTIONAL_STEP} AS final
ARG FINAL_ARG=${DEFINED_IN_SECOND_STEP}-extra-value
RUN echo "in final stage  FINAL_ARG=[$FINAL_ARG]"

Running

$ docker build --rm=true -f Dockerfile -t deleteme . --pull=true \
    --build-arg COMMON_STEP_VAR=common-step-value \
    --build-arg OPTIONAL_STEP=two \
    --target final 

locally however logs out the expected

CACHED [final 1/1] RUN echo "in final stage FINAL_ARG=[step-two-common-step-value-extra-value]"

Also step-one is not executed as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions