├── 1.24 ├── base │ ├── .dockerignore │ ├── download.sh │ ├── Makefile │ ├── rootfs │ │ ├── builder.sh │ │ └── common.sh │ └── Dockerfile ├── main │ ├── .dockerignore │ ├── Makefile │ ├── Dockerfile │ └── rootfs │ │ └── builder.sh └── Makefile.COMMON ├── 1.25 ├── base │ ├── .dockerignore │ ├── download.sh │ ├── Makefile │ ├── rootfs │ │ ├── builder.sh │ │ └── common.sh │ └── Dockerfile ├── main │ ├── .dockerignore │ ├── Makefile │ ├── Dockerfile │ └── rootfs │ │ └── builder.sh └── Makefile.COMMON ├── .gitignore ├── MAINTAINERS.md ├── main ├── go.mod ├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── golangci-lint.yml ├── go.sum ├── .dockerignore ├── CODE_OF_CONDUCT.md ├── SECURITY.md ├── .editorconfig ├── .golangci.yml ├── NOTICE ├── CONTRIBUTING.md ├── cmd └── builder-bumper │ ├── main_test.go │ └── main.go ├── Makefile ├── .circleci └── config.yml ├── scripts └── bump_version.sh ├── README.md └── LICENSE /1.24/base/.dockerignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | -------------------------------------------------------------------------------- /1.24/main/.dockerignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | -------------------------------------------------------------------------------- /1.25/base/.dockerignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | -------------------------------------------------------------------------------- /1.25/main/.dockerignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | builder-bumper/builder-bumper 2 | /docker-images 3 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | * Steve Durrheimer 2 | -------------------------------------------------------------------------------- /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prometheus/golang-builder/HEAD/main -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/prometheus/golang-builder 2 | 3 | go 1.24.0 4 | 5 | require golang.org/x/mod v0.30.0 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" 4 | directory: "/" 5 | schedule: 6 | interval: "monthly" 7 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= 2 | golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= 3 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .editorconfig 2 | .git 3 | AUTHORS.md 4 | CONTRIBUTING.md 5 | LICENSE 6 | Makefile 7 | NOTICE 8 | README.md 9 | arm/ 10 | powerpc/ 11 | mips/ 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Prometheus Community Code of Conduct 2 | 3 | Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting a security issue 2 | 3 | The Prometheus security policy, including how to report vulnerabilities, can be 4 | found here: 5 | 6 | 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.sh] 12 | indent_size = 2 13 | 14 | [Makefile] 15 | indent_style = tab 16 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | exclusions: 3 | rules: 4 | - linters: 5 | - errcheck 6 | # Taken from the default exclusions in v1. 7 | text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked 8 | 9 | version: "2" 10 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Prometheus Golang builder Docker images 2 | Copyright 2013-2016 The Prometheus Authors 3 | 4 | 5 | The following components are used in this product: 6 | 7 | Docker 8 | https://github.com/docker/docker 9 | Copyright 2013-2016 Docker, Inc. 10 | Licensed under the Apache License, Version 2.0 11 | 12 | OSXCross 13 | https://github.com/tpoechtrager/osxcross 14 | Copyright 2014-2015 by Thomas Poechtrager 15 | Licensed under the GNU License, Version 2 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull request, 6 | addressing (with `@...`) the maintainer of this repository (see 7 | [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | -------------------------------------------------------------------------------- /1.24/base/download.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Description: Download a file and verify SHA256. 4 | 5 | set -u -o pipefail 6 | 7 | if [[ $# -ne 2 ]] ; then 8 | echo "usage: $(basename $0) " 9 | exit 1 10 | fi 11 | 12 | url="$1" 13 | sum="$2" 14 | 15 | outfile=$(mktemp) 16 | 17 | if ! curl -s -f -L "${url}" -o "${outfile}" ; then 18 | echo "ERROR: Failed to download ${url} to ${outfile}" 1>&2 19 | rm "${outfile}" 20 | exit 1 21 | fi 22 | 23 | if ! echo "${sum} ${outfile}" | sha256sum -c - > /dev/null ; then 24 | echo "ERROR: Checksum failed" 1>&2 25 | rm "${outfile}" 26 | exit 1 27 | fi 28 | 29 | echo "${outfile}" 30 | -------------------------------------------------------------------------------- /1.25/base/download.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Description: Download a file and verify SHA256. 4 | 5 | set -u -o pipefail 6 | 7 | if [[ $# -ne 2 ]] ; then 8 | echo "usage: $(basename $0) " 9 | exit 1 10 | fi 11 | 12 | url="$1" 13 | sum="$2" 14 | 15 | outfile=$(mktemp) 16 | 17 | if ! curl -s -f -L "${url}" -o "${outfile}" ; then 18 | echo "ERROR: Failed to download ${url} to ${outfile}" 1>&2 19 | rm "${outfile}" 20 | exit 1 21 | fi 22 | 23 | if ! echo "${sum} ${outfile}" | sha256sum -c - > /dev/null ; then 24 | echo "ERROR: Checksum failed" 1>&2 25 | rm "${outfile}" 26 | exit 1 27 | fi 28 | 29 | echo "${outfile}" 30 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Pre-submit tests 2 | on: 3 | pull_request: 4 | paths: 5 | - "go.sum" 6 | - "go.mod" 7 | - "**.go" 8 | - ".github/workflows/ci.yml" 9 | 10 | permissions: # added using https://github.com/step-security/secure-repo 11 | contents: read 12 | 13 | jobs: 14 | unit-tests: 15 | permissions: 16 | contents: read # for actions/checkout to fetch code 17 | pull-requests: read # for golangci/golangci-lint-action to fetch pull requests 18 | name: Run unit tests 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - run: make --always-make test-unit 23 | -------------------------------------------------------------------------------- /1.24/base/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | include ../Makefile.COMMON 15 | 16 | SUFFIX := 17 | -------------------------------------------------------------------------------- /1.25/base/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | include ../Makefile.COMMON 15 | 16 | SUFFIX := 17 | -------------------------------------------------------------------------------- /1.24/main/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | include ../Makefile.COMMON 15 | 16 | build: 17 | @echo ">> building $(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" 18 | @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" --build-arg PROM_OSX_SDK_URL=${PROM_OSX_SDK_URL} . 19 | @docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)" 20 | @docker save -o "$(IMAGE_DIR)/$(IMAGE_FILE)-$(VERSION)-$(DIRNAME)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 21 | -------------------------------------------------------------------------------- /1.25/main/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | include ../Makefile.COMMON 15 | 16 | build: 17 | @echo ">> building $(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" 18 | @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" --build-arg PROM_OSX_SDK_URL=${PROM_OSX_SDK_URL} . 19 | @docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)$(SUFFIX)" "$(REPOSITORY)/$(NAME):$(VERSION)-$(DIRNAME)" 20 | @docker save -o "$(IMAGE_DIR)/$(IMAGE_FILE)-$(VERSION)-$(DIRNAME)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 21 | -------------------------------------------------------------------------------- /cmd/builder-bumper/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "reflect" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func TestNewGoVersion(t *testing.T) { 10 | tests := []struct { 11 | input string 12 | want *goVersion 13 | }{ 14 | {"1.22.1", &goVersion{22, 1}}, 15 | {"1.20.5", &goVersion{20, 5}}, 16 | {"1.19.0", &goVersion{19, 0}}, 17 | {"1.25.3", &goVersion{25, 3}}, 18 | {"1.18.10", &goVersion{18, 10}}, 19 | } 20 | 21 | for _, tt := range tests { 22 | t.Run("Parsing "+tt.input, func(t *testing.T) { 23 | got := newGoVersion(tt.input) 24 | 25 | if !reflect.DeepEqual(got, tt.want) { 26 | t.Errorf("newGoVersion(%q) = %v, want %v", tt.input, got, tt.want) 27 | } 28 | }) 29 | } 30 | } 31 | 32 | func TestAvailableVersions(t *testing.T) { 33 | t.Run("Test that available versions scan correctly removes 'go' prefix", func(t *testing.T) { 34 | got := getAvailableVersions() 35 | 36 | if len(got) == 0 { 37 | t.Fatalf("Expected some versions, got none") 38 | } 39 | 40 | for _, v := range got { 41 | if strings.Contains(v.String(), "go") { 42 | t.Errorf("Version still contains 'go' prefix: %v", v) 43 | } 44 | } 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /1.24/Makefile.COMMON: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | REPOSITORY := quay.io/prometheus 15 | NAME := golang-builder 16 | BRANCH := $(shell git rev-parse --abbrev-ref HEAD) 17 | SUFFIX ?= -$(subst /,-,$(BRANCH)) 18 | VERSION := 1.24.11 19 | DIRNAME := $(shell basename $(CURDIR)) 20 | IMAGE_DIR ?= .build 21 | IMAGE := $(REPOSITORY)/$(NAME) 22 | IMAGE_FILE := $(subst /,-,$(IMAGE)) 23 | 24 | build: 25 | @echo ">> building $(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" 26 | @docker build -t "$(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" . 27 | @docker tag "$(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 28 | @docker save -o "$(IMAGE_DIR)/$(IMAGE_FILE)-$(VERSION)-$(DIRNAME)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 29 | 30 | .PHONY: build 31 | -------------------------------------------------------------------------------- /1.25/Makefile.COMMON: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | REPOSITORY := quay.io/prometheus 15 | NAME := golang-builder 16 | BRANCH := $(shell git rev-parse --abbrev-ref HEAD) 17 | SUFFIX ?= -$(subst /,-,$(BRANCH)) 18 | VERSION := 1.25.5 19 | DIRNAME := $(shell basename $(CURDIR)) 20 | IMAGE_DIR ?= .build 21 | IMAGE := $(REPOSITORY)/$(NAME) 22 | IMAGE_FILE := $(subst /,-,$(IMAGE)) 23 | 24 | build: 25 | @echo ">> building $(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" 26 | @docker build -t "$(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" . 27 | @docker tag "$(IMAGE):$(VERSION)-$(DIRNAME)$(SUFFIX)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 28 | @docker save -o "$(IMAGE_DIR)/$(IMAGE_FILE)-$(VERSION)-$(DIRNAME)" "$(IMAGE):$(VERSION)-$(DIRNAME)" 29 | 30 | .PHONY: build 31 | -------------------------------------------------------------------------------- /1.24/base/rootfs/builder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2016 The Prometheus Authors 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | source /common.sh 17 | 18 | # Building binaries for the specified platforms 19 | # The `build` Makefile target is required 20 | declare -a goarchs 21 | goarchs=(${goarchs[@]:-linux\/amd64}) 22 | for goarch in "${goarchs[@]}" 23 | do 24 | goos=${goarch%%/*} 25 | arch=${goarch##*/} 26 | 27 | if [[ "${arch}" =~ ^armv.*$ ]]; then 28 | goarm=${arch##*v} 29 | arch="arm" 30 | 31 | echo "# ${goos}-${arch}v${goarm}" 32 | prefix=".build/${goos}-${arch}v${goarm}" 33 | mkdir -p "${prefix}" 34 | GOARM=${goarm} GOOS=${goos} GOARCH=${arch} make PREFIX="${prefix}" build 35 | else 36 | echo "# ${goos}-${arch}" 37 | prefix=".build/${goos}-${arch}" 38 | mkdir -p "${prefix}" 39 | GOOS=${goos} GOARCH=${arch} make PREFIX="${prefix}" build 40 | fi 41 | done 42 | 43 | exit 0 44 | -------------------------------------------------------------------------------- /1.25/base/rootfs/builder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2016 The Prometheus Authors 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | source /common.sh 17 | 18 | # Building binaries for the specified platforms 19 | # The `build` Makefile target is required 20 | declare -a goarchs 21 | goarchs=(${goarchs[@]:-linux\/amd64}) 22 | for goarch in "${goarchs[@]}" 23 | do 24 | goos=${goarch%%/*} 25 | arch=${goarch##*/} 26 | 27 | if [[ "${arch}" =~ ^armv.*$ ]]; then 28 | goarm=${arch##*v} 29 | arch="arm" 30 | 31 | echo "# ${goos}-${arch}v${goarm}" 32 | prefix=".build/${goos}-${arch}v${goarm}" 33 | mkdir -p "${prefix}" 34 | GOARM=${goarm} GOOS=${goos} GOARCH=${arch} make PREFIX="${prefix}" build 35 | else 36 | echo "# ${goos}-${arch}" 37 | prefix=".build/${goos}-${arch}" 38 | mkdir -p "${prefix}" 39 | GOOS=${goos} GOARCH=${arch} make PREFIX="${prefix}" build 40 | fi 41 | done 42 | 43 | exit 0 44 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | REPOSITORY := quay.io/prometheus 15 | NAME := golang-builder 16 | VARIANTS ?= base main 17 | VERSION ?= 1.25 18 | 19 | .PHONY: all 20 | all: build test-unit 21 | 22 | .PHONY: build 23 | build: 24 | @./build.sh "$(VERSION)" "$(VARIANTS)" 25 | 26 | .PHONY: test-unit 27 | test-unit: 28 | go test ./... -v 29 | 30 | .PHONY: tag 31 | tag: 32 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-base" "$(REPOSITORY)/$(NAME):base" 33 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):latest" 34 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):main" 35 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):arm" 36 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):powerpc" 37 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):mips" 38 | docker tag "$(REPOSITORY)/$(NAME):$(VERSION)-main" "$(REPOSITORY)/$(NAME):s390x" 39 | 40 | .PHONY: push 41 | push: 42 | docker push -a "$(REPOSITORY)/$(NAME)" 43 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This action is synced from https://github.com/prometheus/prometheus 3 | name: golangci-lint 4 | on: 5 | push: 6 | paths: 7 | - "go.sum" 8 | - "go.mod" 9 | - "**.go" 10 | - "scripts/errcheck_excludes.txt" 11 | - ".github/workflows/golangci-lint.yml" 12 | - ".golangci.yml" 13 | pull_request: 14 | 15 | permissions: # added using https://github.com/step-security/secure-repo 16 | contents: read 17 | 18 | jobs: 19 | golangci: 20 | permissions: 21 | contents: read # for actions/checkout to fetch code 22 | pull-requests: read # for golangci/golangci-lint-action to fetch pull requests 23 | name: lint 24 | runs-on: ubuntu-latest 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 28 | with: 29 | persist-credentials: false 30 | - name: Install Go 31 | uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 32 | with: 33 | go-version: 1.25.x 34 | - name: Install snmp_exporter/generator dependencies 35 | run: sudo apt-get update && sudo apt-get -y install libsnmp-dev 36 | if: github.repository == 'prometheus/snmp_exporter' 37 | - name: Get golangci-lint version 38 | id: golangci-lint-version 39 | run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT 40 | - name: Lint 41 | uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 42 | with: 43 | args: --verbose 44 | version: ${{ steps.golangci-lint-version.outputs.version }} 45 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2.1 3 | 4 | executors: 5 | golang: 6 | docker: 7 | - image: cimg/go:1.25 8 | vm: 9 | machine: 10 | image: ubuntu-2204:current 11 | 12 | jobs: 13 | build: 14 | executor: vm 15 | 16 | parameters: 17 | version: 18 | type: string 19 | 20 | steps: 21 | - checkout 22 | - run: docker info 23 | - run: make VARIANTS=base VERSION=<< parameters.version >> 24 | - run: make VARIANTS=main VERSION=<< parameters.version >> 25 | - run: docker images 26 | - run: ls -l docker-images 27 | - persist_to_workspace: 28 | root: . 29 | paths: 30 | - docker-images 31 | 32 | 33 | publish: 34 | executor: golang 35 | 36 | steps: 37 | - checkout 38 | - setup_remote_docker 39 | - attach_workspace: 40 | at: . 41 | - run: for i in docker-images/*; do docker load -i "$i" ; done 42 | - run: docker images 43 | - run: make tag 44 | - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io 45 | - run: make push 46 | 47 | bump_version: 48 | executor: golang 49 | 50 | steps: 51 | - checkout 52 | - run: ./scripts/bump_version.sh 53 | 54 | workflows: 55 | version: 2 56 | golang-builder: 57 | jobs: 58 | - build: 59 | matrix: 60 | parameters: 61 | version: 62 | - "1.24" 63 | - "1.25" 64 | filters: 65 | tags: 66 | only: /.*/ 67 | - publish: 68 | context: org-context 69 | requires: 70 | - build 71 | filters: 72 | branches: 73 | only: master 74 | nightly: 75 | triggers: 76 | - schedule: 77 | cron: "11 12 * * *" 78 | filters: 79 | branches: 80 | only: 81 | - master 82 | jobs: 83 | - bump_version: 84 | context: org-context 85 | -------------------------------------------------------------------------------- /scripts/bump_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Setting -x is absolutely forbidden as it could leak the GitHub token. 4 | set -uo pipefail 5 | 6 | GITHUB_MAIL="${GITHUB_MAIL:-prometheus-team@googlegroups.com}" 7 | GITHUB_USER="${GITHUB_USER:-prombot}" 8 | BRANCH_NAME="${BRANCH_NAME:-bump_version}" 9 | DEFAULT_BRANCH="${DEFAULT_BRANCH:-$(git remote show origin | awk -F': ' '$1 == " HEAD branch" {print $2}')}" 10 | 11 | ORG="${ORG:-prometheus}" 12 | REPO="${REPO:-golang-builder}" 13 | 14 | # GITHUB_TOKEN required scope: repo.repo_public 15 | GITHUB_TOKEN="${GITHUB_TOKEN:-}" 16 | if [[ -z ${GITHUB_TOKEN} ]]; then 17 | echo -e "\e[31mGitHub token (GITHUB_TOKEN) not set. Terminating.\e[0m" 18 | exit 1 19 | fi 20 | 21 | if ! GO111MODULE=on go run ./cmd/builder-bumper; then 22 | exit 1 23 | fi 24 | 25 | ## Internal functions 26 | github_api() { 27 | local url 28 | url="https://api.github.com/${1}" 29 | shift 1 30 | curl --retry 5 --silent --fail -u "${GITHUB_USER}:${GITHUB_TOKEN}" "${url}" "$@" 31 | } 32 | 33 | if [[ -n "$(git status --porcelain)" ]]; then 34 | # Check if a PR is already opened for the branch. 35 | prLink=$(github_api "repos/${ORG}/${REPO}/pulls?state=open&head=${ORG}:${BRANCH_NAME}" | jq '.[0].html_url') 36 | if [[ "${prLink}" != "null" ]]; then 37 | echo "Pull request already opened for ${BRANCH_NAME} branch: ${prLink}" 38 | echo "Either close it or merge it before running this script again!" 39 | exit 1 40 | fi 41 | 42 | git checkout -b "${BRANCH_NAME}" 43 | git config user.email "${GITHUB_MAIL}" 44 | git config user.name "${GITHUB_USER}" 45 | git add . 46 | git commit -s -m "Bump Go version" 47 | 48 | # Delete the remote branch in case it was merged but not deleted. 49 | # stdout and stderr are redirected to /dev/null otherwise git-push could leak the token in the logs. 50 | git push --quiet "https://${GITHUB_TOKEN}:@github.com/${ORG}/${REPO}" ":${BRANCH_NAME}" 1>/dev/null 2>&1 51 | if git push --quiet "https://${GITHUB_TOKEN}:@github.com/${ORG}/${REPO}" --set-upstream "${BRANCH_NAME}" 1>/dev/null 2>&1; then 52 | post_json="$(printf '{"title":"Bump Go version","base":"%s","head":"%s","body":""}' "${DEFAULT_BRANCH}" "${BRANCH_NAME}")" 53 | github_api "repos/${ORG}/${REPO}/pulls" \ 54 | -X POST \ 55 | --data "${post_json}" 56 | else 57 | echo "Failed to push changes to ${BRANCH_NAME}!" 58 | exit 1 59 | fi 60 | fi 61 | -------------------------------------------------------------------------------- /1.24/base/rootfs/common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2016 The Prometheus Authors 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eo pipefail 17 | 18 | # This is a Makefile based building processus 19 | [[ ! -e "./Makefile" ]] && echo "Error: A Makefile with 'build' and 'test' targets must be present into the root of your source files" && exit 1 20 | 21 | usage() { 22 | base="$(basename "$0")" 23 | cat < 7 | 8 | RUN \ 9 | apt-get update && apt-get install -y --no-install-recommends \ 10 | clang \ 11 | cmake \ 12 | libc6-dev \ 13 | libxml2-dev \ 14 | lzma-dev \ 15 | mingw-w64 \ 16 | patch \ 17 | xz-utils \ 18 | crossbuild-essential-arm64 linux-libc-dev-arm64-cross \ 19 | crossbuild-essential-armel linux-libc-dev-armel-cross \ 20 | crossbuild-essential-armhf linux-libc-dev-armhf-cross \ 21 | crossbuild-essential-i386 linux-libc-dev-i386-cross \ 22 | crossbuild-essential-mips linux-libc-dev-mips-cross \ 23 | crossbuild-essential-mipsel linux-libc-dev-mipsel-cross \ 24 | crossbuild-essential-mips64 linux-libc-dev-mips64-cross \ 25 | crossbuild-essential-mips64el linux-libc-dev-mips64el-cross \ 26 | crossbuild-essential-powerpc linux-libc-dev-powerpc-cross \ 27 | crossbuild-essential-ppc64el linux-libc-dev-ppc64el-cross \ 28 | crossbuild-essential-s390x linux-libc-dev-s390x-cross \ 29 | gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross \ 30 | libc6-riscv64-cross linux-libc-dev-riscv64-cross \ 31 | && rm -rf /var/lib/apt/lists/* \ 32 | && mkdir -p /tmp/osxcross 33 | 34 | COPY --from=rustbuilder /usr/local/cargo/bin/rcodesign /usr/local/bin/rcodesign 35 | 36 | ARG PROM_OSX_SDK_URL 37 | ENV OSXCROSS_PATH=/usr/osxcross \ 38 | OSXCROSS_REV=ff8d100f3f026b4ffbe4ce96d8aac4ce06f1278b \ 39 | SDK_VERSION=14 \ 40 | DARWIN_VERSION=23 \ 41 | OSX_VERSION_MIN=10.13 42 | 43 | WORKDIR /tmp/osxcross 44 | RUN \ 45 | curl -s -f -L "https://codeload.github.com/tpoechtrager/osxcross/tar.gz/${OSXCROSS_REV}" \ 46 | | tar -C /tmp/osxcross --strip=1 -xzf - \ 47 | && curl -s -f -L "${PROM_OSX_SDK_URL}/MacOSX${SDK_VERSION}.sdk.tar.xz" -o "tarballs/MacOSX${SDK_VERSION}.sdk.tar.xz" \ 48 | && UNATTENDED=yes JOBS=2 ./build.sh \ 49 | && mv target "${OSXCROSS_PATH}" \ 50 | && rm -rf /tmp/osxcross "/usr/osxcross/SDK/MacOSX${SDK_VERSION}.sdk/usr/share/man" 51 | 52 | WORKDIR /app 53 | 54 | ENV PATH $OSXCROSS_PATH/bin:$PATH 55 | 56 | COPY rootfs / 57 | -------------------------------------------------------------------------------- /1.25/main/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:latest as rustbuilder 2 | 3 | RUN cargo install --git https://github.com/indygreg/apple-platform-rs --branch main --bin rcodesign apple-codesign 4 | 5 | FROM quay.io/prometheus/golang-builder:1.25-base 6 | MAINTAINER The Prometheus Authors 7 | 8 | RUN \ 9 | apt-get update && apt-get install -y --no-install-recommends \ 10 | clang \ 11 | cmake \ 12 | libc6-dev \ 13 | libxml2-dev \ 14 | lzma-dev \ 15 | mingw-w64 \ 16 | patch \ 17 | xz-utils \ 18 | crossbuild-essential-arm64 linux-libc-dev-arm64-cross \ 19 | crossbuild-essential-armel linux-libc-dev-armel-cross \ 20 | crossbuild-essential-armhf linux-libc-dev-armhf-cross \ 21 | crossbuild-essential-i386 linux-libc-dev-i386-cross \ 22 | crossbuild-essential-mips linux-libc-dev-mips-cross \ 23 | crossbuild-essential-mipsel linux-libc-dev-mipsel-cross \ 24 | crossbuild-essential-mips64 linux-libc-dev-mips64-cross \ 25 | crossbuild-essential-mips64el linux-libc-dev-mips64el-cross \ 26 | crossbuild-essential-powerpc linux-libc-dev-powerpc-cross \ 27 | crossbuild-essential-ppc64el linux-libc-dev-ppc64el-cross \ 28 | crossbuild-essential-s390x linux-libc-dev-s390x-cross \ 29 | gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross \ 30 | libc6-riscv64-cross linux-libc-dev-riscv64-cross \ 31 | && rm -rf /var/lib/apt/lists/* \ 32 | && mkdir -p /tmp/osxcross 33 | 34 | COPY --from=rustbuilder /usr/local/cargo/bin/rcodesign /usr/local/bin/rcodesign 35 | 36 | ARG PROM_OSX_SDK_URL 37 | ENV OSXCROSS_PATH=/usr/osxcross \ 38 | OSXCROSS_REV=ff8d100f3f026b4ffbe4ce96d8aac4ce06f1278b \ 39 | SDK_VERSION=14 \ 40 | DARWIN_VERSION=23 \ 41 | OSX_VERSION_MIN=10.13 42 | 43 | WORKDIR /tmp/osxcross 44 | RUN \ 45 | curl -s -f -L "https://codeload.github.com/tpoechtrager/osxcross/tar.gz/${OSXCROSS_REV}" \ 46 | | tar -C /tmp/osxcross --strip=1 -xzf - \ 47 | && curl -s -f -L "${PROM_OSX_SDK_URL}/MacOSX${SDK_VERSION}.sdk.tar.xz" -o "tarballs/MacOSX${SDK_VERSION}.sdk.tar.xz" \ 48 | && UNATTENDED=yes JOBS=2 ./build.sh \ 49 | && mv target "${OSXCROSS_PATH}" \ 50 | && rm -rf /tmp/osxcross "/usr/osxcross/SDK/MacOSX${SDK_VERSION}.sdk/usr/share/man" 51 | 52 | WORKDIR /app 53 | 54 | ENV PATH $OSXCROSS_PATH/bin:$PATH 55 | 56 | COPY rootfs / 57 | -------------------------------------------------------------------------------- /1.24/base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM goreleaser/goreleaser:v2.6.1 as goreleaser 2 | 3 | FROM debian:bookworm 4 | MAINTAINER The Prometheus Authors 5 | 6 | COPY download.sh /bin/download.sh 7 | 8 | ENV YQ_VERSION 4.45.1 9 | ENV YQ_URL https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 10 | ENV YQ_SUM 654d2943ca1d3be2024089eb4f270f4070f491a0610481d128509b2834870049 11 | 12 | RUN \ 13 | apt-get update \ 14 | && apt-get full-upgrade -y \ 15 | && apt-get install -y --no-install-recommends \ 16 | build-essential \ 17 | bzr \ 18 | ca-certificates \ 19 | curl \ 20 | git \ 21 | gnupg \ 22 | jq \ 23 | libsnmp-dev \ 24 | make \ 25 | unzip \ 26 | yamllint \ 27 | openssh-client \ 28 | && git config --system --add safe.directory "*" \ 29 | && curl -s -f -L https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /etc/apt/nodesource.asc \ 30 | && echo "deb [signed-by=/etc/apt/nodesource.asc] https://deb.nodesource.com/node_22.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \ 31 | && apt-get update \ 32 | && apt-get install -y --no-install-recommends nodejs \ 33 | && yq_file=$(/bin/download.sh ${YQ_URL} ${YQ_SUM}) \ 34 | && mv -v ${yq_file} /bin/yq \ 35 | && chmod 0755 /bin/yq \ 36 | && rm -rf /var/lib/apt/lists/* 37 | 38 | ENV GOLANG_VERSION 1.24.11 39 | ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz 40 | ENV GOLANG_DOWNLOAD_SHA256 bceca00afaac856bc48b4cc33db7cd9eb383c81811379faed3bdbc80edb0af65 41 | 42 | RUN go_file=$(/bin/download.sh ${GOLANG_DOWNLOAD_URL} ${GOLANG_DOWNLOAD_SHA256}) \ 43 | && tar -C /usr/local -xzf ${go_file} \ 44 | && rm -v ${go_file} 45 | 46 | ENV GOPATH /go 47 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 48 | 49 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 50 | WORKDIR $GOPATH 51 | 52 | COPY rootfs / 53 | 54 | COPY --from=goreleaser /usr/bin/goreleaser /usr/bin/goreleaser 55 | 56 | ENV GOTESTSUM_VERSION 1.12.0 57 | ENV GOTESTSUM_URL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz 58 | ENV GOTESTSUM_SUM a50939fcfdfbc052bf97ff074c7fd8bcde1745be4a365d12d79311c293f12ae7 59 | 60 | RUN gotestsum_file=$(/bin/download.sh ${GOTESTSUM_URL} ${GOTESTSUM_SUM}) \ 61 | && tar -C /usr/local -xzf ${gotestsum_file} gotestsum \ 62 | && rm ${gotestsum_file} 63 | 64 | VOLUME /app 65 | WORKDIR /app 66 | ENTRYPOINT ["/builder.sh"] 67 | -------------------------------------------------------------------------------- /1.25/base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM goreleaser/goreleaser:v2.6.1 as goreleaser 2 | 3 | FROM debian:bookworm 4 | MAINTAINER The Prometheus Authors 5 | 6 | COPY download.sh /bin/download.sh 7 | 8 | ENV YQ_VERSION 4.45.1 9 | ENV YQ_URL https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 10 | ENV YQ_SUM 654d2943ca1d3be2024089eb4f270f4070f491a0610481d128509b2834870049 11 | 12 | RUN \ 13 | apt-get update \ 14 | && apt-get full-upgrade -y \ 15 | && apt-get install -y --no-install-recommends \ 16 | build-essential \ 17 | bzr \ 18 | ca-certificates \ 19 | curl \ 20 | git \ 21 | gnupg \ 22 | jq \ 23 | libsnmp-dev \ 24 | make \ 25 | unzip \ 26 | yamllint \ 27 | openssh-client \ 28 | && git config --system --add safe.directory "*" \ 29 | && curl -s -f -L https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /etc/apt/nodesource.asc \ 30 | && echo "deb [signed-by=/etc/apt/nodesource.asc] https://deb.nodesource.com/node_22.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \ 31 | && apt-get update \ 32 | && apt-get install -y --no-install-recommends nodejs \ 33 | && yq_file=$(/bin/download.sh ${YQ_URL} ${YQ_SUM}) \ 34 | && mv -v ${yq_file} /bin/yq \ 35 | && chmod 0755 /bin/yq \ 36 | && rm -rf /var/lib/apt/lists/* 37 | 38 | ENV GOLANG_VERSION 1.25.5 39 | ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz 40 | ENV GOLANG_DOWNLOAD_SHA256 9e9b755d63b36acf30c12a9a3fc379243714c1c6d3dd72861da637f336ebb35b 41 | 42 | RUN go_file=$(/bin/download.sh ${GOLANG_DOWNLOAD_URL} ${GOLANG_DOWNLOAD_SHA256}) \ 43 | && tar -C /usr/local -xzf ${go_file} \ 44 | && rm -v ${go_file} 45 | 46 | ENV GOPATH /go 47 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 48 | 49 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 50 | WORKDIR $GOPATH 51 | 52 | COPY rootfs / 53 | 54 | COPY --from=goreleaser /usr/bin/goreleaser /usr/bin/goreleaser 55 | 56 | ENV GOTESTSUM_VERSION 1.12.0 57 | ENV GOTESTSUM_URL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz 58 | ENV GOTESTSUM_SUM a50939fcfdfbc052bf97ff074c7fd8bcde1745be4a365d12d79311c293f12ae7 59 | 60 | RUN gotestsum_file=$(/bin/download.sh ${GOTESTSUM_URL} ${GOTESTSUM_SUM}) \ 61 | && tar -C /usr/local -xzf ${gotestsum_file} gotestsum \ 62 | && rm ${gotestsum_file} 63 | 64 | VOLUME /app 65 | WORKDIR /app 66 | ENTRYPOINT ["/builder.sh"] 67 | -------------------------------------------------------------------------------- /1.24/main/rootfs/builder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2016 The Prometheus Authors 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | source /common.sh 17 | 18 | # Building binaries for the specified platforms 19 | # The `build` Makefile target is required 20 | declare -a goarchs 21 | goarchs=(${goarchs[@]:-linux\/amd64}) 22 | for goarch in "${goarchs[@]}" 23 | do 24 | goos=${goarch%%/*} 25 | arch=${goarch##*/} 26 | goarm='' cc='gcc' cxx='g++' extra_args='' 27 | 28 | case "${goos}" in 29 | windows) 30 | case "${arch}" in 31 | 386) cc='i686-w64-mingw32-gcc' cxx='i686-w64-mingw32-g++' ;; 32 | amd64) cc='x86_64-w64-mingw32-gcc' cxx='x86_64-w64-mingw32-g++' ;; 33 | esac 34 | ;; 35 | darwin) 36 | case "${arch}" in 37 | amd64) cc='o64-clang' cxx='o64-clang++' extra_args='LD_LIBRARY_PATH=/usr/osxcross/lib' ;; 38 | arm64) cc='oa64-clang' cxx='oa64-clang++' extra_args='LD_LIBRARY_PATH=/usr/osxcross/lib' ;; 39 | esac 40 | ;; 41 | linux) 42 | case "${arch}" in 43 | 386) cc='i686-linux-gnu-gcc' cxx='i686-linux-gnu-g++' ;; 44 | arm64) cc='aarch64-linux-gnu-gcc' cxx='aarch64-linux-gnu-g++' ;; 45 | armv*) goarm="${arch##*v}" 46 | if [[ "${goarm}" == "7" ]]; then 47 | cc='arm-linux-gnueabihf-gcc' cxx='arm-linux-gnueabihf-g++' 48 | else 49 | cc='arm-linux-gnueabi-gcc' cxx='arm-linux-gnueabi-g++' 50 | fi 51 | ;; 52 | mips) cc='mips-linux-gnu-gcc' cxx='mips-linux-gnu-g++' ;; 53 | mips64) cc='mips64-linux-gnuabi64-gcc' cxx='mips64-linux-gnuabi64-g++' ;; 54 | mipsle) cc='mipsel-linux-gnu-gcc' cxx='mipsel-linux-gnu-g++' ;; 55 | mips64le) cc='mips64el-linux-gnuabi64-gcc' cxx='mips64el-linux-gnuabi64-g++' ;; 56 | ppc64) cc='powerpc-linux-gnu-gcc' cxx='powerpc-linux-gnu-g++' ;; 57 | ppc64le) cc='powerpc64le-linux-gnu-gcc' cxx='powerpc64le-linux-gnu-g++' ;; 58 | riscv64) cc='riscv64-linux-gnu-gcc' cxx='riscv64-linux-gnu-g++' ;; 59 | s390x) cc='gcc-s390x-linux-gnu' cxx='g++-s390x-linux-gnu' ;; 60 | esac 61 | ;; 62 | netbsd) 63 | case "${arch}" in 64 | 386) cc='i686-linux-gnu-gcc' cxx='i686-linux-gnu-g++' ;; 65 | esac 66 | ;; 67 | esac 68 | 69 | echo "# ${goos}-${arch}" 70 | prefix=".build/${goos}-${arch}" 71 | mkdir -p "${prefix}" 72 | 73 | echo "# Building with: CC='${cc}' CXX='${cxx}'" 74 | if [[ -n "${goarm}" ]]; then 75 | CC="${cc}" CXX="${cxx}" GOOS="${goos}" GOARCH="${arch}" GOARM="${goarm}" \ 76 | make PREFIX="${prefix}" build ${extra_args} 77 | else 78 | CC="${cc}" CXX="${cxx}" GOOS="${goos}" GOARCH="${arch}" \ 79 | make PREFIX="${prefix}" build ${extra_args} 80 | fi 81 | done 82 | 83 | exit 0 84 | -------------------------------------------------------------------------------- /1.25/main/rootfs/builder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2016 The Prometheus Authors 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | source /common.sh 17 | 18 | # Building binaries for the specified platforms 19 | # The `build` Makefile target is required 20 | declare -a goarchs 21 | goarchs=(${goarchs[@]:-linux\/amd64}) 22 | for goarch in "${goarchs[@]}" 23 | do 24 | goos=${goarch%%/*} 25 | arch=${goarch##*/} 26 | goarm='' cc='gcc' cxx='g++' extra_args='' 27 | 28 | case "${goos}" in 29 | windows) 30 | case "${arch}" in 31 | 386) cc='i686-w64-mingw32-gcc' cxx='i686-w64-mingw32-g++' ;; 32 | amd64) cc='x86_64-w64-mingw32-gcc' cxx='x86_64-w64-mingw32-g++' ;; 33 | esac 34 | ;; 35 | darwin) 36 | case "${arch}" in 37 | amd64) cc='o64-clang' cxx='o64-clang++' extra_args='LD_LIBRARY_PATH=/usr/osxcross/lib' ;; 38 | arm64) cc='oa64-clang' cxx='oa64-clang++' extra_args='LD_LIBRARY_PATH=/usr/osxcross/lib' ;; 39 | esac 40 | ;; 41 | linux) 42 | case "${arch}" in 43 | 386) cc='i686-linux-gnu-gcc' cxx='i686-linux-gnu-g++' ;; 44 | arm64) cc='aarch64-linux-gnu-gcc' cxx='aarch64-linux-gnu-g++' ;; 45 | armv*) goarm="${arch##*v}" 46 | if [[ "${goarm}" == "7" ]]; then 47 | cc='arm-linux-gnueabihf-gcc' cxx='arm-linux-gnueabihf-g++' 48 | else 49 | cc='arm-linux-gnueabi-gcc' cxx='arm-linux-gnueabi-g++' 50 | fi 51 | ;; 52 | mips) cc='mips-linux-gnu-gcc' cxx='mips-linux-gnu-g++' ;; 53 | mips64) cc='mips64-linux-gnuabi64-gcc' cxx='mips64-linux-gnuabi64-g++' ;; 54 | mipsle) cc='mipsel-linux-gnu-gcc' cxx='mipsel-linux-gnu-g++' ;; 55 | mips64le) cc='mips64el-linux-gnuabi64-gcc' cxx='mips64el-linux-gnuabi64-g++' ;; 56 | ppc64) cc='powerpc-linux-gnu-gcc' cxx='powerpc-linux-gnu-g++' ;; 57 | ppc64le) cc='powerpc64le-linux-gnu-gcc' cxx='powerpc64le-linux-gnu-g++' ;; 58 | riscv64) cc='riscv64-linux-gnu-gcc' cxx='riscv64-linux-gnu-g++' ;; 59 | s390x) cc='gcc-s390x-linux-gnu' cxx='g++-s390x-linux-gnu' ;; 60 | esac 61 | ;; 62 | netbsd) 63 | case "${arch}" in 64 | 386) cc='i686-linux-gnu-gcc' cxx='i686-linux-gnu-g++' ;; 65 | esac 66 | ;; 67 | esac 68 | 69 | echo "# ${goos}-${arch}" 70 | prefix=".build/${goos}-${arch}" 71 | mkdir -p "${prefix}" 72 | 73 | echo "# Building with: CC='${cc}' CXX='${cxx}'" 74 | if [[ -n "${goarm}" ]]; then 75 | CC="${cc}" CXX="${cxx}" GOOS="${goos}" GOARCH="${arch}" GOARM="${goarm}" \ 76 | make PREFIX="${prefix}" build ${extra_args} 77 | else 78 | CC="${cc}" CXX="${cxx}" GOOS="${goos}" GOARCH="${arch}" \ 79 | make PREFIX="${prefix}" build ${extra_args} 80 | fi 81 | done 82 | 83 | exit 0 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prometheus Golang builder Docker images 2 | 3 | [![CircleCI](https://circleci.com/gh/prometheus/golang-builder/tree/master.svg?style=shield)][circleci] 4 | [![Docker Repository on Quay.io](https://quay.io/repository/prometheus/golang-builder/status)][quayio] 5 | 6 | ## Details 7 | 8 | Docker Builder Image for cross-building Golang Prometheus projects. 9 | 10 | - `latest`, `main`, `1.25.5-main`, `1.25.5-main` ([1.25.5/main/Dockerfile](1.25.5/main/Dockerfile)) 11 | - `arm`, `1.25.5-arm`, `1.25.5-arm` ([1.25.5/arm/Dockerfile](1.25.5/arm/Dockerfile)) 12 | - `powerpc`, `1.25.5-powerpc`, `1.25.5-powerpc` ([1.25.5/powerpc/Dockerfile](1.25.5/powerpc/Dockerfile)) 13 | - `mips`, `1.25.5-mips`, `1.25.5-mips` ([1.25.5/mips/Dockerfile](1.25.5/mips/Dockerfile)) 14 | - `s390x`, `1.25.5-s390x`, `1.25.5-s390x` ([1.25.5/s390x/Dockerfile](1.25.5/s390x/Dockerfile)) 15 | - `1.24-main`, `1.24.11-main` ([1.24/main/Dockerfile](1.24/main/Dockerfile)) 16 | - `arm`, `1.24-arm`, `1.24.11-arm` ([1.24/arm/Dockerfile](1.24/arm/Dockerfile)) 17 | - `powerpc`, `1.24-powerpc`, `1.24.11-powerpc` ([1.24/powerpc/Dockerfile](1.24/powerpc/Dockerfile)) 18 | - `mips`, `1.24-mips`, `1.24.11-mips` ([1.24/mips/Dockerfile](1.24/mips/Dockerfile)) 19 | - `s390x`, `1.24-s390x`, `1.24.11-s390x` ([1.24/s390x/Dockerfile](1.24/s390x/Dockerfile)) 20 | 21 | ## Usage 22 | 23 | Change the repository import path (`-i`) and target platforms (`-p`) according to your needs. 24 | You can also use those images to run your tests by using the `-T` option. 25 | 26 | ``` 27 | Usage: builder.sh [args] 28 | -i,--import-path arg : Go import path of the project 29 | -p,--platforms arg : List of platforms (GOOS/GOARCH) to build separated by a space 30 | -T,--tests : Go run tests then exit 31 | ``` 32 | 33 | ### Requirements 34 | 35 | This building process is using make to build and run tests. 36 | Therefore a `Makefile` with `build` and `test` targets is needed into the root of your source files. 37 | 38 | ### main/latest tag 39 | 40 | ``` 41 | docker run --rm -ti -v $(pwd):/app quay.io/prometheus/golang-builder:main \ 42 | -i "github.com/prometheus/prometheus" \ 43 | -p "linux/amd64 linux/386 darwin/amd64 darwin/386 windows/amd64 windows/386 freebsd/amd64 freebsd/386 openbsd/amd64 openbsd/386 netbsd/amd64 netbsd/386 dragonfly/amd64" 44 | ``` 45 | 46 | ### arm tag 47 | 48 | ``` 49 | docker run --rm -ti -v $(pwd):/app quay.io/prometheus/golang-builder:arm \ 50 | -i "github.com/prometheus/prometheus" \ 51 | -p "linux/arm linux/arm64 freebsd/arm openbsd/arm netbsd/arm" 52 | ``` 53 | 54 | ### powerpc tag 55 | 56 | ``` 57 | docker run --rm -ti -v $(pwd):/app quay.io/prometheus/golang-builder:powerpc \ 58 | -i "github.com/prometheus/prometheus" \ 59 | -p "linux/ppc64 linux/ppc64le" 60 | ``` 61 | 62 | ### mips tag 63 | 64 | mips64/mips64le cross-build is currently available with golang 1.6. 65 | 66 | ``` 67 | docker run --rm -ti -v $(pwd):/app quay.io/prometheus/golang-builder:mips \ 68 | -i "github.com/prometheus/prometheus" \ 69 | -p "linux/mips64 linux/mips64le" 70 | ``` 71 | 72 | ## Legal note 73 | 74 | OSX/Darwin/Apple builds: 75 | **[Please ensure you have read and understood the Xcode license 76 | terms before continuing.](https://www.apple.com/legal/sla/docs/xcode.pdf)** 77 | 78 | ## More information 79 | 80 | * You will find a Circle CI configuration in `circle.yml`. 81 | * All of the core developers are accessible via the [Prometheus Developers Mailinglist](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers) and the `#prometheus` channel on `irc.freenode.net`. 82 | 83 | ## Contributing 84 | 85 | Refer to [CONTRIBUTING.md](CONTRIBUTING.md) 86 | 87 | ## License 88 | 89 | Apache License 2.0, see [LICENSE](LICENSE). 90 | 91 | [quayio]: https://quay.io/repository/prometheus/golang-builder 92 | [circleci]: https://circleci.com/gh/prometheus/golang-builder 93 | 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /cmd/builder-bumper/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Utility program to bump the Go versions in https://github.com/prometheus/golang-builder. 15 | package main 16 | 17 | import ( 18 | "bufio" 19 | "encoding/json" 20 | "errors" 21 | "flag" 22 | "fmt" 23 | "io" 24 | "log/slog" 25 | "net/http" 26 | "os" 27 | "path/filepath" 28 | "regexp" 29 | "sort" 30 | "strconv" 31 | "strings" 32 | 33 | "golang.org/x/mod/semver" 34 | ) 35 | 36 | const updatesURL = "https://go.dev/dl/?mode=json" 37 | 38 | var ( 39 | help bool 40 | versionRe *regexp.Regexp 41 | 42 | logger = slog.New(slog.NewTextHandler(os.Stdout, nil)) 43 | ) 44 | 45 | func init() { 46 | flag.BoolVar(&help, "help", false, "Help message") 47 | versionRe = regexp.MustCompile(`^(?:1\.(\d+))(?:\.(\d+))?$`) 48 | } 49 | 50 | type goVersion struct { 51 | major int 52 | minor int 53 | } 54 | 55 | type VersionInfo struct { 56 | Version string `json:"version"` 57 | } 58 | 59 | func newGoVersion(v string) *goVersion { 60 | c := semver.Canonical("v" + v) 61 | if c == "" { 62 | logger.Error("couldn't parse semver", "version", v) 63 | os.Exit(1) 64 | } 65 | m := strings.Split(c, ".") 66 | major, err := strconv.Atoi(string(m[1])) 67 | if err != nil { 68 | logger.Error("error parsing major verison", "error", err) 69 | os.Exit(1) 70 | } 71 | minor, err := strconv.Atoi(string(m[2])) 72 | if err != nil { 73 | logger.Error("error parsing minor verison", "error", err) 74 | os.Exit(1) 75 | } 76 | return &goVersion{ 77 | major: major, 78 | minor: minor, 79 | } 80 | } 81 | 82 | // major returns the version string without the minor version. 83 | func (g *goVersion) Major() string { 84 | return fmt.Sprintf("1.%d", g.major) 85 | } 86 | 87 | // golangVersion returns the full version string but without the leading '.0' 88 | // for the initial revision of a major release. 89 | func (g *goVersion) golangVersion() string { 90 | if g.major < 21 && g.minor == 0 { 91 | return g.Major() 92 | } 93 | return fmt.Sprintf("1.%d.%d", g.major, g.minor) 94 | } 95 | 96 | // String returns the full version string. 97 | func (g *goVersion) String() string { 98 | return g.golangVersion() 99 | } 100 | 101 | func (g *goVersion) less(o *goVersion) bool { 102 | if g.major == o.major { 103 | return g.minor < o.minor 104 | } 105 | return g.major < o.major 106 | } 107 | 108 | func (g *goVersion) equal(o *goVersion) bool { 109 | return g.major == o.major && g.minor == o.minor 110 | } 111 | 112 | // url returns the URL of the Go archive. 113 | func (g *goVersion) url() string { 114 | return fmt.Sprintf("https://dl.google.com/go/go%s.linux-amd64.tar.gz", g.golangVersion()) 115 | } 116 | 117 | func fetchJSON(url string) ([]byte, error) { 118 | resp, err := http.Get(url) 119 | if err != nil { 120 | return nil, err 121 | } 122 | defer resp.Body.Close() 123 | 124 | if resp.StatusCode != http.StatusOK { 125 | return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode) 126 | } 127 | 128 | body, err := io.ReadAll(resp.Body) 129 | if err != nil { 130 | return nil, err 131 | } 132 | 133 | return body, nil 134 | } 135 | 136 | func getAvailableVersions() []goVersion { 137 | var availableVersions []goVersion 138 | 139 | jsonData, err := fetchJSON(updatesURL) 140 | if err != nil { 141 | logger.Error("Error fetching JSON", "error", err) 142 | return availableVersions 143 | } 144 | 145 | var availableVersionsJSON []VersionInfo 146 | if err := json.Unmarshal(jsonData, &availableVersionsJSON); err != nil { 147 | logger.Error("Error parsing JSON", "error", err) 148 | return availableVersions 149 | } 150 | 151 | for i := range availableVersionsJSON { 152 | // remove "go" from a string like "go1.22.0" 153 | newGoVersion := newGoVersion(strings.TrimLeft(availableVersionsJSON[i].Version, "go")) 154 | availableVersions = append(availableVersions, *newGoVersion) 155 | } 156 | logger.Info("found available versions", "num", len(availableVersions), "versions", availableVersions) 157 | return availableVersions 158 | } 159 | 160 | // getSHA256 returns the SHA256 of the Go archive. 161 | func (g *goVersion) getSHA256() (string, error) { 162 | resp, err := http.Get(g.url() + ".sha256") 163 | if err != nil { 164 | return "", err 165 | } 166 | defer resp.Body.Close() 167 | b, err := io.ReadAll(resp.Body) 168 | if err != nil { 169 | return "", err 170 | } 171 | return strings.TrimSpace(string(b)), nil 172 | } 173 | 174 | // getLastMinorVersion returns the last minor version for a given Go version. 175 | // if no new minor version available, it will return the given Go version back. 176 | func (g *goVersion) getLastMinorVersion(availableVersions []goVersion) *goVersion { 177 | sort.Slice(availableVersions, func(i, j int) bool { 178 | if availableVersions[i].major == availableVersions[j].major { 179 | return availableVersions[i].minor < availableVersions[j].minor 180 | } 181 | return availableVersions[i].major < availableVersions[j].major 182 | }) 183 | 184 | for _, availableVersion := range availableVersions { 185 | if availableVersion.major == g.major && availableVersion.minor > g.minor { 186 | return &availableVersion 187 | } 188 | } 189 | 190 | return g 191 | } 192 | 193 | // getNextMajor returns the next Go major version for a given Go version. 194 | // It returns nil if the current version is already the latest. 195 | func (g *goVersion) getNextMajor(availableVersions []goVersion) *goVersion { 196 | version := newGoVersion(g.Major() + ".0") 197 | version.major++ 198 | 199 | for _, availableVersion := range availableVersions { 200 | if version.major == availableVersion.major { 201 | return version 202 | } 203 | } 204 | return nil 205 | } 206 | 207 | // getExactVersionFromDir reads the current Go version from a directory. 208 | func getExactVersionFromDir(d string) (*goVersion, error) { 209 | re := regexp.MustCompile(fmt.Sprintf(`^\s*VERSION\s*:=\s*(%s(.\d+)?)`, d)) 210 | f, err := os.Open(filepath.Join(d, "Makefile.COMMON")) 211 | if err != nil { 212 | return nil, err 213 | } 214 | scanner := bufio.NewScanner(f) 215 | for scanner.Scan() { 216 | m := re.FindSubmatch(scanner.Bytes()) 217 | if m != nil { 218 | return newGoVersion(string(m[1])), nil 219 | } 220 | } 221 | if err := scanner.Err(); err != nil { 222 | return nil, err 223 | } 224 | return nil, fmt.Errorf("couldn't get exact version for %s", d) 225 | } 226 | 227 | func replace(filename string, replacers []func(string) (string, error)) error { 228 | b, err := os.ReadFile(filename) 229 | if err != nil { 230 | return err 231 | } 232 | out := string(b) 233 | for _, fn := range replacers { 234 | out, err = fn(out) 235 | if err != nil { 236 | return err 237 | } 238 | } 239 | return os.WriteFile(filename, []byte(out), 0644) 240 | } 241 | 242 | func shaReplacer(old, new *goVersion) func(string) (string, error) { 243 | oldSHA, err := old.getSHA256() 244 | if err != nil { 245 | return func(string) (string, error) { return "", err } 246 | } 247 | nextSHA, err := new.getSHA256() 248 | if err != nil { 249 | return func(string) (string, error) { return "", err } 250 | } 251 | 252 | return func(out string) (string, error) { 253 | return strings.ReplaceAll(out, oldSHA, nextSHA), nil 254 | } 255 | } 256 | 257 | func majorVersionReplacer(prefix string, old, new *goVersion) func(string) (string, error) { 258 | return func(out string) (string, error) { 259 | return strings.ReplaceAll(out, prefix+old.Major(), prefix+new.Major()), nil 260 | } 261 | } 262 | 263 | func golangVersionReplacer(prefix string, old, new *goVersion) func(string) (string, error) { 264 | return func(out string) (string, error) { 265 | return strings.ReplaceAll(out, prefix+old.golangVersion(), prefix+new.golangVersion()), nil 266 | } 267 | } 268 | 269 | func fullVersionReplacer(old, new *goVersion) func(string) (string, error) { 270 | return func(out string) (string, error) { 271 | return strings.ReplaceAll(out, old.String(), new.String()), nil 272 | } 273 | } 274 | 275 | // replaceMajor switches the versions from [1.(N-1), 1.N] to [1.N, 1.(N+1)]. 276 | func replaceMajor(old, current, next *goVersion) error { 277 | // Replace the old version by the next one. 278 | err := filepath.Walk(old.Major(), func(path string, info os.FileInfo, err error) error { 279 | if err != nil { 280 | return err 281 | } 282 | if info.IsDir() { 283 | return nil 284 | } 285 | if info.Name() == "Makefile.COMMON" { 286 | return replace(path, 287 | []func(string) (string, error){ 288 | fullVersionReplacer(old, next), 289 | }, 290 | ) 291 | } 292 | if info.Name() == "Dockerfile" { 293 | return replace(path, 294 | []func(string) (string, error){ 295 | golangVersionReplacer("GOLANG_VERSION ", old, next), 296 | majorVersionReplacer("quay.io/prometheus/golang-builder:", old, next), 297 | shaReplacer(old, next), 298 | }, 299 | ) 300 | } 301 | return replace(path, 302 | []func(string) (string, error){ 303 | golangVersionReplacer("", old, next), 304 | majorVersionReplacer("", old, next), 305 | }, 306 | ) 307 | }) 308 | if err != nil { 309 | return err 310 | } 311 | if err := os.Rename(old.Major(), next.Major()); err != nil { 312 | return fmt.Errorf("failed to create new version directory: %w", err) 313 | } 314 | 315 | // Update CircleCI. 316 | err = replace(".circleci/config.yml", 317 | []func(string) (string, error){ 318 | majorVersionReplacer("", current, next), 319 | majorVersionReplacer("", old, current), 320 | }, 321 | ) 322 | if err != nil { 323 | return err 324 | } 325 | 326 | // Update Makefile. 327 | err = replace("Makefile", 328 | []func(string) (string, error){ 329 | majorVersionReplacer("", current, next), 330 | majorVersionReplacer("", old, current), 331 | }, 332 | ) 333 | if err != nil { 334 | return err 335 | } 336 | 337 | // Update README.md. 338 | return replace("README.md", 339 | []func(string) (string, error){ 340 | fullVersionReplacer(current, next), 341 | majorVersionReplacer("", current, next), 342 | fullVersionReplacer(old, current), 343 | majorVersionReplacer("", old, current), 344 | }, 345 | ) 346 | } 347 | 348 | // updateNextMinor bumps the given directory to the next minor version. 349 | // It returns nil if no new version exists. 350 | func updateNextMinor(dir string, availableVersions []goVersion) (*goVersion, error) { 351 | current, err := getExactVersionFromDir(dir) 352 | if err != nil { 353 | return nil, fmt.Errorf("failed to detect current version of %s: %w", dir, err) 354 | } 355 | 356 | next := current.getLastMinorVersion(availableVersions) 357 | 358 | if next.equal(current) { 359 | logger.Info("no version change for Go", "version", next.golangVersion()) 360 | return nil, nil 361 | } 362 | 363 | err = replace(filepath.Join(current.Major(), "base/Dockerfile"), 364 | []func(string) (string, error){ 365 | golangVersionReplacer("GOLANG_VERSION ", current, next), 366 | shaReplacer(current, next), 367 | }, 368 | ) 369 | if err != nil { 370 | return nil, err 371 | } 372 | 373 | err = replace(filepath.Join(current.Major(), "Makefile.COMMON"), 374 | []func(string) (string, error){ 375 | fullVersionReplacer(current, next), 376 | }, 377 | ) 378 | if err != nil { 379 | return nil, err 380 | } 381 | 382 | err = replace(filepath.Join("README.md"), 383 | []func(string) (string, error){ 384 | fullVersionReplacer(current, next), 385 | }, 386 | ) 387 | if err != nil { 388 | return nil, err 389 | } 390 | 391 | logger.Info("updated version", "current", current, "next", next) 392 | return next, nil 393 | } 394 | 395 | func main() { 396 | flag.Parse() 397 | if help { 398 | logger.Info("Bump Go versions in github.com/prometheus/golang-builder.") 399 | flag.PrintDefaults() 400 | os.Exit(0) 401 | } 402 | if err := run(); err != nil { 403 | logger.Error("update run failed", "error", err) 404 | os.Exit(1) 405 | } 406 | } 407 | 408 | func run() error { 409 | dirs := make([]string, 0) 410 | files, err := os.ReadDir(".") 411 | if err != nil { 412 | return err 413 | } 414 | for _, f := range files { 415 | if !f.IsDir() { 416 | continue 417 | } 418 | if !versionRe.Match([]byte(f.Name())) { 419 | continue 420 | } 421 | dirs = append(dirs, f.Name()) 422 | } 423 | 424 | if len(dirs) != 2 { 425 | return fmt.Errorf("expected 2 versions of Go but got %d", len(dirs)) 426 | } 427 | 428 | // Get list of available versions 429 | availableVersions := getAvailableVersions() 430 | if len(availableVersions) == 0 { 431 | logger.Error("failed to fetch avilable versions from update URL", "url", updatesURL) 432 | return errors.New("failed to fetch available versions") 433 | } 434 | 435 | // Check if a new major Go version exists. 436 | nexts := make([]*goVersion, 0) 437 | if next := newGoVersion(dirs[1] + ".0").getNextMajor(availableVersions); next != nil { 438 | logger.Info("found a new major version of Go", "version", next) 439 | old, err := getExactVersionFromDir(dirs[0]) 440 | if err != nil { 441 | return err 442 | } 443 | current, err := getExactVersionFromDir(dirs[1]) 444 | if err != nil { 445 | return err 446 | } 447 | if err = replaceMajor(old, current, next); err != nil { 448 | return err 449 | } 450 | nexts = append(nexts, next) 451 | } else { 452 | // Otherwise check for new minor versions. 453 | for _, d := range dirs { 454 | logger.Info("processing version dir", "dir", d) 455 | next, err := updateNextMinor(d, availableVersions) 456 | if err != nil { 457 | return err 458 | } 459 | if next != nil { 460 | nexts = append(nexts, next) 461 | } 462 | } 463 | } 464 | 465 | if len(nexts) == 0 { 466 | return nil 467 | } 468 | 469 | sort.SliceStable(nexts, func(i, j int) bool { 470 | return nexts[i].less(nexts[j]) 471 | }) 472 | vs := make([]string, 0) 473 | for _, v := range nexts { 474 | vs = append(vs, v.String()) 475 | } 476 | logger.Info("Run the following command to commit the changes:") 477 | logger.Info(fmt.Sprintf("git checkout -b golang-%s", strings.Join(vs, "-"))) 478 | logger.Info(fmt.Sprintf("git commit . --no-edit --message \"Bump to Go %s\"", strings.Join(vs, " and "))) 479 | 480 | return nil 481 | } 482 | --------------------------------------------------------------------------------