devcontainers / ci

A GitHub Action and Azure DevOps Task designed to simplify using Dev Containers (https://containers.dev) in CI/CD systems.
MIT License
333 stars 51 forks source link

Unable to prebuild devcontainer image (error command docker tag) #271

Open Defman opened 8 months ago

Defman commented 8 months ago

Error

Error: Dev container build failed: Command failed: docker tag example_devcontainer_app ghcr.io/example/example-devcontainer:latest (exit code: undefined)
An error occurred building the container. Error: Command failed: docker tag example_devcontainer_app ghcr.io/example/example-devcontainer:latest

The error only occurs when trying to push the image, the simplest setup without cacheFrom and push works like a charm.

Setup

.devcontainer/
├── devcontainer.json
├── docker-compose.yaml
└── Dockerfile
  build:
    name: Build
    runs-on: 16cores
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Pre-build dev container image
        uses: devcontainers/ci@v0.3
        with:
          imageName: ghcr.io/example/example-devcontainer
          cacheFrom: ghcr.io/example/example-devcontainer
          push: always
onedr0p commented 8 months ago

I have the same issue:

Dev container build failed: Command failed: docker tag vsc-flux-cluster-template-4e21694e9925a5c8755fd5fcba59eadc1f9d0c5b2a7d26a4ed5207ad79324fac-features ghcr.io/onedr0p/flux-cluster-template/devcontainer:latest (exit code: undefined)
jobs:
  publish-devcontainer:
    name: Publish devcontainer
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        with:
          platforms: linux/amd64 # ,linux/arm64

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: devcontainers/ci@v0.3
        with:
          imageName: ghcr.io/${{ github.repository }}/devcontainer
          cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
          imageTag: latest
          platform: linux/amd64 # ,linux/arm64
          configFile: .devcontainer/devcontainer.build.json
          push: always
onedr0p commented 8 months ago

Maybe a duplicate? https://github.com/devcontainers/ci/issues/191

chrmarti commented 7 months ago

Fixed in the Dev Containers CLI 0.57.0. The CI action will automatically pick up that version.

mintuhouse commented 4 months ago

This error still happens for me

About to run devcontainer build --workspace-folder /home/runner/work/rhythms/rhythms --config /home/runner/work/rhythms/rhythms/.devcontainer/mlai/devcontainer.json --image-name ghcr.io/GetRhythms/rhythms/rhythms-mlai-dev-mintuhouse/ruff:latest --cache-from ghcr.io/GetRhythms/rhythms/rhythms-mlai-dev-mintuhouse/ruff:latest --cache-from ghcr.io/GetRhythms/rhythms/rhythms-mlai-dev-main
  [2024-05-07T23:37:31.996Z] @devcontainers/cli 0.60.0. Node.js v18.20.2. linux 6.5.0-1018-azure x64.

Error: Dev container build failed: Command failed: docker tag mlai_mlai ghcr.io/GetRhythms/rhythms/rhythms-mlai-dev-mintuhouse/ruff:latest (exit code: undefined)

 devcontainer:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Pre-build dev container image
        uses: devcontainers/ci@v0.3
        env:
          BUILDX_NO_DEFAULT_ATTESTATIONS: true # https://github.com/devcontainers/ci/issues/191#issuecomment-1603857155
        with:
          configFile: .devcontainer/mlai/devcontainer.json
          cacheFrom: ghcr.io/${{ github.repository }}/rhythms-mlai-dev-main
          imageName: ghcr.io/${{ github.repository }}/rhythms-mlai-dev-${{github.ref_name}}
          # imageTag: ${{ env.IMAGE_TAG }}
          # platform: linux/amd64,linux/arm64
          skipContainerUserIdUpdate: true
chrmarti commented 4 months ago

Looking at the code, this might still occur when you are using a devcontainer.json with an image and no features or with a Docker Compose configuration.

@mintuhouse Could you append your devcontainer.json?

mintuhouse commented 4 months ago

We use docker compose

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
  "name": "ML AI (Rhythms)",
  "initializeCommand": "${localWorkspaceFolder}/.devcontainer/hostsetup",
  // Update the 'dockerComposeFile' list if you have more compose files or use different names.
  // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
  "dockerComposeFile": [
    "../../mlai/docker-compose.yml",
    "docker-compose.extend.yml"
  ],
  // The 'service' property is the name of the service for the container that VS Code should
  // use. Update this value and .devcontainer/docker-compose.yml to the real service name.
  "service": "mlai",
  // The optional 'workspaceFolder' property is the path VS Code should open by default when
  // connected. This is typically a file mount in .devcontainer/docker-compose.yml
  "workspaceFolder": "/workspaces/rhythms/mlai",
  // Features to add to the dev container. More info: https://containers.dev/features.
  "features": {
    // "azure-cli": "latest",
    "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
      "moby": true,
      "installDockerBuildx": true,
      "version": "latest",
      "dockerDashComposeVersion": "v2"
    },
    // "ghcr.io/devcontainers-contrib/features/actions-runner:1": {
    //  "version": "latest",
    //  "dotnetVersion": "latest"
    // },
    // "ghcr.io/devcontainers/features/github-cli:1": {
    //   "version": "latest"
    // },
    "ghcr.io/devcontainers-contrib/features/apt-get-packages:1": {
      "preserve_apt_list": false,
      "packages": "htop",
      "ppas": ""
    },
    "ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
      "plugins": "git git-extras git-prompt direnv",
      "omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions"
    },
    // "ghcr.io/devcontainers/features/dotnet:2": {},
    "ghcr.io/devcontainers-contrib/features/localtunnel-npm:1": {}
  },
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [],
  "otherPortsAttributes": {
    // Prevent auto-forwarding of ports
    "onAutoForward": "ignore"
  },
  // Uncomment the next line if you want start specific services in your Docker Compose config.
  // "runServices": [],
  // Uncomment the next line if you want to keep your containers running after VS Code shuts down.
  // "shutdownAction": "none",
  // Run commands after the container is created.
  "postCreateCommand": "/workspaces/rhythms/mlai/bin/devcontainer-setup",
  // Executes every time the container starts
  // "postStartCommand": "bash -i post-start.sh",
  // Configure tool-specific properties.
  "customizations": {
    // Configure properties specific to VS Code.
    "vscode": {
      "settings": {
        "terminal.integrated.defaultProfile.linux": "zsh",
        "terminal.integrated.profiles.linux": {
          "zsh": {
            "path": "/usr/bin/zsh"
          }
        }
      },
      // Add the IDs of extensions you want installed when the container is created.
      "extensions": [
        "streetsidesoftware.code-spell-checker",
        "bierner.github-markdown-preview",
        "ms-azuretools.vscode-docker",
        "eamodio.gitlens",
        "GitHub.copilot",
        "GitHub.vscode-pull-request-github",
        "esbenp.prettier-vscode",
        "foxundermoon.shell-format",
        "redhat.vscode-yaml",
        "github.vscode-github-actions",
        "Postman.postman-for-vscode",
        "yokawasa.jwt-debugger",
        "ms-python.python",
        "charliermarsh.ruff",
        "njpwerner.autodocstring",
        "tamasfe.even-better-toml",
        "ms-toolsai.jupyter",
        "ms-toolsai.datawrangler",
        "ms-toolsai.vscode-ai",
        "ms-toolsai.vscode-ai-remote",
        "ms-toolsai.vscode-jupyter-powertoys"
      ]
    }
  },
  // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
  // "remoteUser": "devcontainer"
  "remoteEnv": {
    "CI": "${localEnv:CI}",
    "PATH": "${containerEnv:PATH}:/some/other/path"
  }
}
tlgDJPorv commented 1 month ago

Our github org is in all caps, so using the expression ghcr.io/${{ github.repository }}/devcontainer for imageName is a no go.
Added a small step that lowercased the image name, and presto, now it works.
Just adding the comment here incase anyone else that googles their way to this issue might find it useful and save a couple of hours pulling their hair out :-).