Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor repository #25

Merged
merged 18 commits into from
Nov 26, 2021
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
146 changes: 18 additions & 128 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Loading