Skip to content

Commit

Permalink
refactor: repository and source structure (PR #25)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
KEINOS committed Nov 26, 2021
1 parent 85c5321 commit 86e3e71
Show file tree
Hide file tree
Showing 54 changed files with 1,935 additions and 1,616 deletions.
146 changes: 18 additions & 128 deletions .devcontainer/Dockerfile
@@ -1,128 +1,18 @@
# =============================================================================
# Pre Defined Variables
# =============================================================================
# User provided Go version of Docker image
ARG VARIANT
# Default Go version. Choices: 1, 1.15, 1.14
ARG VARIANT_DEFAULT="1"
# Default Language
ARG LC_ALL_DEFAULT='en_US.utf8'
ARG LANG_DEFAULT='en_US.utf8'
# Default Node.js settings
ARG INSTALL_NODE_DEFAULT="false"
ARG NODE_VERSION_DEFAULT="lts/*"

# =============================================================================
# Define Dockerfile.
#
# For image contents see:
# https://github.com/microsoft/vscode-dev-containers/tree/v0.145.1/containers/go/.devcontainer/base.Dockerfile
# =============================================================================
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT:-$VARIANT_DEFAULT}

# Declare user args to receive while building an image.
ARG LANG
ARG LC_ALL
ARG INSTALL_NODE
ARG NODE_VERSION

ENV \
LANG="${LANG:-$LANG_DEFAULT}" \
LC_ALL="${LC_ALL:-$LC_ALL_DEFAULT}" \
PATH="/usr/local/go/bin:${PATH}" \
# Enforce go module mode
GO111MODULE='on' \
# Fix: https://github.com/microsoft/vscode-dev-containers/issues/51
SHELL="/bin/bash"

#RUN localedef -f UTF-8

# [Option] Install Node.js
ARG INSTALL_NODE="${INSTALL_NODE:-INSTALL_NODE_DEFAULT}"
ARG NODE_VERSION="${NODE_VERSION:-NODE_VERSION_DEFAULT}"
RUN if [ "${INSTALL_NODE}" = "true" ]; then \
echo 'Installing Node.js'; \
su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; \
fi

# Bash script file to run right after the container was created.
# See: "postCreateCommand" section in "devcontainer.json" and "postCreateCommand.sh"
# file.
COPY postCreateCommand.sh /postCreateCommand.sh

# Install additional OS packages.
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
# The `rg` is a string search command from files. ex) rg ./cmd foo
ripgrep \
# Directory tree viewer for documentation.
tree \
# xz to untar xz compressed files
xz-utils \
# missing locales
locales

# ShellCheck - Static analyzer and formatter for shell script
# Note: Install the latest shellcheck. See: https://github.com/koalaman/shellcheck/issues/704
RUN url_download="https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.$(uname -m).tar.xz" \
&& path_tmp_dir="$(pwd)/tmp_install_dir" \
&& wget -P "${path_tmp_dir}/" "$url_download"\
&& tar xvf ${path_tmp_dir}/shellcheck* -C "${path_tmp_dir}/" \
&& cp "${path_tmp_dir}/shellcheck-latest/shellcheck" "$(dirname $(which tree))/shellcheck" \
# Smoke test
&& shellcheck --version \
&& rm -r "$path_tmp_dir"

# golangci-lint - The fast Go linters runner. Version=latest
# binary will be installed under: $(go env GOPATH)/bin/golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin \
# Smoke test
&& golangci-lint --version

# Install anything else needed to go get
RUN go get -u -v \
# gopls (language server)
# `gopls` will install the packages in the URL below as well.
# https://github.com/golang/vscode-go/blob/master/docs/tools.md#table-of-contents
"golang.org/x/tools/gopls@latest" \
# go-carpet (Cover area checker)
"github.com/msoap/go-carpet" \
# shfmt (shellformat) is a shell script linter
"mvdan.cc/sh/v3/cmd/shfmt" \
# gp enables to share go files over Go Playground
"github.com/tenntenn/goplayground/cmd/gp" \
# gomarkdoc generates documentation in markdown
"github.com/princjef/gomarkdoc/cmd/gomarkdoc" \
#"github.com/rogpeppe/godef" \
# -------------------------------------------------------------------------
# irregular install (Download source and build)
# -------------------------------------------------------------------------
&& cd "${GOPATH}/pkg/mod" \
&& go get -v -d \
# gocode and gocode-modules is no-good to install as module
"github.com/stamblerre/gocode" \
# cobra (sub-command creation)
"github.com/spf13/cobra" \
# gomock
"github.com/golang/mock/gomock" \
# gocode and gocode-modules
&& cd ${GOPATH}/pkg/mod/github.com/stamblerre/gocode* \
&& go build -o "${GOPATH}/bin/gocode-gomod" . \
# cobra command
&& cd ${GOPATH}/pkg/mod/github.com/spf13/cobra*/cobra \
&& go build -o "${GOPATH}/bin/cobra" . \
# mockgen
&& cd ${GOPATH}/pkg/mod/github.com/golang/mock*/mockgen \
&& go install \
# List bin files
&& echo "- List dir: ${GOPATH}/bin" && ls -l "${GOPATH}/bin"

# Miscellaneous
RUN \
# Set path for go
echo 'export PATH="/go/bin:/usr/local/go/bin:${PATH}"' >> "${HOME}/.bashrc"

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
# [Choice] https://github.com/KEINOS/VSCode-Dev-Container-Go/pkgs/container/vscode-dev-container-go
ARG VARIANT="latest"

# -----------------------------------------------------------------------------
# Main Stage
# -----------------------------------------------------------------------------
# ghcr.io/keinos/vscode-dev-container-go is an Alpine-based container image which
# provides a VSCode development environment over Docker. This image is weekly
# scanned for vulnerability and security with Synk, Dockle and Trivy. For detals
# see: ./README.md
FROM ghcr.io/keinos/vscode-dev-container-go:${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
# USER root
# RUN apk add --no-cache <your-package-list-here>

USER vscode
RUN cd /tmp && go install golang.org/x/lint/golint@latest
20 changes: 8 additions & 12 deletions .devcontainer/README.md
Expand Up @@ -3,24 +3,20 @@

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.

It includes most of the necessary packages and tools for developing Golang app. Aiming to provide the same environment to develop the app.
It includes:

- 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.
- Latest Go version.
- Common packages and tools for developing Golang app and shell scripts.
- [Installed tools and Go modules](https://github.com/KEINOS/VSCode-Dev-Container-Go/blob/main/image_info.txt) | VSCode-Dev-Container-Go | KEINOS @ GitHub
- Weekly updated.

## Developing Online

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).
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)

## VS Code + Docker User

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`".

After a while, you'll get most of the environment needed to develop and debug.

## File Description

- [cobra.yaml](cobra.yaml): Default `cobra` command Settings. Used for `$ cobra add ..`
- [devcontainer.env](devcontainer.env): ENV variables to be loaded once when the container's created.
- [devcontainer.json](devcontainer.json): VSCode Extensions to be installed and env settings.
- [Dockerfile](Dockerfile): Debian 10 (buster) based Golang development container.
- [postCreateCommand.sh](postCreateCommand.sh): Initialization script that runs after the container and the VSCode server is up.
- [README.md](README.md): This file. ;-)
- [welcome.sh](welcome.sh): Bash script to display the basic info and TIPs to use in the first shell login.
26 changes: 0 additions & 26 deletions .devcontainer/devcontainer.env

This file was deleted.

63 changes: 31 additions & 32 deletions .devcontainer/devcontainer.json
@@ -1,49 +1,48 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/go
{
"name": "Go",
"name": "Go Dev",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Go version: 1, 1.15, 1.14
"VARIANT": "1.15",
// Options
"INSTALL_NODE": "false",
"NODE_VERSION": "lts/*"
// Choices: https://github.com/KEINOS/VSCode-Dev-Container-Go/pkgs/container/vscode-dev-container-go
"VARIANT": "latest"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt", "seccomp=unconfined",
"--env-file",".devcontainer/devcontainer.env"
],
// Set VSCode settings
"runArgs": [
"--rm",
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],

// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"go.lintFlags": ["--enable-all", "--new"],
"go.toolsGopath": "/go/bin",
"go.toolsManagement.checkForUpdates": "proxy",
"go.useLanguageServer": true,
"terminal.integrated.shell.linux": "/bin/bash",
"terminal.integrated.shellArgs.linux": ["-l"]
"terminal.integrated.profiles.linux": {
"bash (login)": {
"path": "/bin/bash",
"args": []
}
},
"shellformat.path": "/go/bin/shfmt"
},

// VSCode extension ID to be installed
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go",
"editorconfig.editorconfig",
"foxundermoon.shell-format",
"ms-ceintl.vscode-language-pack-ja",
"ms-ceintl.vscode-language-pack-es",
"ms-azuretools.vscode-docker",
"ms-vsonline.vsonline",
"github.github-vscode-theme",
"github.vscode-pull-request-github",
"davidanson.vscode-markdownlint"
"foxundermoon.shell-format"
],

// 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": "/bin/bash /postCreateCommand.sh;"
"postCreateCommand": "go mod download",

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
//"remoteUser": "vscode"
}
// Comment out to connect as root to debug container.
// "remoteUser": "root"
}
28 changes: 0 additions & 28 deletions .devcontainer/postCreateCommand.sh

This file was deleted.

13 changes: 0 additions & 13 deletions .devcontainer/welcome.sh

This file was deleted.

21 changes: 21 additions & 0 deletions .github/Dockerfile
@@ -0,0 +1,21 @@
# =============================================================================
# Test Container for Vaious Go Versions
# =============================================================================
# Default version
ARG VARIANT="1.15-alpine"

# -----------------------------------------------------------------------------
# Main Stage
# -----------------------------------------------------------------------------
FROM golang:${VARIANT}

ENV GO111MODULE=on

RUN apk add --no-cache \
git \
alpine-sdk \
build-base

WORKDIR /workspaces

ENTRYPOINT go mod download && go test -race ./...
23 changes: 23 additions & 0 deletions .github/SECURITY.md
@@ -0,0 +1,23 @@
# Security Policy

## Supported Go Versions

We run the tests every week scheduled with the below Go versions.

| Version | Supported |
| :------ | :----------------: |
| 1.15.15+ | :white_check_mark: |
| 1.16.8+ | :white_check_mark: |
| 1.17.1+ | :white_check_mark: |

## Code Scaning

[![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)

## Security Status

- Check the current "[Security overview](https://github.com/KEINOS/dev-go/security)" status.

## Reporting a Vulnerability

- Please [issue](https://github.com/KEINOS/dev-go/issues) them.

0 comments on commit 86e3e71

Please sign in to comment.