Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 56 additions & 25 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,68 @@
# Note: You can use any Debian/Ubuntu based image you want.
FROM docker.io/golang:1.22.7-bullseye
# Terraform Provider Utilities Development Container
FROM docker.io/golang:1.24-bullseye

# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="false"
# [Option] Enable non-root Docker access in container
ARG ENABLE_NONROOT_DOCKER="true"
# [Option] Use the OSS Moby Engine instead of the licensed Docker Engine
ARG USE_MOBY="true"
# [Option] Engine/CLI Version
ARG DOCKER_VERSION="latest"
ARG UPGRADE_PACKAGES="true"

# Enable new "BUILDKIT" mode for Docker CLI
ENV DOCKER_BUILDKIT=1

# Install needed packages and setup non-root user. Use a separate RUN statement to add your
# own dependencies. A user of "automatic" attempts to reuse an user ID if one already exists.
ARG USERNAME=automatic
# Install needed packages and setup non-root user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

COPY scripts/*.sh /tmp/scripts/
RUN apt-get update -y \
COPY bashrc /tmp/bashrc
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& echo "Acquire::Check-Valid-Until false;" > /etc/apt/apt.conf.d/99no-check-valid-until \
&& (apt-get update -y --allow-releaseinfo-change 2>&1 || true) \
&& apt-get install -y --allow-unauthenticated ca-certificates gnupg lsb-release || true \
&& apt-get update -y --allow-releaseinfo-change \
&& /bin/bash /tmp/scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
# Use Docker script from script library to set things up
&& /bin/bash /tmp/scripts/docker-in-docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "${USERNAME}" "${USE_MOBY}" "${DOCKER_VERSION}" \
# Install additional development tools
&& apt-get install -y \
git \
curl \
wget \
make \
ca-certificates \
gnupg \
lsb-release \
software-properties-common \
apt-transport-https \
bash-completion \
# Install golangci-lint (latest)
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin \
# Install goimports (latest - GOTOOLCHAIN=auto will download compatible Go toolchain if needed)
&& GOTOOLCHAIN=auto go install golang.org/x/tools/cmd/goimports@latest \
# Install gopls (latest - GOTOOLCHAIN=auto will download compatible Go toolchain if needed)
&& GOTOOLCHAIN=auto go install golang.org/x/tools/gopls@latest \
# Configure bash history and completion for root
&& cat /tmp/bashrc >> /root/.bashrc \
# Configure bash history and completion for vscode user if it exists
&& if [ -d /home/${USERNAME} ]; then cat /tmp/bashrc >> /home/${USERNAME}/.bashrc; fi \
# Also add .env loading to system-wide bashrc for VS Code terminals
&& echo "" >> /etc/bash.bashrc \
&& echo "# Auto-load .env file if it exists (for Utilities token and Terraform variables)" >> /etc/bash.bashrc \
&& echo "if [ -f /workspaces/terraform-provider-utilities/.env ]; then" >> /etc/bash.bashrc \
&& echo " set -a" >> /etc/bash.bashrc \
&& echo " source /workspaces/terraform-provider-utilities/.env" >> /etc/bash.bashrc \
&& echo " set +a" >> /etc/bash.bashrc \
&& echo "elif [ -f /workspace/.env ]; then" >> /etc/bash.bashrc \
&& echo " set -a" >> /etc/bash.bashrc \
&& echo " source /workspace/.env" >> /etc/bash.bashrc \
&& echo " set +a" >> /etc/bash.bashrc \
&& echo "fi" >> /etc/bash.bashrc \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/scripts/
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/scripts/ /tmp/bashrc

# Set up Go environment
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH

VOLUME [ "/var/lib/docker" ]
# Keep as root user to avoid permission issues
# USER ${USERNAME}

# Setting the ENTRYPOINT to docker-init.sh will start up the Docker Engine
# inside the container "overrideCommand": false is set in devcontainer.json.
# The script will also execute CMD if you need to alter startup behaviors.
ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]
CMD [ "sleep", "infinity" ]
# Set working directory
WORKDIR /workspace
38 changes: 38 additions & 0 deletions .devcontainer/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Enable bash history with arrow key navigation
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignoredups:erasedups
# Append to history file instead of overwriting
shopt -s histappend
# Save history after each command
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# Enable arrow key history navigation
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'

# Enable bash completion
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi

# Enable completion for common commands
complete -cf sudo
complete -cf man

# Auto-load .env file if it exists
if [ -f /workspaces/terraform-provider-utilities/.env ]; then
set -a
source /workspaces/terraform-provider-utilities/.env
set +a
elif [ -f /workspace/.env ]; then
set -a
source /workspace/.env
set +a
fi
34 changes: 24 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
{
"name": "Docker in Docker Development Container Template",
"name": "Terraform Provider Utilities Development",
"dockerFile": "Dockerfile",
"runArgs": ["--init", "--privileged"],
"mounts": ["source=dind-var-lib-docker,target=/var/lib/docker,type=volume"],
"overrideCommand": false,
"runArgs": ["--init"],

"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode",
"davidanson.vscode-markdownlint",
"golang.go",
"Gruntfuggly.todo-tree",
"hashicorp.terraform",
"Gruntfuggly.todo-tree",
"ms-azuretools.vscode-docker",
"vscode-icons-team.vscode-icons"
"vscode-icons-team.vscode-icons",
"ms-vscode.makefile-tools"
],
"settings": {
"workbench.iconTheme": "vscode-icons"
"workbench.iconTheme": "vscode-icons",
"go.useLanguageServer": true,
"go.formatTool": "goimports",
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"[terraform]": {
"editor.formatOnSave": true
},
"terraform.format.enable": true,
"terraform.languageServer.enable": true
}
}
},
Expand All @@ -27,6 +41,6 @@
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/scripts/postCreate.sh"

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
// Connect as root to avoid permission issues (commented out remoteUser means root)
// "remoteUser": "vscode"
}
Loading
Loading