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

BUG: Kubefile CMD can not get ENV values with ${VERSION} format #3853

Closed
willzhang opened this issue Sep 6, 2023 · 8 comments
Closed

BUG: Kubefile CMD can not get ENV values with ${VERSION} format #3853

willzhang opened this issue Sep 6, 2023 · 8 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@willzhang
Copy link
Contributor

willzhang commented Sep 6, 2023

Sealos Version

v4.3.3

How to reproduce the bug?

condition1:

when i use ${VERSION} in CMD

FROM scratch
ENV VERSION=v1.0
CMD ["echo VERSION=${VERSION}"]

CMD can not get ENV values

root@node1:~# sealos run registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
2023-09-06T16:33:32 info start to install app in this cluster
2023-09-06T16:33:32 info Executing SyncStatusAndCheck Pipeline in InstallProcessor
2023-09-06T16:33:32 info Executing ConfirmOverrideApps Pipeline in InstallProcessor
2023-09-06T16:33:32 info are you sure to override these following apps? 
registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
✔ Yes [y/yes], No [n/no]: y█
2023-09-06T16:33:34 info Executing PreProcess Pipeline in InstallProcessor
2023-09-06T16:33:34 info Executing pipeline MountRootfs in InstallProcessor.
2023-09-06T16:33:34 info Executing pipeline MirrorRegistry in InstallProcessor.
2023-09-06T16:33:34 info Executing UpgradeIfNeed Pipeline in InstallProcessor
VERSION=
2023-09-06T16:33:34 info succeeded install app in this cluster
2023-09-06T16:33:34 info no nodes that need to be scaled
2023-09-06T16:33:34 info 
      ___           ___           ___           ___       ___           ___
     /\  \         /\  \         /\  \         /\__\     /\  \         /\  \
    /::\  \       /::\  \       /::\  \       /:/  /    /::\  \       /::\  \
   /:/\ \  \     /:/\:\  \     /:/\:\  \     /:/  /    /:/\:\  \     /:/\ \  \
  _\:\~\ \  \   /::\~\:\  \   /::\~\:\  \   /:/  /    /:/  \:\  \   _\:\~\ \  \
 /\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/    /:/__/ \:\__\ /\ \:\ \ \__\
 \:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/  / \:\  \    \:\  \ /:/  / \:\ \:\ \/__/
  \:\ \:\__\    \:\ \:\__\        \::/  /   \:\  \    \:\  /:/  /   \:\ \:\__\
   \:\/:/  /     \:\ \/__/        /:/  /     \:\  \    \:\/:/  /     \:\/:/  /
    \::/  /       \:\__\         /:/  /       \:\__\    \::/  /       \::/  /
     \/__/         \/__/         \/__/         \/__/     \/__/         \/__/

                  Website: https://www.sealos.io/
                  Address: github.com/labring/sealos
                  Version: 4.3.3-d27f4fbc

condition2:

when i use $(VERSION) in CMD

FROM scratch
ENV VERSION=v1.0
CMD ["echo VERSION=$(VERSION)"]

CMD can get ENV values

root@node1:~# sealos run registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
2023-09-06T16:35:36 info start to install app in this cluster
2023-09-06T16:35:36 info Executing SyncStatusAndCheck Pipeline in InstallProcessor
2023-09-06T16:35:36 info Executing ConfirmOverrideApps Pipeline in InstallProcessor
2023-09-06T16:35:36 info are you sure to override these following apps? 
registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
Yes [y/yes], No [n/no]: y
2023-09-06T16:35:38 info Executing PreProcess Pipeline in InstallProcessor
2023-09-06T16:35:38 info Executing pipeline MountRootfs in InstallProcessor.
2023-09-06T16:35:38 info Executing pipeline MirrorRegistry in InstallProcessor.
2023-09-06T16:35:38 info Executing UpgradeIfNeed Pipeline in InstallProcessor
VERSION=v1.0
2023-09-06T16:35:38 info succeeded install app in this cluster
2023-09-06T16:35:38 info no nodes that need to be scaled
2023-09-06T16:35:38 info 
      ___           ___           ___           ___       ___           ___
     /\  \         /\  \         /\  \         /\__\     /\  \         /\  \
    /::\  \       /::\  \       /::\  \       /:/  /    /::\  \       /::\  \
   /:/\ \  \     /:/\:\  \     /:/\:\  \     /:/  /    /:/\:\  \     /:/\ \  \
  _\:\~\ \  \   /::\~\:\  \   /::\~\:\  \   /:/  /    /:/  \:\  \   _\:\~\ \  \
 /\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/    /:/__/ \:\__\ /\ \:\ \ \__\
 \:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/  / \:\  \    \:\  \ /:/  / \:\ \:\ \/__/
  \:\ \:\__\    \:\ \:\__\        \::/  /   \:\  \    \:\  /:/  /   \:\ \:\__\
   \:\/:/  /     \:\ \/__/        /:/  /     \:\  \    \:\/:/  /     \:\/:/  /
    \::/  /       \:\__\         /:/  /       \:\__\    \::/  /       \::/  /
     \/__/         \/__/         \/__/         \/__/     \/__/         \/__/

                  Website: https://www.sealos.io/
                  Address: github.com/labring/sealos
                  Version: 4.3.3-d27f4fbc

What is the expected behavior?

when i use ${VERSION} in CMD, i hope CMD can get ENV values.

What do you see instead?

when i use ${VERSION} in CMD, CMD can not get ENV values , i must use $(VERSION) format.

Operating environment

- Sealos version:
- Docker version:
- Kubernetes version:
- Operating system:
- Runtime environment:
- Cluster size:
- Additional information:

and It is work to use sealos run - e to pass variables in these two condition.

Additional information

related issue: Kubefile CMD not support Standard environment variable format

@willzhang willzhang added the kind/bug Something isn't working label Sep 6, 2023
@willzhang willzhang changed the title BUG: Kubefile CMD can not get ENV values BUG: Kubefile CMD can not get ENV values with ${VERSION} format Sep 6, 2023
@cuisongliu
Copy link
Collaborator

CMD ["echo VERSION=${VERSION}"] this type docker engine is not support. but $() is support .

I think this is not bug, is docker using spec.

@cuisongliu cuisongliu reopened this Sep 7, 2023
@cuisongliu
Copy link
Collaborator

image

@sealos-ci-robot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


image

@willzhang
Copy link
Contributor Author

willzhang commented Sep 7, 2023

not work

49c566cd96cd466f40c1e3a253c1792

76e162677966857170aeecdb1168e0f

sample dockerfile is ok

root@ubuntu:/data/dockerfile# ls
Dockerfile
root@ubuntu:/data/dockerfile# cat Dockerfile 
FROM alpine:latest

ENV MY_VARIABLE=default_value

CMD echo "The value of MY_VARIABLE is $MY_VARIABLE"


root@ubuntu:/data/dockerfile# docker run test
The value of MY_VARIABLE is default_value
root@ubuntu:/data/dockerfile# 

but Kubefile not work

root@ubuntu:/data/cluster-image/test# cat Kubefile 
FROM scratch

ENV MY_VARIABLE=default_value

CMD echo "The value of MY_VARIABLE is $MY_VARIABLE"


root@node1:~# sealos run registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
2023-09-07T10:48:22 info start to install app in this cluster
2023-09-07T10:48:22 info Executing SyncStatusAndCheck Pipeline in InstallProcessor
2023-09-07T10:48:22 info Executing ConfirmOverrideApps Pipeline in InstallProcessor
2023-09-07T10:48:22 info are you sure to override these following apps? 
✔ Yes [y/yes], No [n/no]: y█
2023-09-07T10:48:24 info Executing PreProcess Pipeline in InstallProcessor
2023-09-07T10:48:24 info Executing pipeline MountRootfs in InstallProcessor.
2023-09-07T10:48:24 info Executing pipeline MirrorRegistry in InstallProcessor.
2023-09-07T10:48:24 info Executing UpgradeIfNeed Pipeline in InstallProcessor
The value of MY_VARIABLE is 
2023-09-07T10:48:24 info succeeded install app in this cluster
2023-09-07T10:48:24 info no nodes that need to be scaled
2023-09-07T10:48:24 info 
      ___           ___           ___           ___       ___           ___
     /\  \         /\  \         /\  \         /\__\     /\  \         /\  \
    /::\  \       /::\  \       /::\  \       /:/  /    /::\  \       /::\  \
   /:/\ \  \     /:/\:\  \     /:/\:\  \     /:/  /    /:/\:\  \     /:/\ \  \
  _\:\~\ \  \   /::\~\:\  \   /::\~\:\  \   /:/  /    /:/  \:\  \   _\:\~\ \  \
 /\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/    /:/__/ \:\__\ /\ \:\ \ \__\
 \:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/  / \:\  \    \:\  \ /:/  / \:\ \:\ \/__/
  \:\ \:\__\    \:\ \:\__\        \::/  /   \:\  \    \:\  /:/  /   \:\ \:\__\
   \:\/:/  /     \:\ \/__/        /:/  /     \:\  \    \:\/:/  /     \:\/:/  /
    \::/  /       \:\__\         /:/  /       \:\__\    \::/  /       \::/  /
     \/__/         \/__/         \/__/         \/__/     \/__/         \/__/

                  Website: https://www.sealos.io/
                  Address: github.com/labring/sealos
                  Version: 4.3.3-d27f4fbc

docker inspect

root@ubuntu:/data/dockerfile# docker inspect test
[
    {
        "Id": "sha256:51ea13928bd78e82a4ba3940f88bd232e7e9d412fb23024c0af7005731de92f5",
        "RepoTags": [
            "test:latest"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2023-08-07T19:20:20.894140623Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "MY_VARIABLE=default_value"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "echo \"The value of MY_VARIABLE is $MY_VARIABLE\""
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 7335363,
        "VirtualSize": 7335363,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/220af1a94871cdee5df90d023df4ebbdb78e8f649f53c5f9461d48da181e8193/merged",
                "UpperDir": "/var/lib/docker/overlay2/220af1a94871cdee5df90d023df4ebbdb78e8f649f53c5f9461d48da181e8193/diff",
                "WorkDir": "/var/lib/docker/overlay2/220af1a94871cdee5df90d023df4ebbdb78e8f649f53c5f9461d48da181e8193/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:4693057ce2364720d39e57e85a5b8e0bd9ac3573716237736d6470ec5b7b7230"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

sealos inspect, the env and cmd are same as docker

root@ubuntu:/data/cluster-image/test# sealos inspect registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
{
    "Name": "registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0",
    "FromImageDigest": "sha256:5ed32ca869e745c89b532b4c73baf8e0b4cf6b97a815afd048afe5704f76c8d3",
    "FromImageID": "61249c2a2af99b0b5d209a33fda5adc9b5e74ac5a7fdc2160a8dc970cec9bb5d",
    "OCIv1": {
        "created": "2023-09-07T02:48:09.262424504Z",
        "architecture": "amd64",
        "os": "linux",
        "config": {
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "MY_VARIABLE=default_value"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "echo \"The value of MY_VARIABLE is $MY_VARIABLE\""
            ],
            "Labels": {
                "io.buildah.version": "1.30.0"
            }
        },
        "rootfs": {
            "type": "layers",
            "diff_ids": [
                "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
            ]
        },
        "history": [
            {
                "created": "2023-09-07T02:48:09.260320923Z",
                "created_by": "/bin/sh -c #(nop) ENV MY_VARIABLE=default_value",
                "empty_layer": true
            },
            {
                "created": "2023-09-07T02:48:09.263153537Z",
                "created_by": "/bin/sh -c #(nop) CMD echo \"The value of MY_VARIABLE is $MY_VARIABLE\""
            }
        ]
    }
}

@sealos-ci-robot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


not work

49c566cd96cd466f40c1e3a253c1792

76e162677966857170aeecdb1168e0f

@willzhang
Copy link
Contributor Author

willzhang commented Sep 7, 2023

$ sealos run test --debug
2023-09-07T10:53:22 info Executing ConfirmOverrideApps Pipeline in InstallProcessor
2023-09-07T10:53:22 info are you sure to override these following apps? 
registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
Yes [y/yes], No [n/no]: y
2023-09-07T10:53:31 info Executing PreProcess Pipeline in InstallProcessor
2023-09-07T10:53:31 debug images 61249c2a2af99b0b5d209a33fda5adc9b5e74ac5a7fdc2160a8dc970cec9bb5d are pulled
2023-09-07T10:53:31 debug parse reference 61249c2a2af99b0b5d209a33fda5adc9b5e74ac5a7fdc2160a8dc970cec9bb5d with transport containers-storage
2023-09-07T10:53:31 debug trying to override app registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
2023-09-07T10:53:31 debug Pull Policy for pull [missing]
2023-09-07T10:53:31 debug parse reference 61249c2a2af99b0b5d209a33fda5adc9b5e74ac5a7fdc2160a8dc970cec9bb5d with transport containers-storage
2023-09-07T10:53:31 info Executing pipeline MountRootfs in InstallProcessor.
2023-09-07T10:53:31 debug render env dir: /var/lib/containers/storage/overlay/cc40194b204cc46d67c29d469bc14529de9228a96f2944670f3de1a803f277d9/merged/etc
2023-09-07T10:53:31 debug render env dir: /var/lib/containers/storage/overlay/cc40194b204cc46d67c29d469bc14529de9228a96f2944670f3de1a803f277d9/merged/scripts
2023-09-07T10:53:31 debug render env dir: /var/lib/containers/storage/overlay/cc40194b204cc46d67c29d469bc14529de9228a96f2944670f3de1a803f277d9/merged/manifests
2023-09-07T10:53:31 debug send mount image, target: 192.168.72.40, image: registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0, type: application
2023-09-07T10:53:31 debug not trying to parse private key file cause it's not exists
2023-09-07T10:53:31 debug local 192.168.72.40 copy files src /var/lib/containers/storage/overlay/cc40194b204cc46d67c29d469bc14529de9228a96f2944670f3de1a803f277d9/merged to dst /var/lib/sealos/data/default/applications/default-f0ur1w4v/workdir
2023-09-07T10:53:31 info Executing pipeline MirrorRegistry in InstallProcessor.
2023-09-07T10:53:31 debug registry nodes is: [192.168.72.40]
2023-09-07T10:53:31 info Executing UpgradeIfNeed Pipeline in InstallProcessor
2023-09-07T10:53:31 debug not trying to parse private key file cause it's not exists
2023-09-07T10:53:31 debug start to run command `cd /var/lib/sealos/data/default/applications/default-f0ur1w4v/workdir && echo "The value of MY_VARIABLE is $MY_VARIABLE"` via exec
The value of MY_VARIABLE is 
2023-09-07T10:53:31 info succeeded install app in this cluster
2023-09-07T10:53:31 info no nodes that need to be scaled
......


  - cmd:
    - echo "The value of MY_VARIABLE is $MY_VARIABLE"
    env:
      MY_VARIABLE: default_value
    imageName: registry.cn-shenzhen.aliyuncs.com/cnmirror/test:v1.0
    labels:
      io.buildah.version: 1.30.0
    mountPoint: /var/lib/containers/storage/overlay/cc40194b204cc46d67c29d469bc14529de9228a96f2944670f3de1a803f277d9/merged
    name: default-f0ur1w4v
    type: application

@willzhang
Copy link
Contributor Author

willzhang commented Sep 7, 2023

I have been searching for a long time, but there is no documentation indicating that $(VARIABLE) is a dockerfile syntax. After testing, it has been found that native dockerfiles do not support this format.

I only find this ,it's for kubernetes

https://kubernetes.io/docs/tasks/inject-data-application/define-interdependent-environment-variables/

So where exactly does this format come from ?

@LZiHaN
Copy link
Contributor

LZiHaN commented Sep 8, 2023

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants