Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple build-args not resulting in correct docker build syntax #380

Closed
NonsenseSynapse opened this issue Jun 6, 2021 · 2 comments
Closed

Comments

@NonsenseSynapse
Copy link

Troubleshooting

Before sumbitting a bug report please read the Troubleshooting doc.

Behaviour

Steps to reproduce this issue

Using the following Dockerfile and Github Action:

Dockerfile

FROM alpine:3.7

ARG FIRST_ARG
RUN echo first arg: ${FIRST_ARG}

ARG SECOND_ARG
RUN echo second arg: ${SECOND_ARG}

Github Action

name: Build Test

on:
  workflow_dispatch:
jobs:
  build_and_publish:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Clone Github Repo
        uses: actions/checkout@master
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile
          push: true
          tags: nonsensesynapse/app:tag
          build-args:
            FIRST_ARG="First"
            SECOND_ARG="Second"

Expected behaviour

The correct docker syntax is to have a separate --build-arg for each argument.

docker build --progress=plain --build-arg FIRST_ARG="First" --build-arg SECOND_ARG="Second" - < Dockerfile

which gives me the following output:

#5 [2/3] RUN echo first arg: First
#5 sha256:398661483d922dc4c6b2cb85f72f84de0a8765d511cd2701aa496738019b5baf
#5 0.267 first arg: First
#5 DONE 0.3s

#6 [3/3] RUN echo second arg: Second
#6 sha256:379a45924550875394a9c34cf314ddc4ca9389b749d8205e6e6d36997773d21d
#6 0.331 second arg: Second
#6 DONE 0.4s

Source from docker documentation

$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 --build-arg FTP_PROXY=http://40.50.60.5:4567 .

Actual behaviour

When the action is run, the resulting docker build command is:

/usr/bin/docker buildx build --build-arg FIRST_ARG="First" SECOND_ARG="Second" --tag ***/app:tag --iidfile /tmp/docker-build-push-3G4tPQ/iidfile --file Dockerfile--push .

With the echos in the provided Dockerfile, we get the steps:

#6 [2/3] RUN echo first arg: "First" SECOND_ARG="Second"
#6 sha256:7e57fb6b5e7addf0b970c568b43b010d06ced5c85668930a1d4ea722307cfd72
#6 0.077 first arg: "First" SECOND_ARG="Second"
#6 DONE 0.1s

#7 [3/3] RUN echo second arg: ${SECOND_ARG}
#7 sha256:733bb9263ba53b14a8ab83e857b26039e2a78195d6382568f10074cfd6f5ea16
#7 0.072 second arg:
#7 DONE 0.1s

Syntax errors are thrown if you try to include the build-arg key more than once

build-args:
    FIRST_ARG="First"
build-args:
    SECOND_ARG="Second"

or if you pass in a list

build-args:
    - FIRST_ARG="First"
    - SECOND_ARG="Second"

Configuration

  • Repository URL (if public): private repo
  • Build URL (if public): private repo

Logs

Relevant log snippets included above.

@crazy-max
Copy link
Member

@NonsenseSynapse

As explained in the README, List type is a newline-delimited string:

build-args: |
    "FIRST_ARG=First"
    "SECOND_ARG=Second"

MrOrz added a commit to cofacts/rumors-line-bot that referenced this issue Jun 30, 2021
lapplislazuli added a commit to Tritlo/PropR that referenced this issue Jul 21, 2021
puria added a commit to dyne/fabchain that referenced this issue Jan 5, 2022
LukeWeidenwalker added a commit to Open-EO/openeo-processes-python that referenced this issue Jul 1, 2022
* add pyproject.toml

* update .gitignore to full  list from github/gitignore

* add poetry.lock to .gitignore

* add odc-algo dependency

* add github actions workflow

* minor cleanups to trigger workflow

* actually there is no debian GH runner :(

* attempt at installing gdal in ci

* remove extra python versions for now

* remove another cheeky sudo

* add sudo back in, seems necessary

* allow failrue for pytest to check rest of pipeline

* add name to test

* add devcontainer

* add python3-venv to devcontainer

* Correctly install the openeo_package

* fix venv location

* tests now work in devcontainer

* update tests with matrix strategy

* add mypy

* add mypy config

* add poetry.lock to check how much it speeds up build

* add gdal python dependency

* add older python versions for nox to docker image

* get rid of unnecessary stage

* add workflow for building devcontainer

* name and add workflow_dispatch trigger

* update image name to work on forks

* fix image name templating

* fix typo

* minor edit to test workflow trigger

* change devcontainer name

* merge pipelines

* add the latest tag

* fix using output of non-existant job

* fix docker tag lowercasing

* fix syntax error

* specify that we want to use ghcr.io cache!

* fix ghcr.io/ reference for tests job too

* try different cache-from config

* edit cache-to

* add login step to allow caching

* pull image if missing

* remove writing to cache in first step again

* explicitly pull image before

* also build with cache in tests

* output to local docker to be available to run

* mount GITHUB_WORKSPACE into devcontainer

* pass NOXSESSION into container too!

* Update README to new install

* fix user permissions issues

* add shebang to bashscript

* minor formatting

* try passing user id etc as build arg

* fix curly brackets

* ls statement for debugging permissions issue

* fix wrong syntax on COPY layer and get rid of 3.5 in image

* add a few debugging statements

* fix bracket type ..

* provide build args as strings (see docker/build-push-action#380 (comment))

* try other type of bracket

* try with manually set env variables

* provide as strings

* use =

* uff, need to do that in both places !

* remove debugging echo statements again

* add UID things to readme.

* Update readme with local docker build

* update README with additional instructions

* update devcontainer.json with intial settings

* Skip broken tests

* get_time_dimension_from_data: raise exception instead of returning None

* Ignore typing failures to get CI towards green

* add missing import for pyyaml

* update dependencies for pyyaml to resolve

* fix mypy failures

* update image build workflow to build the whole devcontainer

* change .venv location to in-project

* add $HOME/.local to path to get rid of pip warnings

* add another folder to path

* try username instead

* syntax fix

* set PATH after changing user

* mount files to correct dir

* add missing slash

* Skip failing test

* get rid of push step and use gha cache

* add load back in

* get rid of postCreateCommand

* Update readme to reflect latest changes

* change order in readme.

* change user to ubuntu

* remove remote user field, I misunderstood what this does

* add optional dependencies with extras

* Revert "add optional dependencies with extras"

This reverts commit b305423.
sfuhrm added a commit to sfuhrm/linux-python-docker that referenced this issue Apr 21, 2023
@michael-freidgeim-webjet

@crazy-max

As explained in the README, List type is a newline-delimited string:

build-args: |
    "FIRST_ARG=First"
    "SECOND_ARG=Second"

For me lines in double quotes didn't work, but error was shown

SECOND_ARG=Second command not found

Command without double quotes works

 build-args: |
     FIRST_ARG=First
     SECOND_ARG=Second

Remove quote was suggested by https://chatgpt.com/share/daf20a04-3975-44fe-8fac-4be89a2c5ece

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants