This commit is contained in:
		
							
								
								
									
										37
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| --- | ||||
| kind: pipeline | ||||
| type: docker | ||||
| name: "lint" | ||||
|  | ||||
| steps: | ||||
|   - name: lint | ||||
|     image: koalaman/shellcheck-alpine:v0.8.0 | ||||
|     pull: if-not-exists | ||||
|     commands: | ||||
|       - /bin/shellcheck build.sh | ||||
|  | ||||
| --- | ||||
| kind: pipeline | ||||
| type: docker | ||||
| name: "build toolbox" | ||||
|  | ||||
| trigger: | ||||
|   event: ["tag"] | ||||
|  | ||||
| depends_on: | ||||
|   - "lint" | ||||
|  | ||||
| steps: | ||||
|   - name: "build toolbox" | ||||
|     image: "code.pztrn.name/containers/mirror/docker:26.1.1-dind" | ||||
|     pull: if-not-exists | ||||
|     privileged: true | ||||
|     environment: | ||||
|       REGISTRY: code.pztrn.name | ||||
|       REGISTRY_PROJECT: /containers/go-toolbox | ||||
|       REGISTRY_USERNAME: drone | ||||
|       REGISTRY_PASSWORD: | ||||
|         from_secret: drone_secret | ||||
|     commands: | ||||
|       - apk add --no-cache bash | ||||
|       - ./build.sh | ||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| .idea | ||||
| .vscode | ||||
| *DS_Store* | ||||
							
								
								
									
										3
									
								
								.markdownlint.json
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								.markdownlint.json
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| { | ||||
| 	"line-length": false | ||||
| } | ||||
							
								
								
									
										8
									
								
								.yamllint
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								.yamllint
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| --- | ||||
| extends: default | ||||
|  | ||||
| rules: | ||||
|   line-length: disable | ||||
|   braces: | ||||
|     min-spaces-inside: 1 | ||||
|     max-spaces-inside: 1 | ||||
							
								
								
									
										19
									
								
								Dockerfile
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										19
									
								
								Dockerfile
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| FROM debian:12.5-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/dlv.sh | ||||
| RUN /src/scripts/workers/golangci-lint.sh | ||||
| RUN /src/scripts/workers/gofumpt.sh | ||||
| RUN /src/scripts/workers/mockery.sh | ||||
| RUN /src/scripts/workers/taskfile.sh | ||||
| RUN /src/scripts/workers/go-junit-report.sh | ||||
|  | ||||
| RUN mkdir /home/container && chmod 0777 /home/container | ||||
|  | ||||
| ENV HOME=/home/container | ||||
| ENV GOPATH=/home/container/go | ||||
| ENV GOCACHE=/home/container/.cache | ||||
							
								
								
									
										39
									
								
								README.md
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								README.md
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| # Go ToolBox | ||||
|  | ||||
| Docker image with everything you might need for developing apps in Go. | ||||
|  | ||||
| **Note that for newer mac hardware you have to use Docker Desktop or amd64 virtual machine in lima/other tools!** | ||||
|  | ||||
| ## What's inside | ||||
|  | ||||
| Debian 12 (slim) is used as base image. | ||||
|  | ||||
| | Binary            | Version | Project         | Repo                                                          | | ||||
| | ----------------- | ------- | --------------- | ------------------------------------------------------------- | | ||||
| | `go`              | 1.22.2  | Go              |                                                               | | ||||
| | `golangci-lint`   | 1.57.2  | golangci-lint   | [External link](https://github.com/golangci/golangci-lint)   | | ||||
| | `gofumpt`         | 0.6.0   | gofumpt         | [External link](https://github.com/mvdan/gofumpt)            | | ||||
| | `mockery_v2`      | 2.42.2  | mockery         | [External link](https://github.com/vektra/mockery)           | | ||||
| | `task`            | 3.36.0  | taskfile        | [External link](https://github.com/go-task/task)             | | ||||
| | `go-junit-report` | 2.1.0   | go-junit-report | [External link](https://github.com/jstemmer/go-junit-report) | | ||||
| | `delve`           | 1.22.1  | delve           | [External link](https://github.com/go-delve/delve)           | | ||||
|  | ||||
| ## HOME | ||||
|  | ||||
| Home directory is `/home/container`. | ||||
|  | ||||
| ## Caching | ||||
|  | ||||
| Go's build cache resides in `/home/container/.cache`, `GOCACHE` environment variable is defined. You can mount it when needed in Dockerfile as: | ||||
|  | ||||
| ```Dockerfile | ||||
| RUN --mount=type=cache,target="$GOCACHE" go build | ||||
| ``` | ||||
|  | ||||
| ## Utilities examples | ||||
|  | ||||
| ### JUnit report generation (for Gitlab) | ||||
|  | ||||
| ```shell | ||||
| go test -v 2>&1 ./... | go-junit-report -set-exit-code > unit-report.xml | ||||
| ``` | ||||
							
								
								
									
										37
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										37
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| # build.sh checks if docker image with same sha256 exists remotely. | ||||
| # if exists, do nothing, if not, build the image | ||||
|  | ||||
| commit_sha="${DRONE_COMMIT_SHA}" | ||||
| image_path="${REGISTRY}${REGISTRY_PROJECT}" | ||||
|  | ||||
| if [ "${DRONE_TAG}" != "" ]; then | ||||
|     tag="${DRONE_TAG}" | ||||
| else | ||||
|     tag="${DRONE_COMMIT_SHA}" | ||||
| fi | ||||
|  | ||||
| # Starting Docker daemon. | ||||
| /usr/local/bin/dockerd --data-root=/var/lib/docker --max-concurrent-uploads 1 & | ||||
|  | ||||
| # Wait for it. | ||||
| echo "* Waiting for Docker daemon to start..." | ||||
| while true; do | ||||
|     if docker ps &>/dev/null; then | ||||
|         break | ||||
|     fi | ||||
| done | ||||
|  | ||||
| echo "* Logging in to registry..." | ||||
| docker login -u "${REGISTRY_USERNAME}" -p "${REGISTRY_PASSWORD}" "${REGISTRY}" | ||||
|  | ||||
| echo "* Building docker image ${image_path}:${tag}..." | ||||
|  | ||||
| if docker manifest inspect "${image_path}:${tag}" >/dev/null; then | ||||
|     echo "* Docker image ${image_path}:${tag} is already exists on remote, no rebuilt necessary." | ||||
|     exit 0 | ||||
| fi | ||||
|  | ||||
| docker build --pull --build-arg VCS_REF="${commit_sha}" --build-arg VCS_URL="${image_path}" --tag "${image_path}:${tag}" . | ||||
| docker push "${image_path}:${tag}" | ||||
							
								
								
									
										17
									
								
								scripts/helpers/arch.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										17
									
								
								scripts/helpers/arch.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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 | ||||
							
								
								
									
										4
									
								
								scripts/workers/debian.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										4
									
								
								scripts/workers/debian.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| apt update && apt upgrade -y | ||||
| apt install -y build-essential curl file git make | ||||
							
								
								
									
										7
									
								
								scripts/workers/dlv.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								scripts/workers/dlv.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| dlv_version=1.22.1 | ||||
|  | ||||
| set -xe | ||||
|  | ||||
| CGO_ENABLED=0 GOBIN=/usr/local/bin/ go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@v"$dlv_version" | ||||
							
								
								
									
										10
									
								
								scripts/workers/go-junit-report.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										10
									
								
								scripts/workers/go-junit-report.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| go_junit_report_version=2.1.0 | ||||
|  | ||||
| cd /tmp | ||||
| git clone https://github.com/jstemmer/go-junit-report.git | ||||
| cd go-junit-report || exit 1 | ||||
| git checkout "v${go_junit_report_version}" | ||||
| go build -o /usr/local/bin/go-junit-report . | ||||
| rm -rf /tmp/go-junit-report | ||||
							
								
								
									
										12
									
								
								scripts/workers/gofumpt.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										12
									
								
								scripts/workers/gofumpt.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| gofumpt_version="0.6.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 | ||||
							
								
								
									
										22
									
								
								scripts/workers/golang.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								scripts/workers/golang.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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.22.2 | ||||
|  | ||||
| # 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 | ||||
							
								
								
									
										20
									
								
								scripts/workers/golangci-lint.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										20
									
								
								scripts/workers/golangci-lint.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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.57.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}/" | ||||
							
								
								
									
										14
									
								
								scripts/workers/mockery.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								scripts/workers/mockery.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| mockery_v2_version=2.42.2 | ||||
|  | ||||
| cd /tmp || exit 1 | ||||
|  | ||||
| # mockery v2 we download from releases page | ||||
| arch=$(uname -m) | ||||
| download_url="https://github.com/vektra/mockery/releases/download/v${mockery_v2_version}/mockery_${mockery_v2_version}_Linux_${arch}.tar.gz" | ||||
| curl -L ${download_url} -o "/tmp/mockery_${arch}.tar.gz" | ||||
| mkdir /tmp/mockery_v2 | ||||
| tar xf "/tmp/mockery_${arch}.tar.gz" -C /tmp/mockery_v2 | ||||
| mv /tmp/mockery_v2/mockery /usr/local/bin/mockery_v2 | ||||
| rm -rf "/tmp/mockery_$(uname -m).tar.gz" /tmp/mockery* | ||||
							
								
								
									
										21
									
								
								scripts/workers/taskfile.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								scripts/workers/taskfile.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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.36.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 | ||||
		Reference in New Issue
	
	Block a user