Skip to content

Commit bb7f428

Browse files
committed
refactor: repository and source structure (PR #25)
## Feat Totally refactored (simpler source structure) * feat: new Docker image (more secure and light weight. Debian -> Alpine) * feat: codeQL-analysis.yml * feat: auto mod updater (auto PR on go.mod update) * feat: auto merge on go.mod update only (via mergify) * feat: include go.sum ## Fix * fix: #23 bad indentation * fix: golangci-lint warnings * fix: use latest goclangci-lint for lint check * fix: mergify.yml (deprecated "strict" config) * fix: redundant checks (only on push to main) * fix: remove bin directory ## Chore * Update platform-test.yaml * Update golangci-lint.yaml * Update version-tests.yaml --- Closing #23 Closing #24
1 parent 85c5321 commit bb7f428

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1935
-1616
lines changed

.devcontainer/Dockerfile

Lines changed: 18 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,18 @@
1-
# =============================================================================
2-
# Pre Defined Variables
3-
# =============================================================================
4-
# User provided Go version of Docker image
5-
ARG VARIANT
6-
# Default Go version. Choices: 1, 1.15, 1.14
7-
ARG VARIANT_DEFAULT="1"
8-
# Default Language
9-
ARG LC_ALL_DEFAULT='en_US.utf8'
10-
ARG LANG_DEFAULT='en_US.utf8'
11-
# Default Node.js settings
12-
ARG INSTALL_NODE_DEFAULT="false"
13-
ARG NODE_VERSION_DEFAULT="lts/*"
14-
15-
# =============================================================================
16-
# Define Dockerfile.
17-
#
18-
# For image contents see:
19-
# https://github.com/microsoft/vscode-dev-containers/tree/v0.145.1/containers/go/.devcontainer/base.Dockerfile
20-
# =============================================================================
21-
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT:-$VARIANT_DEFAULT}
22-
23-
# Declare user args to receive while building an image.
24-
ARG LANG
25-
ARG LC_ALL
26-
ARG INSTALL_NODE
27-
ARG NODE_VERSION
28-
29-
ENV \
30-
LANG="${LANG:-$LANG_DEFAULT}" \
31-
LC_ALL="${LC_ALL:-$LC_ALL_DEFAULT}" \
32-
PATH="/usr/local/go/bin:${PATH}" \
33-
# Enforce go module mode
34-
GO111MODULE='on' \
35-
# Fix: https://github.com/microsoft/vscode-dev-containers/issues/51
36-
SHELL="/bin/bash"
37-
38-
#RUN localedef -f UTF-8
39-
40-
# [Option] Install Node.js
41-
ARG INSTALL_NODE="${INSTALL_NODE:-INSTALL_NODE_DEFAULT}"
42-
ARG NODE_VERSION="${NODE_VERSION:-NODE_VERSION_DEFAULT}"
43-
RUN if [ "${INSTALL_NODE}" = "true" ]; then \
44-
echo 'Installing Node.js'; \
45-
su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; \
46-
fi
47-
48-
# Bash script file to run right after the container was created.
49-
# See: "postCreateCommand" section in "devcontainer.json" and "postCreateCommand.sh"
50-
# file.
51-
COPY postCreateCommand.sh /postCreateCommand.sh
52-
53-
# Install additional OS packages.
54-
RUN export DEBIAN_FRONTEND=noninteractive \
55-
&& apt-get update \
56-
&& apt-get -y upgrade \
57-
&& apt-get -y install --no-install-recommends \
58-
# The `rg` is a string search command from files. ex) rg ./cmd foo
59-
ripgrep \
60-
# Directory tree viewer for documentation.
61-
tree \
62-
# xz to untar xz compressed files
63-
xz-utils \
64-
# missing locales
65-
locales
66-
67-
# ShellCheck - Static analyzer and formatter for shell script
68-
# Note: Install the latest shellcheck. See: https://github.com/koalaman/shellcheck/issues/704
69-
RUN url_download="https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.$(uname -m).tar.xz" \
70-
&& path_tmp_dir="$(pwd)/tmp_install_dir" \
71-
&& wget -P "${path_tmp_dir}/" "$url_download"\
72-
&& tar xvf ${path_tmp_dir}/shellcheck* -C "${path_tmp_dir}/" \
73-
&& cp "${path_tmp_dir}/shellcheck-latest/shellcheck" "$(dirname $(which tree))/shellcheck" \
74-
# Smoke test
75-
&& shellcheck --version \
76-
&& rm -r "$path_tmp_dir"
77-
78-
# golangci-lint - The fast Go linters runner. Version=latest
79-
# binary will be installed under: $(go env GOPATH)/bin/golangci-lint
80-
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin \
81-
# Smoke test
82-
&& golangci-lint --version
83-
84-
# Install anything else needed to go get
85-
RUN go get -u -v \
86-
# gopls (language server)
87-
# `gopls` will install the packages in the URL below as well.
88-
# https://github.com/golang/vscode-go/blob/master/docs/tools.md#table-of-contents
89-
"golang.org/x/tools/gopls@latest" \
90-
# go-carpet (Cover area checker)
91-
"github.com/msoap/go-carpet" \
92-
# shfmt (shellformat) is a shell script linter
93-
"mvdan.cc/sh/v3/cmd/shfmt" \
94-
# gp enables to share go files over Go Playground
95-
"github.com/tenntenn/goplayground/cmd/gp" \
96-
# gomarkdoc generates documentation in markdown
97-
"github.com/princjef/gomarkdoc/cmd/gomarkdoc" \
98-
#"github.com/rogpeppe/godef" \
99-
# -------------------------------------------------------------------------
100-
# irregular install (Download source and build)
101-
# -------------------------------------------------------------------------
102-
&& cd "${GOPATH}/pkg/mod" \
103-
&& go get -v -d \
104-
# gocode and gocode-modules is no-good to install as module
105-
"github.com/stamblerre/gocode" \
106-
# cobra (sub-command creation)
107-
"github.com/spf13/cobra" \
108-
# gomock
109-
"github.com/golang/mock/gomock" \
110-
# gocode and gocode-modules
111-
&& cd ${GOPATH}/pkg/mod/github.com/stamblerre/gocode* \
112-
&& go build -o "${GOPATH}/bin/gocode-gomod" . \
113-
# cobra command
114-
&& cd ${GOPATH}/pkg/mod/github.com/spf13/cobra*/cobra \
115-
&& go build -o "${GOPATH}/bin/cobra" . \
116-
# mockgen
117-
&& cd ${GOPATH}/pkg/mod/github.com/golang/mock*/mockgen \
118-
&& go install \
119-
# List bin files
120-
&& echo "- List dir: ${GOPATH}/bin" && ls -l "${GOPATH}/bin"
121-
122-
# Miscellaneous
123-
RUN \
124-
# Set path for go
125-
echo 'export PATH="/go/bin:/usr/local/go/bin:${PATH}"' >> "${HOME}/.bashrc"
126-
127-
# [Optional] Uncomment this line to install global node packages.
128-
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
1+
# [Choice] https://github.com/KEINOS/VSCode-Dev-Container-Go/pkgs/container/vscode-dev-container-go
2+
ARG VARIANT="latest"
3+
4+
# -----------------------------------------------------------------------------
5+
# Main Stage
6+
# -----------------------------------------------------------------------------
7+
# ghcr.io/keinos/vscode-dev-container-go is an Alpine-based container image which
8+
# provides a VSCode development environment over Docker. This image is weekly
9+
# scanned for vulnerability and security with Synk, Dockle and Trivy. For detals
10+
# see: ./README.md
11+
FROM ghcr.io/keinos/vscode-dev-container-go:${VARIANT}
12+
13+
# [Optional] Uncomment this section to install additional OS packages.
14+
# USER root
15+
# RUN apk add --no-cache <your-package-list-here>
16+
17+
USER vscode
18+
RUN cd /tmp && go install golang.org/x/lint/golint@latest

.devcontainer/README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33

44
This directory is for [GitHub Codespaces](https://github.com/features/codespaces) and/or [VS Code + Docker](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) users for development.
55

6-
It includes most of the necessary packages and tools for developing Golang app. Aiming to provide the same environment to develop the app.
6+
It includes:
7+
8+
- Latest [Alpine-based container image](https://github.com/KEINOS/VSCode-Dev-Container-Go/pkgs/container/vscode-dev-container-go) with vulnerability and security scan via Synk, Dockle and Trivy.
9+
- Latest Go version.
10+
- Common packages and tools for developing Golang app and shell scripts.
11+
- [Installed tools and Go modules](https://github.com/KEINOS/VSCode-Dev-Container-Go/blob/main/image_info.txt) | VSCode-Dev-Container-Go | KEINOS @ GitHub
12+
- Weekly updated.
713

814
## Developing Online
915

10-
If GitHub detects this directory (`.devcontainer`) in the repo, then you will be able to develop online via [GitHub Codespaces](https://github.com/features/codespaces).
16+
Just press the `.`(dot) key on GitHub and you should be redirected to [GitHub Codespaces](https://github.com/features/codespaces). (You may need to register to use Codesspaces)
1117

1218
## VS Code + Docker User
1319

1420
The container contains VS Code Server as well. If you already have installed the "[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)" extension, then press "<kbd>F1</kbd>" and select "`Remote-Containers: Open in Container`".
1521

1622
After a while, you'll get most of the environment needed to develop and debug.
17-
18-
## File Description
19-
20-
- [cobra.yaml](cobra.yaml): Default `cobra` command Settings. Used for `$ cobra add ..`
21-
- [devcontainer.env](devcontainer.env): ENV variables to be loaded once when the container's created.
22-
- [devcontainer.json](devcontainer.json): VSCode Extensions to be installed and env settings.
23-
- [Dockerfile](Dockerfile): Debian 10 (buster) based Golang development container.
24-
- [postCreateCommand.sh](postCreateCommand.sh): Initialization script that runs after the container and the VSCode server is up.
25-
- [README.md](README.md): This file. ;-)
26-
- [welcome.sh](welcome.sh): Bash script to display the basic info and TIPs to use in the first shell login.

.devcontainer/devcontainer.env

Lines changed: 0 additions & 26 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/go
13
{
2-
"name": "Go",
4+
"name": "Go Dev",
35
"build": {
46
"dockerfile": "Dockerfile",
57
"args": {
6-
// Go version: 1, 1.15, 1.14
7-
"VARIANT": "1.15",
8-
// Options
9-
"INSTALL_NODE": "false",
10-
"NODE_VERSION": "lts/*"
8+
// Choices: https://github.com/KEINOS/VSCode-Dev-Container-Go/pkgs/container/vscode-dev-container-go
9+
"VARIANT": "latest"
1110
}
1211
},
13-
"runArgs": [
14-
"--cap-add=SYS_PTRACE",
15-
"--security-opt", "seccomp=unconfined",
16-
"--env-file",".devcontainer/devcontainer.env"
17-
],
18-
// Set VSCode settings
12+
"runArgs": [
13+
"--rm",
14+
"--cap-add=SYS_PTRACE",
15+
"--security-opt",
16+
"seccomp=unconfined"
17+
],
18+
19+
// Set *default* container specific settings.json values on container create.
1920
"settings": {
21+
"go.toolsManagement.checkForUpdates": "local",
22+
"go.useLanguageServer": true,
2023
"go.gopath": "/go",
2124
"go.goroot": "/usr/local/go",
22-
"go.lintFlags": ["--enable-all", "--new"],
23-
"go.toolsGopath": "/go/bin",
24-
"go.toolsManagement.checkForUpdates": "proxy",
25-
"go.useLanguageServer": true,
26-
"terminal.integrated.shell.linux": "/bin/bash",
27-
"terminal.integrated.shellArgs.linux": ["-l"]
25+
"terminal.integrated.profiles.linux": {
26+
"bash (login)": {
27+
"path": "/bin/bash",
28+
"args": []
29+
}
30+
},
31+
"shellformat.path": "/go/bin/shfmt"
2832
},
2933

30-
// VSCode extension ID to be installed
34+
// Add the IDs of extensions you want installed when the container is created.
3135
"extensions": [
3236
"golang.Go",
33-
"editorconfig.editorconfig",
34-
"foxundermoon.shell-format",
35-
"ms-ceintl.vscode-language-pack-ja",
36-
"ms-ceintl.vscode-language-pack-es",
37-
"ms-azuretools.vscode-docker",
38-
"ms-vsonline.vsonline",
39-
"github.github-vscode-theme",
40-
"github.vscode-pull-request-github",
41-
"davidanson.vscode-markdownlint"
37+
"foxundermoon.shell-format"
4238
],
4339

40+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
41+
// "forwardPorts": [],
42+
4443
// Use 'postCreateCommand' to run commands after the container is created.
45-
"postCreateCommand": "/bin/bash /postCreateCommand.sh;"
44+
"postCreateCommand": "go mod download",
4645

47-
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
48-
//"remoteUser": "vscode"
49-
}
46+
// Comment out to connect as root to debug container.
47+
// "remoteUser": "root"
48+
}

.devcontainer/postCreateCommand.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.devcontainer/welcome.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# =============================================================================
2+
# Test Container for Vaious Go Versions
3+
# =============================================================================
4+
# Default version
5+
ARG VARIANT="1.15-alpine"
6+
7+
# -----------------------------------------------------------------------------
8+
# Main Stage
9+
# -----------------------------------------------------------------------------
10+
FROM golang:${VARIANT}
11+
12+
ENV GO111MODULE=on
13+
14+
RUN apk add --no-cache \
15+
git \
16+
alpine-sdk \
17+
build-base
18+
19+
WORKDIR /workspaces
20+
21+
ENTRYPOINT go mod download && go test -race ./...

.github/SECURITY.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Security Policy
2+
3+
## Supported Go Versions
4+
5+
We run the tests every week scheduled with the below Go versions.
6+
7+
| Version | Supported |
8+
| :------ | :----------------: |
9+
| 1.15.15+ | :white_check_mark: |
10+
| 1.16.8+ | :white_check_mark: |
11+
| 1.17.1+ | :white_check_mark: |
12+
13+
## Code Scaning
14+
15+
[![CodeQL](https://github.com/KEINOS/dev-go/actions/workflows/codeQL-analysis.yml/badge.svg)](https://github.com/KEINOS/dev-go/actions/workflows/codeQL-analysis.yml)
16+
17+
## Security Status
18+
19+
- Check the current "[Security overview](https://github.com/KEINOS/dev-go/security)" status.
20+
21+
## Reporting a Vulnerability
22+
23+
- Please [issue](https://github.com/KEINOS/dev-go/issues) them.

0 commit comments

Comments
 (0)