cli icon indicating copy to clipboard operation
cli copied to clipboard

Redundant Dockerfile required in order to push to correct repo

Open AvishayHirsh opened this issue 1 year ago • 3 comments

Using 0.58 version :

  1. Create devcontainer.json
{
  "image":"mcr.microsoft.com/devcontainers/base:ubuntu",
  "features": {
    "ghcr.io/devcontainers/features/node:1": {
      "version": "16.18.1"
    },
    "ghcr.io/devcontainers-contrib/features/bash-command:1": {
      "command": "pip3 install jinja2 PyYAML"
    }
  }
} 

  1. Build and try push to your repository :
devcontainer --log-level trace --workspace-folder . build --config devcontainer.json --image-name <YourCustomRepo>:<YourCustomTag>  --platform linux/arm64,linux/amd64 --push true

This Results with :


exporting to image:

ERROR: failed to solve: failed to push docker.io/library/vsc-base-image-360ebb83a1aa22c95928798ea8b92eedca9aac8ca2cc4a873ab7b5223cedfebd-features:latest: push access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed 

Expected: build is successfull and pushed to custom repo in registry. Actual: It seems to try push to ibrary/vsc-base-image instead of my repo, and fails

When i replace the image property with build to Dockerfile which has the image inside it, it just works :

{
  "build": {
    "dockerfile": "Dockerfile"
  },
  "features": {
    "ghcr.io/devcontainers/features/node:1": {
      "version": "16.18.1"
    },
    "ghcr.io/devcontainers-contrib/features/bash-command:1": {
      "command": "pip3 install jinja2 PyYAML"
    }
  }
}

Dockerfile :

FROM mcr.microsoft.com/devcontainers/base:ubuntu

it works and pushes to the custom repo as required.

AvishayHirsh avatar Apr 02 '24 15:04 AvishayHirsh

Hi 👋

Thanks for opening this issue, I was able to reproduce this as well.

Actual: It seems to try push to ibrary/vsc-base-image instead of my repo, and fails

When the dev container is built with an image property, it is pushing an incorrect image. This definitely looks like a bug. // cc @chrmarti

samruddhikhandale avatar Apr 04 '24 22:04 samruddhikhandale

@gauravsaini04 Can you help prioritize fixing this issue?

samruddhikhandale avatar Apr 04 '24 22:04 samruddhikhandale

@samruddhikhandale btw seems to be same as https://github.com/devcontainers/cli/issues/370

AvishayHirsh avatar Apr 07 '24 10:04 AvishayHirsh

Hi @samruddhikhandale ,

I have created a PR https://github.com/devcontainers/cli/pull/812 if user procide the --image-name then this specific name will be used to push the docker image with the build command. but if we do not pass the --image-name then it is using cli-generated-image to push to image and it is failing with the below error:

=> => writing image sha256:4b31a4eefdc45dbfb4b49f26827cdfabc25e8615f1bcd  0.0s
 => => naming to docker.io/library/vsc-example-push-ca34dc0eddd392c65ec66  0.0s
 => ERROR pushing vsc-example-push-ca34dc0eddd392c65ec666bc1f7466ba3bc47  12.5s
 => => pushing layer 7c0a0d09595d                                         11.7s
 => => pushing layer 243946f56500                                         11.7s
 => => pushing layer 9206b4b84489                                         11.7s
 => => pushing layer 5f70bf18a086                                         11.7s
 => => pushing layer 55ea4bb32210                                         11.7s
 => => pushing layer f29f4d95caff                                         11.7s
 => => pushing layer 4ea23d6daef7                                         11.7s
 => => pushing layer 751bee089a05                                         11.7s
 => => pushing layer 25998ae5ea08                                         11.7s
 => => pushing layer 71b7b5901bbd                                         11.7s
 => => pushing layer f8af91c37aab                                         11.7s
 => => pushing layer 5498e8c22f69                                         11.7s
------
 > pushing vsc-example-push-ca34dc0eddd392c65ec666bc1f7466ba3bc4760f9ef20a68674a2f9a7405218f-features with docker:
------
ERROR: unauthorized: access token has insufficient scopes
{
  "outcome": "error",
  "message": "Command failed: docker buildx build --platform linux/amd64 --push --build-context dev_containers_feature_content_source=/tmp/devcontainercli-node/container-features/0.59.1-1714115121385 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:ubuntu --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-example-push-ca34dc0eddd392c65ec666bc1f7466ba3bc4760f9ef20a68674a2f9a7405218f-features -f /tmp/devcontainercli-node/container-features/0.59.1-1714115121385/Dockerfile.extended /tmp/devcontainercli-node/empty-folder",
  "description": "An error occurred building the container."
}

prathameshzarkar9 avatar Apr 26 '24 07:04 prathameshzarkar9

Awesome, thanks @prathameshzarkar9! Reviewing the PR now.

if we do not pass the --image-name then it is using cli-generated-image to push to image and it is failing with the below error:

That's alright, anyone who wants to publish the image would have to make sure they have logged into the appropriate registries.

samruddhikhandale avatar Apr 26 '24 19:04 samruddhikhandale

Hi @samruddhikhandale , review comments addressed, kindly confirm and merge if the changes make sense.

prathameshzarkar9 avatar Apr 29 '24 03:04 prathameshzarkar9

Hi @samruddhikhandale ,

I have been addressed all the comments under this PR: https://github.com/devcontainers/cli/pull/812

Can you review and approve the same?

prathameshzarkar9 avatar May 22 '24 09:05 prathameshzarkar9

Closing as completed with https://github.com/devcontainers/cli/pull/812

samruddhikhandale avatar May 28 '24 23:05 samruddhikhandale