Skip to content

Commit d8a7bc0

Browse files
authored
chore(ci): improve devcontainer UX (#1973)
Signed-off-by: Pavel Boldyrev <[email protected]>
1 parent b1b8d15 commit d8a7bc0

File tree

6 files changed

+122
-17
lines changed

6 files changed

+122
-17
lines changed

.devcontainer/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.24.3
2+
3+
ARG GOLANGCI_LINT_VERSION=2.1.6 # renovate: depName=golangci/golangci-lint datasource=github-releases
4+
5+
RUN apt update && apt upgrade -y && \
6+
apt-get install --no-install-recommends -y ca-certificates curl gnupg lsb-release jq zsh neovim && \
7+
chsh -s $(which zsh) && \
8+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v${GOLANGCI_LINT_VERSION}
12+
13+
14+
RUN curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh && \
15+
chmod +x install-opentofu.sh && \
16+
./install-opentofu.sh --install-method deb && \
17+
rm -f install-opentofu.sh

.devcontainer/devcontainer.json

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,75 @@
33
{
44
"name": "Default Linux Universal",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/go:1.24-bullseye",
7-
6+
"dockerFile": "Dockerfile",
7+
88
// Features to add to the dev container. More info: https://containers.dev/features.
99
"features": {
10-
"ghcr.io/devcontainers/features/terraform:1": {
11-
"version": "1.10.3"
12-
}
10+
"ghcr.io/devcontainers/features/terraform:1": {}
1311
},
14-
15-
"postAttachCommand": ["bash", "./.devcontainer/post-attach.sh"],
12+
13+
"mounts": [
14+
// Zsh commands history persistence
15+
{
16+
"source": "${localEnv:HOME}/.zsh_history",
17+
"target": "/root/.zsh_history",
18+
"type": "bind"
19+
},
20+
// Git configuration file
21+
{
22+
"source": "${localEnv:HOME}/.gitconfig",
23+
"target": "/root/.gitconfig",
24+
"type": "bind"
25+
},
26+
// SSH directory for Linux, OSX and WSL
27+
// On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is
28+
// created in the container. On Windows, files are copied
29+
// from /mnt/ssh to ~/.ssh to fix permissions.
30+
{
31+
"source": "${localEnv:HOME}/.ssh",
32+
"target": "/mnt/ssh",
33+
"type": "bind"
34+
},
35+
// Docker socket to access the host Docker server
36+
{
37+
"source": "/var/run/docker.sock",
38+
"target": "/var/run/docker.sock",
39+
"type": "bind"
40+
}
41+
],
1642

1743
// Use 'forwardPorts' to make a list of ports inside the container available locally.
1844
// "forwardPorts": [],
1945

2046
// Configure tool-specific properties.
21-
// "customizations": {},
47+
"customizations": {
48+
// Configure properties specific to VS Code.
49+
"vscode": {
50+
// Set *default* container specific settings.json values on container create.
51+
"settings": {
52+
"go.toolsManagement.checkForUpdates": "local",
53+
"go.useLanguageServer": true
54+
},
55+
// Add the IDs of extensions you want installed when the container is created.
56+
"extensions": [
57+
"britesnow.vscode-toggle-quotes",
58+
"davidanson.vscode-markdownlint",
59+
"EditorConfig.editorconfig",
60+
"golang.go",
61+
"hashicorp.terraform",
62+
"joshbolduc.commitlint",
63+
"ms-azuretools.vscode-docker",
64+
"ms-vscode.makefile-tools",
65+
"psioniq.psi-header"
66+
]
67+
}
68+
},
2269

2370
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
24-
// "remoteUser": "root"
25-
26-
71+
"remoteUser": "root",
72+
73+
"postAttachCommand": ["bash", "./.devcontainer/post-attach.sh"],
74+
2775
// Use 'postCreateCommand' to run commands after the container is created.
2876
"postCreateCommand": "make build"
2977
}

.devcontainer/post-attach.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
#!/usr/bin/bash
1+
#!/usr/bin/env bash
2+
3+
# Display welcome banner
4+
echo -e "\033[1;36m"
5+
echo "════════════════════════════════════════════════════════════════════════════════════════════"
6+
echo
7+
echo " 🚀 Terraform Provider For Proxmox Development Environment"
8+
echo
9+
echo " ⚠️ EXPERIMENTAL"
10+
echo " Use at your own risk! Some tools may be missing or not work as expected."
11+
echo
12+
echo " • Go Version: $(go version | cut -d' ' -f3 | sed 's/^go//')"
13+
echo " • Terraform Version: $(terraform version -json | jq -r '.terraform_version')"
14+
echo " • OpenTofu Version: $(tofu version -json | jq -r '.terraform_version')"
15+
echo " • Working Directory: $(pwd)"
16+
echo
17+
echo "════════════════════════════════════════════════════════════════════════════════════════════"
18+
echo -e "\033[0m"
219

320
# Workaround for https://github.com/orgs/community/discussions/75161
421
unset GIT_COMMITTER_NAME

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"hashicorp.terraform",
88
"joshbolduc.commitlint",
99
"PKief.material-icon-theme",
10-
"psioniq.psi-header"
10+
"psioniq.psi-header",
11+
"ms-azuretools.vscode-docker"
1112
]
1213
}

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ make docs
5252

5353
If you are using VS Code, feel free to copy `settings.json` from `.vscode/settings.example.json`.
5454

55+
## Devcontainer support
56+
57+
Prerequisites:
58+
59+
- Docker (or Docker Desktop) installed on your machine
60+
- [VS Code Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
61+
62+
To launch the devcontainer:
63+
64+
1. Open the project in VS Code.
65+
2. Run **Remote-Containers: Open Folder in Container** from the Command Palette.
66+
67+
See [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers) for more details.
68+
5569
## Testing
5670

5771
### Unit Tests

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ TARGETS=darwin linux windows
33
TERRAFORM_PLUGIN_EXTENSION=
44
VERSION=0.78.0# x-release-please-version
55

6-
GOLANGCI_LINT_VERSION=v2.1.6# renovate: depName=golangci/golangci-lint datasource=github-releases
6+
GOLANGCI_LINT_VERSION=2.1.6# renovate: depName=golangci/golangci-lint datasource=github-releases
77

88
# check if opentofu is installed and use it if it is,
99
# otherwise use terraform
@@ -110,10 +110,18 @@ testacc:
110110
@TF_ACC=1 env $$(cat testacc.env | xargs) go test --timeout=30m --tags=acceptance -count=1 -v github.com/bpg/terraform-provider-proxmox/fwprovider/...
111111

112112
.PHONY: lint
113-
lint:
113+
lint: ensure-golangci-lint
114114
# NOTE: This target is for local runs only. For linting in CI see .github/workflows/golangci-lint.yml
115-
@docker run -t --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint fmt
116-
@docker run -t --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint run --fix
115+
golangci-lint fmt
116+
golangci-lint run --fix
117+
118+
.PHONY: ensure-golangci-lint
119+
ensure-golangci-lint:
120+
@CURRENT_VERSION=$$(golangci-lint version --short 2>/dev/null | sed 's/^v//' || echo "not installed"); \
121+
if [ "$$CURRENT_VERSION" != "$(GOLANGCI_LINT_VERSION)" ]; then \
122+
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION) (current: $$CURRENT_VERSION)"; \
123+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v$(GOLANGCI_LINT_VERSION); \
124+
fi
117125

118126
.PHONY: release-build
119127
release-build:

0 commit comments

Comments
 (0)