Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
96a1262
feat: Time for devcontainers!
sunib Oct 1, 2025
2e42e09
fix: Get docker also in the dev container so that we can run the e2e …
sunib Oct 1, 2025
32e643a
fix: Linting should be fast and off course we want host networking.
sunib Oct 1, 2025
fcf1789
fix: Does this solve it?
sunib Oct 1, 2025
4d8baed
Does this work?
sunib Oct 1, 2025
77520d1
fix: Let's start with a fresh new tab
sunib Oct 1, 2025
70417f6
Cleaning up! It now works locally at least
sunib Oct 1, 2025
dfac6a3
Also doing the kubectl setup in case of a new devcontainer
sunib Oct 1, 2025
e95eee4
Please let this be the fix
sunib Oct 1, 2025
4f6e7f5
Let's try this then
sunib Oct 1, 2025
8e422c0
Let's do this then
sunib Oct 1, 2025
e0b3407
This should speed up the linting step
sunib Oct 1, 2025
3995104
Let's get this show on the road
sunib Oct 1, 2025
040a180
Let's try
sunib Oct 1, 2025
96ff6c2
Well I'm curious
sunib Oct 1, 2025
938a36c
Let's try it like this then
sunib Oct 1, 2025
89c4e6e
feat: Let's move back to a more worker based approach, no docker-in-d…
sunib Oct 2, 2025
27a7e40
fix: Let's see if this turns green now
sunib Oct 2, 2025
3a0f816
fix: Make the build local for dev containers
sunib Oct 2, 2025
bc4f03f
Let's see
sunib Oct 2, 2025
0d1666e
Cleaning up and tweaking
sunib Oct 2, 2025
9870d62
chore: Let's see if we can get the linting faster
sunib Oct 2, 2025
3e291b8
Would this be better?
sunib Oct 2, 2025
01948d3
Increased liniting requirements (the 20 dollar refactor wow)
sunib Oct 2, 2025
d2f6346
fix: Hopefully now validating the Dev Container
sunib Oct 2, 2025
50c704d
Experiment on linting speed.
sunib Oct 2, 2025
e306f4c
Let's accept it: and let's put them in parallel for now.
sunib Oct 2, 2025
e0dc14d
fix: Allow running tests as well (and init inside docker)
sunib Oct 2, 2025
40b90e7
Hopefully fixing it
sunib Oct 2, 2025
f10a51f
Let's put it back please
sunib Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Development container with all tools pre-installed including Docker and Kind
# Extends the CI base image with Docker support for local development
# This is NOT for production - see root Dockerfile for that
# For local dev: builds CI base from local Dockerfile.ci
# For CI: uses pre-built image from GHCR
ARG CI_BASE_IMAGE=ci-base-local
FROM ${CI_BASE_IMAGE} AS ci-base

# Switch to noninteractive for Docker installation
ENV DEBIAN_FRONTEND=noninteractive

# Install Docker (for local development and Kind cluster management)
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
apt-transport-https \
gnupg \
lsb-release \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \
&& chmod a+r /etc/apt/keyrings/docker.asc \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt-get update \
&& apt-get -y install --no-install-recommends \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install Kind (for local Kubernetes clusters)
ENV KIND_VERSION=v0.30.0
RUN curl -Lo /usr/local/bin/kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64 \
&& chmod +x /usr/local/bin/kind

# Verify Docker and Kind installations
RUN echo "=== Additional Dev Tools ===" \
&& kind version \
&& docker --version

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

# Default command
CMD ["/bin/bash"]
83 changes: 83 additions & 0 deletions .devcontainer/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# CI-focused base image with essential build tools
# This is used in CI pipelines and as base for the full dev container
FROM golang:1.25.1-bookworm

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Install essential packages (no Docker)
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
git \
curl \
ca-certificates \
vim \
less \
jq \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Tool versions - centralized for easy updates
ENV KUBECTL_VERSION=v1.32.3 \
KUSTOMIZE_VERSION=5.7.1 \
KUBEBUILDER_VERSION=4.4.0 \
GOLANGCI_LINT_VERSION=v2.5.0 \
HELM_VERSION=v3.12.3

# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" \
&& chmod +x kubectl \
&& mv kubectl /usr/local/bin/

# Install Kustomize
RUN curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s ${KUSTOMIZE_VERSION} /usr/local/bin/

# Install Kubebuilder
RUN curl -L -o /usr/local/bin/kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_linux_amd64" \
&& chmod +x /usr/local/bin/kubebuilder

# Install Helm
RUN curl -fsSL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz \
| tar -xzO linux-amd64/helm > /usr/local/bin/helm \
&& chmod +x /usr/local/bin/helm

# Install golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}

# Set working directory
WORKDIR /workspace

# Install Go tools used by the project (using @version doesn't need go.mod)
RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0 \
&& go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

# Initialize golangci-lint cache by running it once on an empty directory
# This downloads linter dependencies without needing source code
RUN mkdir -p /tmp/golangci-init && cd /tmp/golangci-init \
&& go mod init example.com/init \
&& echo 'package main\n\nfunc main() {}' > main.go \
&& golangci-lint run --timeout=5m || true \
&& cd / && rm -rf /tmp/golangci-init

# Pre-download Go modules for caching - placed AFTER tool installation
# This layer will be cached and only rebuilt when go.mod/go.sum changes
# Moving this down prevents tool reinstallation when dependencies change
COPY go.mod go.sum ./
RUN go mod download

# Verify installations
RUN echo "=== Tool Versions ===" \
&& go version \
&& kubectl version --client \
&& kustomize version \
&& (kubebuilder version || echo "Kubebuilder: not available (optional)") \
&& helm version \
&& golangci-lint version

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

# Default command
CMD ["/bin/bash"]
49 changes: 49 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Development Container

Quick-start development environment with all tools pre-installed.

## Quick Start

### VS Code
1. Install [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
2. Open project in VS Code: `code .`
3. Press `F1` → `Dev Containers: Reopen in Container`
4. Wait for initial build (~5-10 min first time)

### Verify
```bash
go version # 1.25.1
kind version # v0.30.0
kubectl version # v1.32.3
golangci-lint version # v2.4.0
```

### Run Tests
```bash
make test # Unit tests
make lint # Linting
make test-e2e # E2E tests (creates Kind cluster)
```

## Architecture

Two containers:
- **`Dockerfile.ci`** - CI base (Go tools, no Docker) - Used in GitHub Actions
- **`Dockerfile`** - Full dev (extends CI base, adds Docker+Kind) - Local only

Local dev builds CI base automatically (`initializeCommand`), no GHCR pulls needed.

## Files

- `Dockerfile.ci` - CI base container
- `Dockerfile` - Full dev container
- `devcontainer.json` - VS Code configuration
- `README.md` - This file

## Troubleshooting

**Container won't build** → Ensure Docker is running
**E2E tests fail** → Check `docker info` works
**Slow rebuild** → Normal, only rebuilds when tools/deps change

See [`docs/COMPLETE_SOLUTION.md`](../docs/COMPLETE_SOLUTION.md) for details.
36 changes: 29 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.25.1",
"name": "GitOps Reverser DevContainer",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"CI_BASE_IMAGE": "ci-base-local"
},
"target": ""
},
"initializeCommand": "cd .devcontainer && docker build -f Dockerfile.ci -t ci-base-local ..",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": false,
"dockerDashComposeVersion": "v2"
}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
"terminal.integrated.shell.linux": "/bin/bash",
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go"
},
"extensions": [
"golang.go",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"kilocode.kilo-code"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
"postCreateCommand": "docker network create -d=bridge --subnet=172.19.0.0/24 kind || true",

"remoteUser": "root",

"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
]
}

23 changes: 0 additions & 23 deletions .devcontainer/post-install.sh

This file was deleted.

4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
!cmd/
!api/
!internal/

# Additional files needed for dev container build (.devcontainer/Dockerfile)
!.golangci.yml
!hack/
Loading