Skip to content

Commit ab485fc

Browse files
authored
Merge pull request #1 from stuartleeks/sl/devcontainer
Add initial devcontainer
2 parents 0358628 + c112bb3 commit ab485fc

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

.devcontainer/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM golang:1.14-stretch
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 \
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 \
17+
# Install Release Tools
18+
#
19+
# --> RPM used by goreleaser
20+
&& apt install -y rpm \
21+
# Clean up
22+
&& apt-get autoremove -y \
23+
&& apt-get clean -y \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
27+
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
28+
# will be updated to match your local UID/GID (when using the dockerFile property).
29+
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
30+
ARG USERNAME=vscode
31+
ARG USER_UID=1000
32+
ARG USER_GID=$USER_UID
33+
34+
35+
# Enable go modules
36+
ENV GO111MODULE=on
37+
38+
# Install Go tools
39+
RUN \
40+
# --> Delve for debugging
41+
go get github.com/go-delve/delve/cmd/[email protected] \
42+
# --> Go language server
43+
&& go get golang.org/x/tools/[email protected] \
44+
# --> Go symbols and outline for go to symbol support and test support
45+
&& go get github.com/acroca/[email protected] && go get github.com/ramya-rao-a/go-outline@7182a932836a71948db4a81991a494751eccfe77 \
46+
# --> GolangCI-lint
47+
&& curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sed 's/tar -/tar --no-same-owner -/g' | sh -s -- -b $(go env GOPATH)/bin \
48+
# --> Install junit converter
49+
&& go get github.com/jstemmer/[email protected] \
50+
&& rm -rf /go/src/ && rm -rf /go/pkg
51+
52+
# Switch back to dialog for any ad-hoc use of apt-get
53+
ENV DEBIAN_FRONTEND=dialog

.devcontainer/devcontainer.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// 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
3+
{
4+
"name": "devcontainer-cli",
5+
"dockerFile": "Dockerfile",
6+
"runArgs": [
7+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
8+
// new files getting created as root, but you may need to update the USER_UID
9+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
10+
// "-u", "vscode",
11+
"--cap-add=SYS_PTRACE",
12+
"--security-opt",
13+
"seccomp=unconfined",
14+
15+
// Mount go mod cache
16+
"-v", "devcontainer-cli-gomodcache:/go/pkg",
17+
// Keep command history
18+
"-v", "devcontainer-cli-bashhistory:/root/commandhistory",
19+
// Mount docker socket for docker builds
20+
"-v", "/var/run/docker.sock:/var/run/docker.sock",
21+
// Use host network
22+
"--network=host",
23+
// Mount azure, git and docker config
24+
"-v", "${env:HOME}${env:USERPROFILE}/.azure:/root/.azure"
25+
],
26+
27+
// Set *default* container specific settings.json values on container create.
28+
"settings": {
29+
"terminal.integrated.shell.linux": "/bin/bash",
30+
"go.gopath": "/go",
31+
"go.useLanguageServer": true,
32+
"[go]": {
33+
"editor.snippetSuggestions": "none",
34+
"editor.formatOnSave": true,
35+
"editor.codeActionsOnSave": {
36+
"source.organizeImports": true,
37+
}
38+
},
39+
"gopls": {
40+
"usePlaceholders": true, // add parameter placeholders when completing a function
41+
// Experimental settings
42+
"completeUnimported": true, // autocomplete unimported packages
43+
"watchFileChanges": true, // watch file changes outside of the editor
44+
"deepCompletion": true, // enable deep completion
45+
},
46+
"files.eol": "\n", // formatting only supports LF line endings
47+
},
48+
49+
// Add the IDs of extensions you want installed when the container is created.
50+
"extensions": [
51+
"ms-vscode.go"
52+
]
53+
54+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
55+
// "forwardPorts": [],
56+
57+
// Use 'postCreateCommand' to run commands after the container is created.
58+
// "postCreateCommand": "go version",
59+
60+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
61+
// "remoteUser": "vscode"
62+
}

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
build:
2-
go build ./cmd/devcontainer
2+
go build ./cmd/devcontainer
3+
4+
devcontainer:
5+
docker build -f ./.devcontainer/Dockerfile ./.devcontainer -t devcontainer-cli

0 commit comments

Comments
 (0)