Skip to content

Commit

Permalink
chore: Bump alpine to 3.21 (#279)
Browse files Browse the repository at this point in the history
* chore: Bump alpine to 3.21

* chore: Remove go patch version from go.mod

* refactor: Scripts

* chore: Remove go patch version form go mod

* docs: Update readme
  • Loading branch information
obalunenko authored Dec 20, 2024
1 parent 5372434 commit 47bc437
Show file tree
Hide file tree
Showing 57 changed files with 500 additions and 409 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM --platform=$BUILDPLATFORM golang:1.23.4-alpine3.20 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23.4-alpine3.21 AS builder

ARG APK_BASH_VERSION=~5
ARG APK_GIT_VERSION=~2
ARG APK_MAKE_VERSION=~4
ARG APK_OPENSSH_VERSION=~9
ARG APK_GCC_VERSION=~13
ARG APK_GCC_VERSION=~14
ARG APK_BUILDBASE_VERSION=~0
ARG APK_CA_CERTIFICATES_VERSION=20240705-r0
ARG APK_CA_CERTIFICATES_VERSION=20241010-r0
ARG APK_BINUTILS_VERSION=~2

RUN apk add --no-cache \
Expand Down Expand Up @@ -41,12 +41,12 @@ RUN --mount=type=bind,source=./scripts,target=./scripts \
GOOS=$TARGETOS GOARCH=$TARGETARCH make install-tools


FROM golang:1.23.4-alpine3.20 AS releaser
FROM golang:1.23.4-alpine3.21 AS releaser

ARG APK_BASH_VERSION=~5
ARG APK_BUILDBASE_VERSION=~0
ARG APK_GIT_VERSION=~2
ARG APK_DOCKER_CLI_VERSION=~26
ARG APK_DOCKER_CLI_VERSION=~27
ARG APK_DOCKER_CLI_COMPOSE_VERSION=~2
ARG APK_DOCKER_CLI_BUILDX_VERSION=~0
ARG APK_OPENSSH_VERSION=~9
Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@ docker pull ghcr.io/obalunenko/go-tools:latest

### Go base image

The base image is built on top of the official image [golang:1.23.1-alpine3.20](https://hub.docker.com/_/golang) and includes the following tools:
The base image is built on top of the official image [golang:1.23.4-alpine3.21](https://hub.docker.com/_/golang) and includes the following tools:


##### Below is a full manifest of the tools available


| Tool | Version | Description |
|------------------------------------------------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [go-enum](https://github.com/abice/go-enum) | v0.6.0 | An enum generator for go |
| [buf](https://github.com/bufbuild/buf) | v1.48.0 | The buf CLI is the best tool for working with Protocol Buffers |
| [coverbadger](https://github.com/obalunenko/coverbadger) | v1.4.0 | Generate coverage badge images for Markdown files using Go |
| [enumer](https://github.com/alvaroloes/enumer) | v1.1.2 | A Go tool to auto generate methods for your enums |
| [gocov](https://github.com/axw/gocov) | v1.1.0 | Coverage testing tool for The Go Programming Language |
| [svu](https://github.com/caarlos0/svu) | v2.2.0 | Semantic Version Util |
| [swagger](https://github.com/go-swagger/go-swagger) | v0.31.0 | Client/Server from OpenAPI docs generation tool |
| [golangci-lint](https://github.com/golangci/golangci-lint) | v1.60.3 | Fast linters Runner for Go |
| [goreleaser](https://github.com/goreleaser/goreleaser) | v2.2.0 | Deliver Go binaries as fast and easily as possible |
| [fiximports](https://golang.org/x/tools/cmd/fiximports) | v0.28.0 | The fiximports command fixes import declarations to use the canonical import path for packages that have an "import comment" as defined by https://golang.org/s/go14customimport. |
| [go-enum](https://github.com/abice/go-enum) | v0.6.0 | An enum generator for go |
| [gocov](https://github.com/axw/gocov) | v1.2.1 | Coverage testing tool for The Go Programming Language |
| [gocov-html](https://github.com/matm/gocov-html) | v1.4.0 | Make pretty HTML output from gocov, a coverage testing tool for Go |
| [goveralls](https://github.com/mattn/goveralls) | v0.0.12 | Go integration for Coveralls.io continuous code coverage tracking system. |
| [tparse](https://github.com/mfridman/tparse) | v0.14.0 | CLI tool for summarizing go test output. Pipe friendly. CI/CD friendly. |
| [coverbadger](https://github.com/obalunenko/coverbadger) | v1.4.0 | Generate coverage badge images for Markdown files using Go |
| [gofumpt](https://mvdan.cc/gofumpt) | v0.7.0 | A stricter gofmt |
| [goimports](https://golang.org/x/tools/cmd/goimports) | v0.28.0 | Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones |
| [golangci-lint](https://github.com/golangci/golangci-lint) | v1.62.2 | Fast linters Runner for Go |
| [goose](https://github.com/pressly/goose/v3/cmd/goose) | v3.24.0 | A database migration tool |
| [goreadme](https://github.com/posener/goreadme) | v1.4.2 | Generate readme file from Go doc |
| [goose](https://github.com/pressly/goose/v3/cmd/goose) | v3.22.0 | A database migration tool |
| [swag](github.com/swaggo/swag/cmd/swag) | v1.16.3 | Automatically generate RESTful API documentation with Swagger 2.0 for Go |
| [pkgsite](https://golang.org/x/pkgsite/cmd/pkgsite) | v0.0.0-20240905030440-6b577b411ef5 | Pkgsite extracts and generates documentation for Go programs. It runs as a web server and presents the documentation as a web page. |
| [fiximports](https://golang.org/x/tools/cmd/fiximports) | v0.24.0 | The fiximports command fixes import declarations to use the canonical import path for packages that have an "import comment" as defined by https://golang.org/s/go14customimport. |
| [goimports](https://golang.org/x/tools/cmd/goimports) | v0.24.0 | Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones |
| [stringer](https://golang.org/x/tools/cmd/stringer) | v0.24.0 | Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface. |
| [govulncheck](https://golang.org/x/vuln/cmd/govulncheck) | v1.1.3 | Govulncheck reports known vulnerabilities that affect Go code. |
| [goreleaser](https://github.com/goreleaser/goreleaser) | v2.5.0 | Deliver Go binaries as fast and easily as possible |
| [gotestsum](https://gotest.tools/gotestsum) | v1.12.0 | 'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results. |
| [gofumpt](https://mvdan.cc/gofumpt) | v0.7.0 | A stricter gofmt |
| [goveralls](https://github.com/mattn/goveralls) | v0.0.12 | Go integration for Coveralls.io continuous code coverage tracking system. |
| [govulncheck](https://golang.org/x/vuln/cmd/govulncheck) | v1.1.3 | Govulncheck reports known vulnerabilities that affect Go code. |
| [pkgsite](https://golang.org/x/pkgsite/cmd/pkgsite) | v0.0.0-20241216215327-06c6edf28e6c | Pkgsite extracts and generates documentation for Go programs. It runs as a web server and presents the documentation as a web page. |
| [stringer](https://golang.org/x/tools/cmd/stringer) | v0.28.0 | Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface. |
| [svu](https://github.com/caarlos0/svu) | v2.2.0 | Semantic Version Util |
| [swag](github.com/swaggo/swag/cmd/swag) | v1.16.4 | Automatically generate RESTful API documentation with Swagger 2.0 for Go |
| [swagger](https://github.com/go-swagger/go-swagger) | v0.31.0 | Client/Server from OpenAPI docs generation tool |
| [tparse](https://github.com/mfridman/tparse) | v0.16.0 | CLI tool for summarizing go test output. Pipe friendly. CI/CD friendly. |


## How to Use
Expand Down
72 changes: 46 additions & 26 deletions scripts/install/vendored-tools.sh
Original file line number Diff line number Diff line change
@@ -1,77 +1,97 @@
#!/bin/bash

# Enable strict error handling
set -eu

# Script metadata
SCRIPT_NAME="$(basename "$0")"
REPO_ROOT="$(pwd)"
TOOLS_DIR="${REPO_ROOT}/tools"

echo "${SCRIPT_NAME} is running... "

# Change directory to TOOLS_DIR
cd "${TOOLS_DIR}" || exit 1

# Function to check the status of the last executed command
function check_status() {
# first param is error message to print in case of error
local error_message="$1"
if [ $? -ne 0 ]; then
if [ -n "$1" ]; then
echo "$1"
if [ -n "$error_message" ]; then
echo "[ERROR]: $error_message"
fi

# Exit 255 to pass signal to xargs to abort process with code 1, in other cases xargs will complete with 0.
# Exit with code 255 to signal xargs to abort the process, otherwise it will return 0
exit 255
fi
}

# Function to install a dependency
function install_dep() {
dep=$1
local dep=$1

bin_out=$GOBIN/$(echo $dep | awk 'BEGIN { FS="/" } {for (i=NF; i>0; i--) if ($i !~ /^v[0-9]/) {print $i;exit}}')
# Extract the binary output path
bin_out="$GOBIN/$(echo "$dep" | awk 'BEGIN { FS="/" } { for (i=NF; i>0; i--) if ($i !~ /^v[0-9]/) { print $i; exit } }')"

echo "[INFO]: Going to build ${dep} - ${bin_out}"
# Determine tools module
tools_module="$(grep '^module ' go.mod | awk '{print $2}')"

go build -mod=vendor -o "${bin_out}" "${dep}"
# Extract the version of the dependency
raw_version=$(go list -mod=readonly -m -f '{{if not .Indirect}}{{.Path}} {{.Version}}{{end}}' all | grep -v "^${tools_module}")
version=$(echo "$raw_version" | awk '{print $2}')

check_status "[FAIL]: build [${dep}] failed!"
echo "[INFO]: Building ${dep}@${version} - Output: ${bin_out}"

# Build the dependency
go build -mod=vendor -o "${bin_out}" "${dep}"
check_status "Build failed for dependency [${dep}@${version}]!"

echo "[SUCCESS]: build [${dep}] finished."
echo "[SUCCESS]: Successfully built [${dep}@${version}]."
}

# Export functions for use in subshells (xargs)
export -f install_dep
export -f check_status

# Function to install dependencies listed in the go.mod file
function install_deps() {
local tools_module

# Extract the tools module name
tools_module="$(grep '^module ' go.mod | awk '{print $2}')"
echo "[INFO]: Installing dependencies for module: ${tools_module}"

echo "[INFO]: Running install_deps for ${tools_module}"

# List and install dependencies using xargs for parallel execution
go list -e -f '{{ join .Imports "\n" }}' -tags="tools" "${tools_module}" |
xargs -n 1 -P 0 -I {} bash -c 'install_dep "$@"' _ {}
xargs -n 1 -P 0 -I {} bash -c 'install_dep "$@"' _ {}
}

# Function to iterate over tools and install them
function install_tools() {
declare -a tools_list

temp_file=./tools_list.txt # создаем временный файл
declare -a tools_list
local temp_file=./tools_list.txt

touch "$temp_file" # создаем временный файл

ls -d ${TOOLS_DIR}/*/ > "$temp_file" # сохраняем вывод команды в файл
# Create a temporary file to store tool directories
touch "$temp_file"
ls -d "${TOOLS_DIR}"/*/ > "$temp_file"

# Read all tool directories into an array
while IFS= read -r t; do
tools_list+=("$t")
done < "$temp_file" # читаем файл в массив
done < "$temp_file"

rm "$temp_file" # удаляем временный файл
# Clean up the temporary file
rm "$temp_file"

# Loop through each tool and install its dependencies
for t in "${tools_list[@]}"; do
echo "In loop - current ${t}"
echo "[INFO]: Processing tool: ${t}"

tool=$(basename "${t}")
cd "${TOOLS_DIR}/${tool}" || exit 1
install_deps
cd - || exit 1
cd - > /dev/null || exit 1
done
}


install_tools
# Start the tool installation process
install_tools
78 changes: 31 additions & 47 deletions scripts/sync-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,66 @@

set -eu

# Constants
SCRIPT_NAME="$(basename "$0")"
SCRIPT_DIR="$(dirname "$0")"
REPO_ROOT="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)"
TOOLS_DIR="${REPO_ROOT}/tools"

echo "${SCRIPT_NAME} is running... "
echo "${SCRIPT_NAME} is running..."

function sync_vendor() {
# Function to sync the vendor directory
sync_vendor() {
echo "Syncing vendor..."
rm -rf vendor
rm -rf ./vendor
go mod tidy
go mod vendor
}

function check_status() {
# first param is error message to print in case of error
if [ $? -ne 0 ]; then
if [ -n "$1" ]; then
echo "$1"
fi

# Exit 255 to pass signal to xargs to abort process with code 1, in other cases xargs will complete with 0.
exit 255
fi
}

function sync_dep() {
dep=$1

echo "[INFO]: Going to sync ${dep}"

sync_vendor

check_status "[FAIL]: sync [${dep}] failed!"

echo "[SUCCESS]: sync [${dep}] finished."
}

export -f sync_dep
export -f check_status
export -f sync_vendor

function sync_deps() {
# Function to sync dependencies
sync_deps() {
local tools_module
tools_module="$(grep '^module ' go.mod | awk '{print $2}')"

echo "[INFO]: Running install_deps for ${tools_module}"

go list -e -f '{{ join .Imports "\n" }}' -tags="tools" "${tools_module}" |
xargs -n 1 -P 0 -I {} bash -c 'sync_dep "$@"' _ {}
sync_vendor
}

function sync_tools() {
declare -a tools_list
# Function to sync all tools in the TOOLS_DIR
sync_tools() {
local tools_list=()

temp_file=./tools_list.txt # создаем временный файл
# Temporary file to store the list of tools
local temp_file="./tools_list.txt"
touch "${temp_file}"

touch "$temp_file" # создаем временный файл
# Save tools directories into the temporary file
ls -d "${TOOLS_DIR}"/*/ > "${temp_file}"

ls -d ${TOOLS_DIR}/*/ > "$temp_file" # сохраняем вывод команды в файл
# Read tools into an array
while IFS= read -r tool_dir; do
tools_list+=("${tool_dir}")
done < "${temp_file}"

while IFS= read -r t; do
tools_list+=("$t")
done < "$temp_file" # читаем файл в массив
# Remove the temporary file
rm "${temp_file}"

rm "$temp_file" # удаляем временный файл
# Loop through each tool directory and sync dependencies
for tool_path in "${tools_list[@]}"; do
echo "[INFO]: Processing tool directory: ${tool_path}"

for t in "${tools_list[@]}"; do
echo "In loop - current ${t}"
local tool
tool=$(basename "${tool_path}")

tool=$(basename "${t}")
cd "${TOOLS_DIR}/${tool}" || exit 1
sync_deps
cd - || exit 1
cd - > /dev/null || exit 1
done
}

# Start the tool synchronization process
sync_tools

echo "${SCRIPT_NAME} done."
echo "${SCRIPT_NAME} finished."
2 changes: 1 addition & 1 deletion tools/buf/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module buf

go 1.23.4
go 1.23

require github.com/bufbuild/buf v1.48.0

Expand Down
2 changes: 1 addition & 1 deletion tools/coverbadger/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module coverbadger

go 1.23.1
go 1.23

require github.com/obalunenko/coverbadger v1.4.0

Expand Down
2 changes: 1 addition & 1 deletion tools/enumer/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module enumer

go 1.23.1
go 1.23

require github.com/alvaroloes/enumer v1.1.2

Expand Down
2 changes: 1 addition & 1 deletion tools/fiximports/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module fiximports

go 1.23.1
go 1.23

require golang.org/x/tools v0.28.0
2 changes: 1 addition & 1 deletion tools/go-enum/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go-enum

go 1.23.1
go 1.23

require github.com/abice/go-enum v0.6.0

Expand Down
2 changes: 1 addition & 1 deletion tools/gocov-html/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module gocov-html

go 1.23.1
go 1.23

require github.com/matm/gocov-html v1.4.0

Expand Down
Loading

0 comments on commit 47bc437

Please sign in to comment.