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

Issue with hyphens in build args used in FROM #3

Open
sysadmiral opened this issue Sep 7, 2022 · 3 comments
Open

Issue with hyphens in build args used in FROM #3

sysadmiral opened this issue Sep 7, 2022 · 3 comments

Comments

@sysadmiral
Copy link

sysadmiral commented Sep 7, 2022

Hi thanks for a great tool.

I'm taking the Dockerfile and devcontainer.json from here.

The ARG for setting the ${VARIANT} contains a dash which seems to create a problem with the passing of command-line args in this script.

Here is the error I get:

docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.

and the debug output is:

Using workspace -v
[DEBUG] CONFIG_DIR: ./.devcontainer
[DEBUG] CONFIG_FILE: devcontainer.json
[DEBUG] CONFIG: 
{
        "name": "Node.js",
        "build": {
                "dockerfile": "Dockerfile",
                "args": { "VARIANT": "16-bullseye" }
        },

        "customizations": {
                "vscode": {
                        "extensions": [
                                "dbaeumer.vscode-eslint"
                        ]
                }
        },



        "remoteUser": "node"
}
[DEBUG] DOCKER_FILE: /home/amo_chumber/scratch/devcontainer-test/.devcontainer/Dockerfile
[DEBUG] REMOTE_USER: node
[DEBUG] ARGS: --build-arg VARIANT="16-bullseye"
[DEBUG] SHELL: null
[DEBUG] PORTS: 
[DEBUG] ENVS: 
[DEBUG] WORK_DIR: /workspace
[DEBUG] MOUNT:  --mount type=bind,source=-v,target=/workspace
Building and starting container
invalid reference format
[DEBUG] DOCKER_IMAGE_HASH: Sending build context to Docker daemon  4.096kB
Step 1/2 : ARG VARIANT=16-bullseye
Step 2/2 : FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.

I suspect this is a bash-ism with some quoting...

@sysadmiral sysadmiral changed the title Issue with hyphens in build args Issue with hyphens in build args used in FROM Sep 7, 2022
@sysadmiral
Copy link
Author

yeah definitely a bash-ism:

amo_chumber@cloudshell:~/scratch/devcontainer-test$ docker build -f .devcontainer/$(cat .devcontainer/devcontainer.json | grep -v // | jq -r '.build.dockerfile') $(cat .devcontainer/devcontainer.json | grep -v // | jq -r '.build.args | to_entries? | map("--build-arg \(.key)=\"\(.value)\"")? | join(" ")') .
Sending build context to Docker daemon  4.608kB
Step 1/2 : ARG VARIANT=16-bullseye
Step 2/2 : FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}
invalid reference format

vs

amo_chumber@cloudshell:~/scratch/devcontainer-test$ docker build -f .devcontainer/Dockerfile --build-arg VARIANT="16-bullseye" .
Sending build context to Docker daemon  4.608kB
Step 1/2 : ARG VARIANT=16-bullseye
Step 2/2 : FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}
 ---> f9bdb7d738da
Successfully built f9bdb7d738da

@sysadmiral
Copy link
Author

So changing line 57 to:

ARGS=$(echo $CONFIG | jq -r '.build.args | to_entries? | map("--build-arg \(.key)=\(.value)")? | join(" ")')

seems to resolve this but I'm not sure of the wider implications of removing the \" from around \(.value)...

@toddas90
Copy link

Changing line 57 didn't fix it for me. I had to manually go in and change it so that it wasn't using an argument. That does seem to be the issue though. Good job!

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

2 participants