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(docker-metadata): INPUT_TAGS with list value is not working #356

Closed
mbagsik00 opened this issue Oct 7, 2021 · 6 comments
Closed

Comments

@mbagsik00
Copy link

Hi @gperdomor,

We noticed an issue when we have a list of value for the INPUT_TAGS that it only use the last value instead of tagging it multiple times. Here's an example value INPUT_TAGS="type=ref,event=branch,type=raw,value=v1.2.3" and the docker image only get tagged with v1.2.3. Although, adding multiple tags is working at the nx-docker executor.

We did look into the code and we noticed a difference between the getInputs from the nx-docker context.ts and docker-metadata context.ts.

nx-docker context.ts
tags: await getInputList('tags', options.tags),

docker-metadata context.ts
tags: getInputList('tags', options.tags, true).map((tag) => interpolate(tag)),

We tried to match it with the executor and test it by removing the parameter true which is the ignoreComma parameter of getInputList and that fixes the issue. Not sure if there's a reason we want to ignore comma in the docker-metadata. According to the documentation, that is how we list values.

Note: For list values use a comma-delimited string,
like INPUT_TAGS=user/app:v1,user/app:latest

Thanks! :)

@gperdomor
Copy link
Owner

Hi @mbagsik00... Which version of the plugin are using? Can you share the configuration of the docker builder? and an example of the env variables that are you using?

@mbagsik00
Copy link
Author

Hi @gperdomor,

Plugin version "@nx-tools/nx-docker": "^1.0.5"

docker builder configuration

                "build-image": {
                    "executor": "@nx-tools/nx-docker:build",
                    "options": {
                        "file": "build/dockerfiles/service/Dockerfile",
                        "push": false,
                        "load": true,
                        "platforms": ["linux/amd64"],
                        "meta": {
                            "enabled": true,
                            "images": [
                                "076854421720.dkr.ecr.us-east-1.amazonaws.com/test"
                            ],
                            "tags": [
                                "type=ref,event=branch",
                                "type=raw,value=v1.2.3"
                            ]
                        }
                }

Environment variable
INPUT_TAGS="\"type=ref,event=branch\",\"type=raw,value=v1\""

Tried without double quotes as well (INPUT_TAGS="type=ref,event=branch,type=raw,value=v1") but the same issue.
Although, only the above one enclosed in double-quotes works if we set the ignoreComma to false.

@gperdomor
Copy link
Owner

Sorry for the confusion, the problem is the same described here #350...

You need to execute this

INPUT_TAGS="type=ref,event=branch
type=raw,value=v1" nx run api:docker

Also, if you only need to change the tag version, you can use something like this:

"tags": [
    "type=ref,event=branch",
    "type=raw,value=$TAG_VERSION"
]

Then you can run TAG_VERSION=5.0.0 nx run api:docker, this is basically why you can see the interpolate call in the docker-metadata context, the metadata action needs this values to operate...

The nx-docker also run a final interpolation before run the docker build command

@mbagsik00
Copy link
Author

@gperdomor That one works! Thank you! Maybe we can update the documentation to say that we needed a new line. 😄

@gperdomor
Copy link
Owner

@mbagsik00 also, I have a new version of the plugin in alpha state 2.0.0-alpha.1, your feedback would be appreciated 🙏🏻

The new docs. To try the new version you need to change your config to

"build-image": {
    "executor": "@nx-tools/nx-docker:build",
    "options": {
        "file": "build/dockerfiles/service/Dockerfile",
        "push": false,
        "load": true,
        "platforms": ["linux/amd64"],
        "metadata": {
            "images": [
                "076854421720.dkr.ecr.us-east-1.amazonaws.com/test"
            ],
            "tags": [
                "type=ref,event=branch",
                "type=raw,value=v1.2.3"
            ]
        }
}

Resume, rename metato metadata, delete enabled=true option, this is no longer required, the metadata extraction is enabled when metadata.images is present... To use metadata also you need to install the @nx-tools/docker-metadata dependency since now is an optional dependency of @nx-tools/nx-docker

@gperdomor
Copy link
Owner

@gperdomor That one works! Thank you! Maybe we can update the documentation to say that we needed a new line. 😄

a new troubleshooting section was added.

I will close this issue now 😄

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