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
87 changes: 3 additions & 84 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,85 +1,4 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM mcr.microsoft.com/devcontainers/go:1-1.23-bookworm

FROM golang:1.17-bullseye

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt, install packages and tools
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog nano sudo bsdmainutils \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install git iproute2 procps lsb-release build-essential \
# Install Release Tools
#
# --> RPM used by goreleaser
&& apt install -y rpm

# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Set default user
USER $USERNAME
RUN mkdir -p ~/.local/bin
ENV PATH /home/${USERNAME}/.local/bin:$PATH

# Set env for tracking that we're running in a devcontainer
ENV DEVCONTAINER=true

# Enable go modules
ENV GO111MODULE=on

# Install Go tools
ARG GO_PLS_VERSION=0.7.2
ARG DLV_VERSION=1.7.2
ARG GOLANGCI_LINT_VERSION=1.42.1
RUN \
# --> Delve for debugging
go get github.com/go-delve/delve/cmd/dlv@v${DLV_VERSION}\
# --> Go language server
&& go get golang.org/x/tools/gopls@v${GO_PLS_VERSION} \
# --> Go symbols and outline for go to symbol support and test support
&& go get github.com/acroca/go-symbols@v0.1.1 && go get github.com/ramya-rao-a/go-outline@7182a932836a71948db4a81991a494751eccfe77 \
# --> GolangCI-lint
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v${GOLANGCI_LINT_VERSION} \
# --> Go releaser
&& echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list \
&& sudo apt update \
&& sudo apt install goreleaser -y \
# --> Install junit converter
&& go get github.com/jstemmer/go-junit-report@v0.9.1 \
&& sudo rm -rf /go/src/ \
&& sudo rm -rf /go/pkg

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

# gh
COPY scripts/gh.sh /tmp/
RUN /tmp/gh.sh

# symlink gh config folder
RUN echo 'if [[ ! -d /home/vscode/.config/gh ]]; then mkdir -p /home/vscode/.config; ln -s /config/gh /home/vscode/.config/gh; fi ' >> ~/.bashrc

ARG DOCKER_GROUP_ID

# docker-from-docker
COPY scripts/docker-client.sh /tmp/
RUN /tmp/docker-client.sh
# workaround for https://github.com/yarnpkg/yarn/issues/9216
RUN sudo rm -f /etc/apt/sources.list.d/yarn.list
99 changes: 28 additions & 71 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,38 @@
-y// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.1/containers/go
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "devcontainer-cli",
"dockerFile": "Dockerfile",
"name": "devcontainerx",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"cacheFrom": "ghcr.io/stuartleeks/devcontainer-cli-devcontainer",
"args": {
// To ensure that the group ID for the docker group in the container
// matches the group ID on the host, add this to your .bash_profile on the host
// export DOCKER_GROUP_ID=$(getent group docker | awk -F ":" '{ print $3 }')
"DOCKER_GROUP_ID": "${localEnv:DOCKER_GROUP_ID}"
}
// Path is relataive to the devcontainer.json file.
"dockerfile": "Dockerfile"
},
"runArgs": [
// Uncomment the next line to use a non-root user. On Linux, this will prevent
// new files getting created as root, but you may need to update the USER_UID
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
// "-u", "vscode",
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",

// Mount go mod cache
"-v", "devcontainer-cli-gomodcache:/go/pkg",
// Use host network
"--network=host",
],

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"go.gopath": "/go",
"go.useLanguageServer": true,
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
}
},
"gopls": {
"usePlaceholders": true, // add parameter placeholders when completing a function
// Experimental settings
"completeUnimported": true, // autocomplete unimported packages
"deepCompletion": true, // enable deep completion
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker": {},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
"ghcr.io/guiyomh/features/golangci-lint:0": {
"version": "latest"
},
"files.eol": "\n", // formatting only supports LF line endings
"ghcr.io/guiyomh/features/goreleaser:0": {
"version": "1.15.2"
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.go",
"stuartleeks.vscode-go-by-example",
"darkriszty.markdown-table-prettify",
"davidanson.vscode-markdownlint",
"mushan.vscode-paste-image"
,
"ms-azuretools.vscode-docker",],

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

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "make post-create",

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"mounts": [
// Keep command history
"source=devcontainer-cli-bashhistory,target=/home/vscode/commandhistory",
// Mounts the .config/gh host folder into the dev container to pick up host gh CLI login details
// NOTE that mounting directly to ~/.config/gh makes ~/.config only root-writable
// Instead monut to another location and symlink in Dockerfile
"type=bind,source=${env:HOME}${env:USERPROFILE}/.config/gh,target=/config/gh",
// Mounts the .azure host folder into the dev container to pick up host az CLI login details
"type=bind,source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure",
// Mount host docker socket
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
],
// Configure tool-specific properties.
"customizations": {
// TODO
"extensions": [
"golang.go",
"stuartleeks.vscode-go-by-example",
"darkriszty.markdown-table-prettify",
"davidanson.vscode-markdownlint",
"mushan.vscode-paste-image",
"ms-azuretools.vscode-docker",
],
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 2 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
BRANCH: ${{ github.ref }}
with:
imageName: ghcr.io/stuartleeks/devcontainer-cli-devcontainer
cacheFrom: ghcr.io/stuartleeks/devcontainer-cli-devcontainer
cacheTo: type=inline
runCmd: |
sudo chown -R $(whoami) /go/pkg
./scripts/ci_release.sh
Expand Down
13 changes: 10 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
},
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/devcontainer",
"program": "${workspaceFolder}/cmd/devcontainerx",
"env": {},
"args": ["list"],
"args": ["list", "--output", "table"],
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 1,
Expand All @@ -35,6 +42,6 @@
"maxArrayValues": 64,
"maxStructFields": -1
}
},
},
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"apiVersion": 2,
"showGlobalVariables": false,
"debugAdapter": "legacy"
},
"chat.tools.terminal.autoApprove": {
"make": true
}
}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ endif


test:
richgo test -v ./...
go test -v ./...


fmt:
find . -name '*.go' | grep -v vendor | xargs gofmt -s -w


post-create:
sudo chown vscode /go/pkg
go get -u github.com/kyoh86/richgo
# #sudo chown vscode /go/pkg
# # go get -u github.com/kyoh86/richgo
4 changes: 2 additions & 2 deletions cmd/devcontainerx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func createConfigShowCommand() *cobra.Command {
c := config.GetAll()
jsonConfig, err := json.MarshalIndent(c, "", " ")
if err != nil {
return fmt.Errorf("Error converting to JSON: %s\n", err)
return fmt.Errorf("error converting to JSON: %s", err)
}
fmt.Println(string(jsonConfig))
return nil
Expand All @@ -40,7 +40,7 @@ func createConfigWriteCommand() *cobra.Command {
Long: "Write out the config file to ~/.devcontainer-cli/devcontainer-cli.json",
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.SaveConfig(); err != nil {
return fmt.Errorf("Error saving config: %s\n", err)
return fmt.Errorf("error saving config: %s", err)
}
fmt.Println("Config saved")
return nil
Expand Down
Loading