From 7200d400f060dcf1eff8ea24b48246495d9f9be0 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Tue, 9 May 2023 14:16:12 +0400 Subject: [PATCH] Add common tools --- .gitignore | 1 + Dockerfile | 16 ++++++++++++++++ LICENSE | 2 +- README.md | 13 ++++++++++++- build.sh | 19 +++++++++++++++++++ scripts/helpers/arch.sh | 17 +++++++++++++++++ scripts/workers/debian.sh | 4 ++++ scripts/workers/gofumpt.sh | 12 ++++++++++++ scripts/workers/golang.sh | 22 ++++++++++++++++++++++ scripts/workers/golangci-lint.sh | 20 ++++++++++++++++++++ scripts/workers/taskfile.sh | 21 +++++++++++++++++++++ 11 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 build.sh create mode 100644 scripts/helpers/arch.sh create mode 100644 scripts/workers/debian.sh create mode 100644 scripts/workers/gofumpt.sh create mode 100644 scripts/workers/golang.sh create mode 100644 scripts/workers/golangci-lint.sh create mode 100644 scripts/workers/taskfile.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8580346 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM debian:11.6-slim + +COPY . /src +RUN for file in $(find /src -type f -name "*.sh"); do chmod +x $file; done + +RUN /src/scripts/workers/debian.sh +RUN /src/scripts/workers/golang.sh +RUN /src/scripts/workers/golangci-lint.sh +RUN /src/scripts/workers/gofumpt.sh +RUN /src/scripts/workers/taskfile.sh + +RUN mkdir /home/container && chmod 0777 /home/container + +ENV HOME=/home/container +ENV GOPATH=/home/container/go +ENV GOCACHE=/home/container/.cache diff --git a/LICENSE b/LICENSE index 2071b23..52d4b16 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2023 Vladimir Khodakov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 8c0338d..3844af2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # toolbox -Докер-тулбокс с гошными и окологошными тулзами, которые я использую для разработки. \ No newline at end of file +Докер-тулбокс с гошными и окологошными тулзами, которые я использую для разработки. + +## Что присутствует + +В качестве базового образа используется Debian 11 (slim). + +| Бинарный файл | Версия | Проект | Репозиторий | +| ----------------- |-------------| --------------- | ------------------------------------------------------------- | +| `go` | 1.20.3 | Go | | +| `golangci-lint` | 1.52.2 | golangci-lint | [Внешняя ссылка](https://github.com/golangci/golangci-lint) | +| `gofumpt` | 0.5.0 | gofumpt | [Внешняя ссылка](https://github.com/mvdan/gofumpt) | +| `task` | 3.24.0 | taskfile | [Внешняя ссылка](https://github.com/go-task/task) | diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..352ff29 --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# build.sh checks if docker image with same sha256 exists remotely. +# if exists, do nothing, if not, build the image + +commit_sha="${CI_COMMIT_SHA}" +registry_uri="${CI_PROJECT_URL}" +image_name="${CI_REGISTRY_IMAGE}" +arch="${ARCH}" + +echo "* Building docker image ${image_name}:${commit_sha}-${arch}..." + +if docker manifest inspect "${image_name}:${commit_sha}-${arch}" >/dev/null; then + echo "* Docker image ${image_name}:${commit_sha}-${arch} is already exists on remote, no rebuilt necessary." + exit 0 +fi + +docker build --pull --build-arg VCS_REF=${commit_sha} --build-arg VCS_URL=${registry_uri} --tag ${image_name}:${commit_sha}-${arch} . +docker push ${image_name}:${commit_sha}-${arch} diff --git a/scripts/helpers/arch.sh b/scripts/helpers/arch.sh new file mode 100644 index 0000000..dd25dc6 --- /dev/null +++ b/scripts/helpers/arch.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# shellcheck disable=SC2034 +# Line above disables shellcheck linters: +# * SC2043 - unused variable (this file sourced elsewhere). + +base_arch=$(uname -m) +arch="" + +if [ "$base_arch" = "x86_64" ]; then + arch=amd64 +elif [ "$base_arch" = "aarch64" ]; then + arch=arm64 +else + echo "unknown arch" + exit 1 +fi diff --git a/scripts/workers/debian.sh b/scripts/workers/debian.sh new file mode 100644 index 0000000..38e0215 --- /dev/null +++ b/scripts/workers/debian.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +apt update && apt upgrade -y +apt install -y build-essential curl file git make diff --git a/scripts/workers/gofumpt.sh b/scripts/workers/gofumpt.sh new file mode 100644 index 0000000..b70168a --- /dev/null +++ b/scripts/workers/gofumpt.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +gofumpt_version="0.5.0" + +set -xe + +cd /tmp +git clone https://github.com/mvdan/gofumpt.git +cd gofumpt || exit 1 +git checkout "v${gofumpt_version}" +go build -o /usr/local/bin/gofumpt . +rm -rf /tmp/gofumpt diff --git a/scripts/workers/golang.sh b/scripts/workers/golang.sh new file mode 100644 index 0000000..3f6a40b --- /dev/null +++ b/scripts/workers/golang.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# shellcheck disable=SC2154 +# Line above disables shellcheck linters: +# * SC2154 - variable referenced but not assigned (false positive, assigned when sourced arch.sh). + +set -xe + +go_version=1.20.3 + +# shellcheck disable=SC2086,SC2046,SC2164 +cd $(dirname ${BASH_SOURCE[0]}) +script_path=$(pwd) + +# shellcheck disable=SC1091 +source "${script_path}/../helpers/arch.sh" + +curl "https://dl.google.com/go/go${go_version}.linux-${arch}.tar.gz" -o "/tmp/go-${arch}.tar.gz" +file "/tmp/go-${arch}.tar.gz" +tar -xf "/tmp/go-${arch}.tar.gz" -C /usr/local/ +rm "/tmp/go-${arch}.tar.gz" +ln -s /usr/local/go/bin/* /usr/local/bin diff --git a/scripts/workers/golangci-lint.sh b/scripts/workers/golangci-lint.sh new file mode 100644 index 0000000..e0d9281 --- /dev/null +++ b/scripts/workers/golangci-lint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# shellcheck disable=SC2154 +# Line above disables shellcheck linters: +# * SC2154 - variable referenced but not assigned (false positive, assigned when sourced arch.sh). + +golangci_lint_version=1.52.2 + +# shellcheck disable=SC2086,SC2046,SC2164 +cd "$(dirname ${BASH_SOURCE[0]})" +script_path=$(pwd) + +# shellcheck disable=SC1091 +source "${script_path}/../helpers/arch.sh" + +curl -L "https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-linux-${arch}.tar.gz" -o "/tmp/golangci-lint-${arch}.tar.gz" +file "/tmp/golangci-lint-${arch}.tar.gz" +tar -xf "/tmp/golangci-lint-${arch}.tar.gz" -C /tmp +mv "/tmp/golangci-lint-${golangci_lint_version}-linux-${arch}/golangci-lint" /usr/local/bin +rm -rf "/tmp/golangci-lint-${arch}.tar.gz" "/tmp/golangci-lint-${golangci_lint_version}-linux-${arch}/" diff --git a/scripts/workers/taskfile.sh b/scripts/workers/taskfile.sh new file mode 100644 index 0000000..67b662f --- /dev/null +++ b/scripts/workers/taskfile.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# shellcheck disable=SC2154 +# Line above disables shellcheck linters: +# * SC2154 - variable referenced but not assigned (false positive, assigned when sourced arch.sh). + +taskfile_version=3.24.0 + +# shellcheck disable=SC2086,SC2046,SC2164 +cd "$(dirname ${BASH_SOURCE[0]})" +script_path=$(pwd) + +# shellcheck disable=SC1091 +source "${script_path}/../helpers/arch.sh" + +curl -L "https://github.com/go-task/task/releases/download/v${taskfile_version}/task_linux_${arch}.tar.gz" -o "/tmp/taskfile-${arch}.tar.gz" +file "/tmp/taskfile-${arch}.tar.gz" +tar -xf "/tmp/taskfile-${arch}.tar.gz" -C /tmp +mv "/tmp/task" /usr/local/bin +rm -rf "/tmp/*" +ls -la /usr/local/bin