jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.36k stars 196 forks source link

[Bug]: virtualenv printout does not respect `--quiet` flag #1632

Open justinTM opened 10 months ago

justinTM commented 10 months ago

Current Behavior (bug) Even with the --quiet flag in devbox run build --quiet, there is still stdout printing, which is messing up subsequent commands:

# devbox.json
# ... some stuff omitted
"scripts": {
    "build": [
        "branch=$(git rev-parse --abbrev-ref HEAD)",
        "account=$(aws sts get-caller-identity | jq -r .Account)",
        "ecr_registry=${account}.dkr.ecr.us-east-2.amazonaws.com",
        "tag=${ecr_registry}/${CI_PROJECT_NAME}:${branch}",
        "aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin $ecr_registry >&2",
        "docker build -t $tag . >&2",
        "echo \"\n${tag}\n\" >&2",
        "echo $tag"
    ],
},
$ my_image=$(devbox run build --quiet)
Ensuring packages are installed.
Using virtualenv: /Users/justin/git/gl/org/group/project/.venv
Login Succeeded
[+] Building 0.1s (11/11) FINISHED                                                                            
 => [internal] load build definition from Dockerfile                                                     0.0s
 => => transferring dockerfile: 977B                                                                     0.0s
 => [internal] load .dockerignore                                                                        0.0s
 => => transferring context: 2B                                                                          0.0s
 => [internal] load metadata for public.ecr.aws/lambda/python:3.11                                       0.0s
 => [build 1/6] FROM public.ecr.aws/lambda/python:3.11                                                   0.0s
 => [internal] load build context                                                                        0.0s
 => => transferring context: 68B                                                                         0.0s
 => CACHED [build 2/6] WORKDIR /build                                                                    0.0s
 => CACHED [build 3/6] RUN pip install --no-cache-dir poetry==1.6.1                                      0.0s
 => CACHED [build 4/6] COPY pyproject.toml poetry.lock ./                                                0.0s
 => CACHED [build 5/6] RUN touch README.md                                                               0.0s
 => CACHED [build 6/6] RUN --mount=type=cache,target=/tmp/poetry_cache poetry install --without dev --n  0.0s
 => exporting to image                                                                                   0.0s
 => => exporting layers                                                                                  0.0s
 => => writing image sha256:adde3655866e6ad7c4f1835be0f9bbd71fcc2e019f2945b666a8beeccc39e257             0.0s
 => => naming to ------------.dkr.ecr.us-east-2.amazonaws.com/------:------------      0.0s

------------.dkr.ecr.us-east-2.amazonaws.com/------:------------

awesome. okay now let's run the image as a container:

$ docker run -it $my_image /bin/bash
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.

oh?

$ docker image ls | head -2
REPOSITORY                                           TAG              IMAGE ID       CREATED          SIZE
------.dkr.ecr.us-east-2.amazonaws.com/----          TRZ-19--------   adde3655866e   14 minutes ago   962MB

I guess docker doesn't like capitalized JIRA ticket numbers in the tag?

$ echo "my_image=\"$my_image\""
my_image="Using virtualenv: /Users/justin/git/gl/org/group/project/.venv
------------.dkr.ecr.us-east-2.amazonaws.com/--------:TRZ-19--------"

oh my god 🤦‍♂️🤦‍♂️🤦‍♂️

Expected Behavior (fix) quiet means quiet. everything goes to stderr or nothing is printed at all.

Additional context Please include the output of devbox version -v and a copy of your devbox.json file.

justinTM commented 10 months ago

workaround is to query list of images, but this is fragile.

devbox run build && dive $(docker image ls -q | head -1)

justinTM commented 10 months ago

what's hilariously ridiculous too is devbox isn't even using the virtualenv python like it says:

$ (devbox) bash-3.2$ which python
/Users/justin/git/gl/org/group/project/.devbox/nix/profile/default/bin/python
(devbox) bash-3.2$ poetry env info

Virtualenv
Python:         3.11.5
Implementation: CPython
Path:           /Users/justin/git/gl/org/group/project/.venv
Executable:     /Users/justin/git/gl/org/group/project/.venv/bin/python
Valid:          True
justinTM commented 10 months ago

workaround for the above is to activate the virtual environment in devbox's shell initialization:

# devbox.json

"shell": {
    "init_hook": [
      "source parameters/dev.env",
      "source parameters/local.env",
      "export CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN",
      "aws sts get-caller-identity >& /dev/null || aws configure",
      "source $(poetry env info --path)/bin/activate"
    ],
Lagoja commented 10 months ago

Hey @justinTM, thanks for reporting this. We recently merged a PR that should provide a partial fix for this issue -- the output from the python+pip plugins will no longer push the messages to stdout, and instead will route them to stderr. This means the messages will still appear when running the script in your shell, but will not clutter up any files or tags that you are creating.

We're discussing a broader fix for the --quiet flag per your feedback as well

justinTM commented 9 months ago

sweet thanks for the update John!

been loving devbox! laptop got stolen in SF a week ago and it was painless to get up and running again