-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db740e5
Showing
126 changed files
with
4,604 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# ============================================================================= | ||
# Pre Defined Variables | ||
# ============================================================================= | ||
# User provided Go version of Docker image | ||
ARG VARIANT | ||
# Default Go version. Choices: 1, 1.16, 1.15, 1.14 | ||
ARG VARIANT_DEFAULT="1.16" | ||
# 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/*" | ||
ARG LANG="${LANG:-$LANG_DEFAULT}" | ||
ARG LC_ALL="${LC_ALL:-$LC_ALL_DEFAULT}" | ||
|
||
# ============================================================================= | ||
# Main | ||
# ============================================================================= | ||
FROM golang:${VARIANT:-$VARIANT_DEFAULT}-buster | ||
|
||
# Declare user args to receive while building an image. | ||
ARG LANG | ||
ARG LC_ALL | ||
ARG INSTALL_NODE="${INSTALL_NODE:-INSTALL_NODE_DEFAULT}" | ||
ARG NODE_VERSION="${NODE_VERSION:-NODE_VERSION_DEFAULT}" | ||
|
||
ENV \ | ||
LANG="$LANG" \ | ||
LANGUAGE="$LANG" \ | ||
LC_ALL="$LC_ALL" \ | ||
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" \ | ||
DEBIAN_FRONTEND=noninteractive | ||
|
||
#RUN localedef -f UTF-8 | ||
|
||
# [Option] Install Node.js | ||
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 | ||
|
||
# Setup scripts | ||
COPY postCreateCommand.sh /postCreateCommand.sh | ||
COPY installToolsForDev.sh /installToolsForDev.sh | ||
COPY createVSCodeUser.sh /createVSCodeUser.sh | ||
|
||
# Pre-setup | ||
# ----------------------------------------------------------------------------- | ||
RUN \ | ||
echo 'ENV INFO:'; env \ | ||
# Get to latest versions of all current packages | ||
&& apt-get -y update \ | ||
&& apt-get -y upgrade --no-install-recommends \ | ||
&& apt-get autoremove -y \ | ||
# Set env path for go to .bashrc | ||
&& echo 'export PATH="/go/bin:/usr/local/go/bin:${PATH}"' >> "${HOME}/.bashrc" \ | ||
# Install tools to help dev | ||
&& /bin/bash /installToolsForDev.sh \ | ||
# Create vscode user for non-root-user usage | ||
&& /bin/bash /createVSCodeUser.sh | ||
|
||
RUN \ | ||
echo "${LC_ALL} UTF-8" >>/etc/locale.gen \ | ||
&& locale-gen "$LC_ALL" \ | ||
&& update-locale LANG="$LANG" | ||
|
||
# [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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!-- markdownlint-disable MD033 --> | ||
# Dockerfile To Develop | ||
|
||
This directory contains a Dockerfile to provide the same environment to develop the app. | ||
|
||
It includes most of the necessary packages and tools for developing Golang app. | ||
|
||
Mostly suitable 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. | ||
|
||
## Developing Online | ||
|
||
If GitHub detects this directory (`.devcontainer`) in your repo, then you will be able to develop online via [GitHub Codespaces](https://github.com/features/codespaces). | ||
|
||
Fork this repo to your GitHub account and open it via GitHub Codespaces. | ||
|
||
## Developing Locally | ||
|
||
### For VS Code + Docker + Remote Container Users | ||
|
||
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. | ||
|
||
### For Only Docker Users | ||
|
||
For non-remote-container user, simply run the below command in the root dir of this repo. | ||
|
||
```bash | ||
/bin/bash ./.devcontainer/run-devcontainer.sh | ||
``` | ||
|
||
- Tested env | ||
- macOS Catalina (OSX 10.15.7) | ||
- Docker version: 20.10.5, build 55c4c88 | ||
|
||
## File Description | ||
|
||
- [aliases.sh](aliases.sh) ... Bash alias file to abbreviate type the path to the test script. | ||
- [cobra.yaml](cobra.yaml) ... Default `cobra` command Settings. Used for `$ cobra add ..` | ||
- [createVSCodeUser.sh](createVSCodeUser.sh) ... Bash script that creates `vscode` user in the container. | ||
- [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. | ||
- [installToolsForDev.sh](installToolsForDev.sh) ... Bash script that installs the required commands for tests and other helpful commands for development. (For Debian-like OS) | ||
- [postCreateCommand.sh](postCreateCommand.sh) ... Initialization script that runs after the container and the VSCode server is up. Needs to rebuild container if any change made as well. | ||
- [README.md](README.md) ... This file. ;-) | ||
- [run-devcontainer.sh](run-devcontainer.sh) ... Bash script for non-remote-container user. It will pull, build image and runs the container. | ||
- [welcome.sh](welcome.sh) ... Bash script to display the basic info and TIPs to use in the first shell login. | ||
|
||
Note: For VSCode + Remote Containers users, if you make any changes to the above files, you need to rebuild the container. | ||
|
||
## Required Storage | ||
|
||
- You will need around 1.6GB in size. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# ----------------------------------------------------------------------------- | ||
# Aliases for Useful Shell Script | ||
# ----------------------------------------------------------------------------- | ||
|
||
alias build-app='cd "$PATH_DIR_ROOT_REPO"; ./bin/build-app.sh' | ||
alias run-all='cd "$PATH_DIR_ROOT_REPO"; ./.github/run-tests-merge.sh' | ||
alias run-coverage='cd "$PATH_DIR_ROOT_REPO"; ./.github/run-tests-coverage.sh' | ||
alias run-lint='cd "$PATH_DIR_ROOT_REPO"; ./.github/run-tests-lint.sh' | ||
alias update-docs='cd "$PATH_DIR_ROOT_REPO"; ./.github/update-docs.sh' | ||
alias update-readme='cd "$PATH_DIR_ROOT_REPO"; ./.github/update-docs.sh' | ||
alias welcome='cd "$PATH_DIR_ROOT_REPO"; ${HOME}/.welcome.sh' | ||
alias qiitrans='go run "$PATH_DIR_ROOT_REPO"/src/main ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
echo '===============================================================================' | ||
echo ' Create VSCode User' | ||
echo '===============================================================================' | ||
|
||
set -eu | ||
|
||
echo "ENV INFO:" | ||
env | ||
|
||
USERNAME="vscode" | ||
USERGROUP="vscode" | ||
USER_UID=1000 | ||
USER_GID=1000 | ||
|
||
if ! id -u "${USERNAME}" >/dev/null 2>&1; then | ||
# Create group | ||
groupadd -f --gid "$USER_GID" "$USERGROUP" | ||
|
||
# Create user | ||
useradd -s /bin/bash -d "/home/${USERNAME}" --uid "$USER_UID" --gid "$USER_GID" -m "$USERNAME" | ||
|
||
# Add add sudo support for non-root user | ||
echo "$USERNAME" ALL=\(root\) NOPASSWD:ALL >/etc/sudoers.d/"$USERNAME" | ||
chmod 0440 /etc/sudoers.d/"$USERNAME" | ||
export EXISTING_NON_ROOT_USER="${USERNAME}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# ============================================================================= | ||
# devcontainer.env defines ENV variables when run. | ||
# | ||
# Same as: `docker run --env-file $(pwd)/devcontainer.env` | ||
# Note that you need to rebuild the container if you change the values. | ||
# ============================================================================= | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Host's Env Variables | ||
# コンテナに渡すホスト側の環境変数(システム環境変数)です。 | ||
# ----------------------------------------------------------------------------- | ||
LANG | ||
LC_ALL | ||
|
||
# 以下の環境変数はホスト側の環境変数で DeepL のアクセストークンを予め設定してください | ||
DEEPL_API_KEY | ||
|
||
# ----------------------------------------------------------------------------- | ||
# User Defined Variables. | ||
# ----------------------------------------------------------------------------- | ||
FOO="bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "Go", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { | ||
// Go version: 1, 1.16, 1.15, 1.14 | ||
"VARIANT": "1.16" | ||
} | ||
}, | ||
"runArgs": [ | ||
"--cap-add=SYS_PTRACE", | ||
"--security-opt", | ||
"seccomp=unconfined", | ||
"--env-file", | ||
"./.devcontainer/devcontainer.env" | ||
], | ||
// Set VSCode settings | ||
"settings": { | ||
"go.gopath": "/go", | ||
"go.goroot": "/usr/local/go", | ||
"go.lintFlags": [ | ||
"--enable-all", | ||
"--new" | ||
], | ||
"go.toolsGopath": "/go/bin", | ||
"go.toolsManagement.checkForUpdates": "proxy", | ||
"go.useLanguageServer": true, | ||
"shellformat.path": "/go/bin/shfmt", | ||
"terminal.integrated.profiles.windows": { | ||
"PowerShell -NoProfile": { | ||
"source": "PowerShell", | ||
"args": [ | ||
"-NoProfile" | ||
] | ||
} | ||
}, | ||
"terminal.integrated.profiles.linux": { | ||
"zsh (login)": { | ||
"path": "/bin/bash", | ||
"args": [] | ||
} | ||
}, | ||
"notebook.experimental.useMarkdownRenderer": true, | ||
"shellformat.useEditorConfig": true | ||
}, | ||
// VSCode extension ID to be installed | ||
"extensions": [ | ||
"davidanson.vscode-markdownlint", | ||
"editorconfig.editorconfig", | ||
"foxundermoon.shell-format", | ||
"github.github-vscode-theme", | ||
"github.vscode-pull-request-github", | ||
"golang.Go", | ||
"ms-ceintl.vscode-language-pack-ja", | ||
"ms-ceintl.vscode-language-pack-es", | ||
"ms-azuretools.vscode-docker", | ||
"ms-vsonline.vsonline", | ||
"tamasfe.even-better-toml", | ||
"znck.grammarly" | ||
], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "/bin/bash /postCreateCommand.sh;", | ||
// Comment in or out to connect as a root or non-root user. See https://aka.ms/vscode-remote/containers/non-root. | ||
//"remoteUser": "vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
echo '===============================================================================' | ||
echo ' Install Helper Commands for Development' | ||
echo '===============================================================================' | ||
|
||
GoVersion=$(go version | grep -o -E "([0-9]+\.){1}[0-9]+(\.[0-9]+)?" | head -n1) | ||
GoVersionMinor=$(echo "$GoVersion" | awk -F. '{printf "%d", $2}') | ||
GoVersionRequireMin=16 | ||
|
||
NameRepo="QiiTrans" | ||
|
||
echo "Current Go version is: ${GoVersion} (Minosr ver is: ${GoVersionMinor})" | ||
|
||
if [ "$GoVersionMinor" -lt "$GoVersionRequireMin" ]; then | ||
echo >&2 "Minimum Go version does not satisfy. Required minimum Go version: 1.${GoVersionRequireMin}" | ||
exit 1 | ||
fi | ||
|
||
set -eu | ||
|
||
echo | ||
echo '* Installing additional apt packages' | ||
# Install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies | ||
apt-get -y install --no-install-recommends \ | ||
apt-utils \ | ||
\ | ||
apt-transport-https \ | ||
ca-certificates \ | ||
curl \ | ||
dialog \ | ||
iproute2 \ | ||
git \ | ||
gnupg2 \ | ||
htop \ | ||
jq \ | ||
less \ | ||
libc6 \ | ||
libgcc1 \ | ||
libgssapi-krb5-2 \ | ||
libicu[0-9][0-9] \ | ||
liblttng-ust0 \ | ||
libstdc++6 \ | ||
locales \ | ||
lsb-release \ | ||
lsof \ | ||
man-db \ | ||
nano \ | ||
ncdu \ | ||
net-tools \ | ||
openssh-client \ | ||
procps \ | ||
psmisc \ | ||
ripgrep \ | ||
rsync \ | ||
sudo \ | ||
tree \ | ||
unzip \ | ||
vim-tiny \ | ||
wget \ | ||
xz-utils \ | ||
zip \ | ||
zlib1g | ||
|
||
# Install libssl1.1 if available | ||
if [[ -n $(apt-cache --names-only search ^libssl1.1$) ]]; then | ||
apt-get -y install libssl1.1 | ||
fi | ||
|
||
# Install appropriate version of libssl1.0.x if available | ||
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') | ||
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then | ||
if [[ -n $(apt-cache --names-only search ^libssl1.0.2$) ]]; then | ||
# Debian 9 | ||
apt-get -y install libssl1.0.2 | ||
elif [[ -n $(apt-cache --names-only search ^libssl1.0.0$) ]]; then | ||
# Ubuntu 18.04, 16.04, earlier | ||
apt-get -y install libssl1.0.0 | ||
fi | ||
fi | ||
|
||
echo | ||
echo '* Installing tools in go' | ||
go install "github.com/msoap/go-carpet@latest" | ||
go install "mvdan.cc/sh/v3/cmd/shfmt@latest" | ||
go install "github.com/tenntenn/goplayground/cmd/gp@latest" | ||
go install "github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest" | ||
go install "github.com/nicksnyder/go-i18n/v2/goi18n@latest" | ||
go install "mvdan.cc/gofumpt@latest" | ||
go install "golang.org/x/tools/gopls@latest" | ||
go install "github.com/spf13/cobra/cobra@latest" | ||
go install "github.com/golang/mock/mockgen@latest" | ||
go install "github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest" | ||
go install "github.com/ramya-rao-a/go-outline@latest" | ||
go install "github.com/go-delve/delve/cmd/dlv@latest" | ||
go install "honnef.co/go/tools/cmd/staticcheck@latest" | ||
go install "github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest" | ||
|
||
echo | ||
echo '* Installing shellcheck' | ||
# ShellCheck - Static analyzer and formatter for shell script | ||
# Note: Install the latest shellcheck. See: https://github.com/koalaman/shellcheck/issues/704 | ||
url_download="https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.$(uname -m).tar.xz" && | ||
timestamp="$(date +%Y%m%d%H%M%S)" && | ||
path_tmp_dir=$(mktemp "/tmp/${NameRepo}-${timestamp}.tmp.XXXXXX") && | ||
echo "TEMP PATH: ${path_tmp_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" "${GOPATH:?Undefined}/bin/shellcheck" && | ||
shellcheck --version && | ||
rm -r "$path_tmp_dir" | ||
|
||
echo | ||
echo '* Installing golangci-lint' | ||
# golangci-lint - The fast Go linters runner. Version=latest | ||
# binary will be installed under: $(go env GOPATH)/bin/golangci-lint | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" && | ||
golangci-lint --version |
Oops, something went wrong.