loft-sh / devpod

Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker.
https://devpod.sh
Mozilla Public License 2.0
8.67k stars 322 forks source link

The right way to build a workspace [kubernetes] #920

Closed solesensei closed 6 months ago

solesensei commented 7 months ago

Hey there! 👋

I'm currently setting up workspace builds.

  // .devcontainer.json
  "build": {
    "context": "..",
    "dockerfile": "../Dockerfile"
  },

Previously, I was able to use BUILD_REPOSITORY and BUILDKIT options to build (on kubernetes) and push an image to some image registry. This way, I could avoid rebuilding my workspace each time I launched it. However, it seems that now the only method available is to use the devpod build command and prebuild workspaces, but this approach is limited to the docker driver and my laptop, not the kubernetes.

So, my main question is: What's the current recommended approach for building and saving workspaces and is it possible to do so on Kubernetes?

pascalbreuninger commented 7 months ago

Hi @solesensei, we're now building the workspace directly in the pod instead of on the users machine like before, which is why there are no BuildKit options anymore. The new flow for this is using prebuilds, the piece you're missing in your setup is only step 1:

  1. Specify a prebuild customization in your devcontainer.json:

    ...
    "customizations": {
    "devpod": {
      "prebuildRepository": "ghcr.io/my-org/my-repo"
    }
    }
  2. Build the prebuild image locally or in a CI Pipeline devpod build github.com/my-org/my-repo --repository ghcr.io/my-org/my-repo

  3. Create the workspace using the kubernetes provider. If there is a prebuild match it'll prefer that over building from source

solesensei commented 7 months ago

Hi @pascalbreuninger, thanks for the clarification!

So if I understood correctly the point 2. there is no way to build&push on Kubernetes itself.

What kind of CI pipeline can you recommend? Do you mean Github Actions with some devpod action?

solesensei commented 7 months ago

As far as I remember buildkit can build your image on a temporary buildkit pod and then push it to the image registry. Are there any specific reasons why you have stopped supporting it?

I'm interested because I'm looking for remote image building solutions.

pascalbreuninger commented 7 months ago

As far as I remember buildkit can build your image on a temporary buildkit pod and then push it to the image registry. Are there any specific reasons why you have stopped supporting it?

Yes, we wanted to get rid of the requirement to have a registry configured. Now we use Kaniko to build and start in the same pod, without the necessity to push the image anywhere

As for

What kind of CI pipeline can you recommend? Do you mean Github Actions with some devpod action?

We were thinking about writing a github action to make that easier, generally any CI solution that supports docker should suffice. The basic steps there would be, for example triggered by changes to the .devcontainer folder:

  1. Install docker (depends on CI Provider)
  2. Login to docker registry docker login ghcr.io (or whatever you use)
  3. Download DevPod CLI curl -L -o devpod "https://github.com/loft-sh/devpod/releases/latest/download/devpod-linux-amd64" && sudo install -c -m 0755 devpod /usr/local/bin && rm -f devpod
  4. devpod provider add docker
  5. devpod build github.com/my-org/my-repo --repository ghcr.io/my-org/my-repo --provider docker