Skip to content

Commit 42d3dd6

Browse files
authored
Merge pull request #85 from stuartleeks/devcontainer-update
Simplify devcontainer. Fixup linter errors. Remove snippets Add cacheTo: type=inline to cache dev container image
2 parents db9513f + fc0f60b commit 42d3dd6

File tree

27 files changed

+853
-1733
lines changed

27 files changed

+853
-1733
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,4 @@
1-
#-------------------------------------------------------------------------------------------------------------
2-
# Copyright (c) Microsoft Corporation. All rights reserved.
3-
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4-
#-------------------------------------------------------------------------------------------------------------
1+
FROM mcr.microsoft.com/devcontainers/go:1-1.23-bookworm
52

6-
FROM golang:1.17-bullseye
7-
8-
# Avoid warnings by switching to noninteractive
9-
ENV DEBIAN_FRONTEND=noninteractive
10-
11-
# Configure apt, install packages and tools
12-
RUN apt-get update \
13-
&& apt-get -y install --no-install-recommends apt-utils dialog nano sudo bsdmainutils \
14-
#
15-
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
16-
&& apt-get -y install git iproute2 procps lsb-release build-essential \
17-
# Install Release Tools
18-
#
19-
# --> RPM used by goreleaser
20-
&& apt install -y rpm
21-
22-
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
23-
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
24-
# will be updated to match your local UID/GID (when using the dockerFile property).
25-
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
26-
ARG USERNAME=vscode
27-
ARG USER_UID=1000
28-
ARG USER_GID=$USER_UID
29-
30-
# Create the user
31-
RUN groupadd --gid $USER_GID $USERNAME \
32-
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
33-
&& apt-get update \
34-
&& apt-get install -y sudo \
35-
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
36-
&& chmod 0440 /etc/sudoers.d/$USERNAME
37-
38-
# Set default user
39-
USER $USERNAME
40-
RUN mkdir -p ~/.local/bin
41-
ENV PATH /home/${USERNAME}/.local/bin:$PATH
42-
43-
# Set env for tracking that we're running in a devcontainer
44-
ENV DEVCONTAINER=true
45-
46-
# Enable go modules
47-
ENV GO111MODULE=on
48-
49-
# Install Go tools
50-
ARG GO_PLS_VERSION=0.7.2
51-
ARG DLV_VERSION=1.7.2
52-
ARG GOLANGCI_LINT_VERSION=1.42.1
53-
RUN \
54-
# --> Delve for debugging
55-
go get github.com/go-delve/delve/cmd/dlv@v${DLV_VERSION}\
56-
# --> Go language server
57-
&& go get golang.org/x/tools/gopls@v${GO_PLS_VERSION} \
58-
# --> Go symbols and outline for go to symbol support and test support
59-
&& go get github.com/acroca/go-symbols@v0.1.1 && go get github.com/ramya-rao-a/go-outline@7182a932836a71948db4a81991a494751eccfe77 \
60-
# --> GolangCI-lint
61-
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v${GOLANGCI_LINT_VERSION} \
62-
# --> Go releaser
63-
&& echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list \
64-
&& sudo apt update \
65-
&& sudo apt install goreleaser -y \
66-
# --> Install junit converter
67-
&& go get github.com/jstemmer/go-junit-report@v0.9.1 \
68-
&& sudo rm -rf /go/src/ \
69-
&& sudo rm -rf /go/pkg
70-
71-
# Switch back to dialog for any ad-hoc use of apt-get
72-
ENV DEBIAN_FRONTEND=dialog
73-
74-
# gh
75-
COPY scripts/gh.sh /tmp/
76-
RUN /tmp/gh.sh
77-
78-
# symlink gh config folder
79-
RUN echo 'if [[ ! -d /home/vscode/.config/gh ]]; then mkdir -p /home/vscode/.config; ln -s /config/gh /home/vscode/.config/gh; fi ' >> ~/.bashrc
80-
81-
ARG DOCKER_GROUP_ID
82-
83-
# docker-from-docker
84-
COPY scripts/docker-client.sh /tmp/
85-
RUN /tmp/docker-client.sh
3+
# workaround for https://github.com/yarnpkg/yarn/issues/9216
4+
RUN sudo rm -f /etc/apt/sources.list.d/yarn.list

.devcontainer/devcontainer.json

Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,38 @@
1-
-y// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.1/containers/go
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
33
{
4-
"name": "devcontainer-cli",
5-
"dockerFile": "Dockerfile",
4+
"name": "devcontainerx",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
66
"build": {
7-
"cacheFrom": "ghcr.io/stuartleeks/devcontainer-cli-devcontainer",
8-
"args": {
9-
// To ensure that the group ID for the docker group in the container
10-
// matches the group ID on the host, add this to your .bash_profile on the host
11-
// export DOCKER_GROUP_ID=$(getent group docker | awk -F ":" '{ print $3 }')
12-
"DOCKER_GROUP_ID": "${localEnv:DOCKER_GROUP_ID}"
13-
}
7+
// Path is relataive to the devcontainer.json file.
8+
"dockerfile": "Dockerfile"
149
},
15-
"runArgs": [
16-
// Uncomment the next line to use a non-root user. On Linux, this will prevent
17-
// new files getting created as root, but you may need to update the USER_UID
18-
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
19-
// "-u", "vscode",
20-
"--cap-add=SYS_PTRACE",
21-
"--security-opt",
22-
"seccomp=unconfined",
23-
24-
// Mount go mod cache
25-
"-v", "devcontainer-cli-gomodcache:/go/pkg",
26-
// Use host network
27-
"--network=host",
28-
],
29-
30-
// Set *default* container specific settings.json values on container create.
31-
"settings": {
32-
"terminal.integrated.shell.linux": "/bin/bash",
33-
"go.gopath": "/go",
34-
"go.useLanguageServer": true,
35-
"[go]": {
36-
"editor.snippetSuggestions": "none",
37-
"editor.formatOnSave": true,
38-
"editor.codeActionsOnSave": {
39-
"source.organizeImports": true,
40-
}
41-
},
42-
"gopls": {
43-
"usePlaceholders": true, // add parameter placeholders when completing a function
44-
// Experimental settings
45-
"completeUnimported": true, // autocomplete unimported packages
46-
"deepCompletion": true, // enable deep completion
10+
"features": {
11+
"ghcr.io/devcontainers/features/docker-outside-of-docker": {},
12+
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
13+
"ghcr.io/guiyomh/features/golangci-lint:0": {
14+
"version": "latest"
4715
},
48-
"files.eol": "\n", // formatting only supports LF line endings
16+
"ghcr.io/guiyomh/features/goreleaser:0": {
17+
"version": "1.15.2"
18+
}
4919
},
50-
51-
// Add the IDs of extensions you want installed when the container is created.
52-
"extensions": [
53-
"golang.go",
54-
"stuartleeks.vscode-go-by-example",
55-
"darkriszty.markdown-table-prettify",
56-
"davidanson.vscode-markdownlint",
57-
"mushan.vscode-paste-image"
58-
,
59-
"ms-azuretools.vscode-docker",],
60-
6120
// Use 'forwardPorts' to make a list of ports inside the container available locally.
6221
// "forwardPorts": [],
63-
6422
// Use 'postCreateCommand' to run commands after the container is created.
6523
"postCreateCommand": "make post-create",
66-
67-
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
68-
"remoteUser": "vscode",
69-
"mounts": [
70-
// Keep command history
71-
"source=devcontainer-cli-bashhistory,target=/home/vscode/commandhistory",
72-
// Mounts the .config/gh host folder into the dev container to pick up host gh CLI login details
73-
// NOTE that mounting directly to ~/.config/gh makes ~/.config only root-writable
74-
// Instead monut to another location and symlink in Dockerfile
75-
"type=bind,source=${env:HOME}${env:USERPROFILE}/.config/gh,target=/config/gh",
76-
// Mounts the .azure host folder into the dev container to pick up host az CLI login details
77-
"type=bind,source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure",
78-
// Mount host docker socket
79-
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
80-
],
24+
// Configure tool-specific properties.
25+
"customizations": {
26+
// TODO
27+
"extensions": [
28+
"golang.go",
29+
"stuartleeks.vscode-go-by-example",
30+
"darkriszty.markdown-table-prettify",
31+
"davidanson.vscode-markdownlint",
32+
"mushan.vscode-paste-image",
33+
"ms-azuretools.vscode-docker",
34+
],
35+
},
36+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
37+
// "remoteUser": "root"
8138
}

.github/workflows/build-and-release.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
BRANCH: ${{ github.ref }}
4444
with:
4545
imageName: ghcr.io/stuartleeks/devcontainer-cli-devcontainer
46+
cacheFrom: ghcr.io/stuartleeks/devcontainer-cli-devcontainer
47+
cacheTo: type=inline
4648
runCmd: |
4749
sudo chown -R $(whoami) /go/pkg
4850
./scripts/ci_release.sh

.vscode/launch.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Launch file",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "debug",
12+
"program": "${file}"
13+
},
714
{
815
"name": "Launch",
916
"type": "go",
1017
"request": "launch",
1118
"mode": "auto",
12-
"program": "${workspaceFolder}/cmd/devcontainer",
19+
"program": "${workspaceFolder}/cmd/devcontainerx",
1320
"env": {},
14-
"args": ["list"],
21+
"args": ["list", "--output", "table"],
1522
"dlvLoadConfig": {
1623
"followPointers": true,
1724
"maxVariableRecurse": 1,
@@ -35,6 +42,6 @@
3542
"maxArrayValues": 64,
3643
"maxStructFields": -1
3744
}
38-
},
45+
},
3946
]
4047
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"apiVersion": 2,
1111
"showGlobalVariables": false,
1212
"debugAdapter": "legacy"
13+
},
14+
"chat.tools.terminal.autoApprove": {
15+
"make": true
1316
}
1417
}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ endif
3131

3232

3333
test:
34-
richgo test -v ./...
34+
go test -v ./...
3535

3636

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

4040

4141
post-create:
42-
sudo chown vscode /go/pkg
43-
go get -u github.com/kyoh86/richgo
42+
# #sudo chown vscode /go/pkg
43+
# # go get -u github.com/kyoh86/richgo

cmd/devcontainerx/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func createConfigShowCommand() *cobra.Command {
2525
c := config.GetAll()
2626
jsonConfig, err := json.MarshalIndent(c, "", " ")
2727
if err != nil {
28-
return fmt.Errorf("Error converting to JSON: %s\n", err)
28+
return fmt.Errorf("error converting to JSON: %s", err)
2929
}
3030
fmt.Println(string(jsonConfig))
3131
return nil
@@ -40,7 +40,7 @@ func createConfigWriteCommand() *cobra.Command {
4040
Long: "Write out the config file to ~/.devcontainer-cli/devcontainer-cli.json",
4141
RunE: func(cmd *cobra.Command, args []string) error {
4242
if err := config.SaveConfig(); err != nil {
43-
return fmt.Errorf("Error saving config: %s\n", err)
43+
return fmt.Errorf("error saving config: %s", err)
4444
}
4545
fmt.Println("Config saved")
4646
return nil

0 commit comments

Comments
 (0)