From 6a7801e62ae44dc690218e5a482360e9e62bd8bb Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Fri, 23 May 2025 23:25:51 -0400 Subject: [PATCH] chore(ci): improve devcontainer UX Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .devcontainer/Dockerfile | 18 ++++++++ .devcontainer/devcontainer.json | 73 ++++++++++++++++++++++++++++----- .devcontainer/post-attach.sh | 17 ++++++++ .vscode/extensions.json | 3 +- Makefile | 4 +- 5 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..ae78b357 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,18 @@ +ARG GO_VERSION=1.24.3 +ARG GOLANGCI_LINT_VERSION=2.1.6 # renovate: depName=golangci/golangci-lint datasource=github-releases + +FROM golang:${GO_VERSION} + +# install docker +RUN apt update && apt upgrade -y && apt-get install -y ca-certificates curl gnupg lsb-release jq zsh neovim && \ + chsh -s $(which zsh) && \ + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ + rm -rf /var/lib/apt/lists/* + +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + + +RUN curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh && \ + chmod +x install-opentofu.sh && \ + ./install-opentofu.sh --install-method deb && \ + rm -f install-opentofu.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b81f5ad9..03db03cd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,27 +3,78 @@ { "name": "Default Linux Universal", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/go:1.24-bullseye", - + // "image": "mcr.microsoft.com/devcontainers/go:1.24-bullseye", + // "image": "qmcgaw/godevcontainer:latest", + "dockerFile": "Dockerfile", + // Features to add to the dev container. More info: https://containers.dev/features. "features": { - "ghcr.io/devcontainers/features/terraform:1": { - "version": "1.10.3" - } + "ghcr.io/devcontainers/features/terraform:1": {} }, - - "postAttachCommand": ["bash", "./.devcontainer/post-attach.sh"], + + "mounts": [ + // Zsh commands history persistence + { + "source": "${localEnv:HOME}/.zsh_history", + "target": "/root/.zsh_history", + "type": "bind" + }, + // Git configuration file + { + "source": "${localEnv:HOME}/.gitconfig", + "target": "/root/.gitconfig", + "type": "bind" + }, + // SSH directory for Linux, OSX and WSL + // On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is + // created in the container. On Windows, files are copied + // from /mnt/ssh to ~/.ssh to fix permissions. + { + "source": "${localEnv:HOME}/.ssh", + "target": "/mnt/ssh", + "type": "bind" + }, + // Docker socket to access the host Docker server + { + "source": "/var/run/docker.sock", + "target": "/var/run/docker.sock", + "type": "bind" + } + ], // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Configure tool-specific properties. - // "customizations": {}, + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "go.toolsManagement.checkForUpdates": "local", + "go.useLanguageServer": true, + "go.gopath": "/go" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "britesnow.vscode-toggle-quotes", + "davidanson.vscode-markdownlint", + "EditorConfig.editorconfig", + "golang.go", + "hashicorp.terraform", + "joshbolduc.commitlint", + "ms-azuretools.vscode-docker", + "ms-vscode.makefile-tools", + "psioniq.psi-header" + ] + } + }, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" - - + "remoteUser": "root", + + "postAttachCommand": ["bash", "./.devcontainer/post-attach.sh"], + // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "make build" } diff --git a/.devcontainer/post-attach.sh b/.devcontainer/post-attach.sh index 7564b7fc..e34f8c4b 100644 --- a/.devcontainer/post-attach.sh +++ b/.devcontainer/post-attach.sh @@ -1,5 +1,22 @@ #!/usr/bin/bash +# Display welcome banner +echo -e "\033[1;36m" +echo "════════════════════════════════════════════════════════════════════════════════════════════" +echo +echo " 🚀 Terraform Provider For Proxmox Development Environment" +echo +echo " ⚠️ EXPERIMENTAL" +echo " Use at your own risk! Some tools may be missing or not work as expected." +echo +echo " • Go Version: $(go version | cut -d' ' -f3 | sed 's/^go//')" +echo " • Terraform Version: $(terraform version -json | jq -r '.terraform_version')" +echo " • OpenTofu Version: $(tofu version -json | jq -r '.terraform_version')" +echo " • Working Directory: $(pwd)" +echo +echo "════════════════════════════════════════════════════════════════════════════════════════════" +echo -e "\033[0m" + # Workaround for https://github.com/orgs/community/discussions/75161 unset GIT_COMMITTER_NAME unset GIT_COMMITTER_EMAIL diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 40ecdfd7..96999103 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,6 +7,7 @@ "hashicorp.terraform", "joshbolduc.commitlint", "PKief.material-icon-theme", - "psioniq.psi-header" + "psioniq.psi-header", + "ms-azuretools.vscode-docker" ] } diff --git a/Makefile b/Makefile index b221c223..fae5bac4 100644 --- a/Makefile +++ b/Makefile @@ -112,8 +112,8 @@ testacc: .PHONY: lint lint: # NOTE: This target is for local runs only. For linting in CI see .github/workflows/golangci-lint.yml - @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 - @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 + golangci-lint fmt + golangci-lint run --fix .PHONY: release-build release-build: