|
| 1 | +// Copyright © 2024 Prometheus Team |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package cmd |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "path/filepath" |
| 20 | + |
| 21 | + "github.com/prometheus/promu/util/sh" |
| 22 | +) |
| 23 | + |
| 24 | +var ( |
| 25 | + codesigncmd = app.Command("codesign", "Code sign the darwin binary using rcodesign.") |
| 26 | + binaryPath = codesigncmd.Arg("path", "Absolute path to binary to be signed").Required().String() |
| 27 | +) |
| 28 | + |
| 29 | +func runCodeSign(binaryPath string) { |
| 30 | + codeSignGoBinary(binaryPath) |
| 31 | +} |
| 32 | + |
| 33 | +func codeSignGoBinary(binaryPath string) { |
| 34 | + var ( |
| 35 | + goVersion = config.Go.Version |
| 36 | + dockerMainBuilderImage = fmt.Sprintf("%s:%s-main", dockerBuilderImageName, goVersion) |
| 37 | + mountPath = fmt.Sprintf("/%s", filepath.Base(binaryPath)) |
| 38 | + mountPathConcat = fmt.Sprintf("%s:%s", binaryPath, mountPath) |
| 39 | + ) |
| 40 | + fmt.Printf("> using rcodesign to sign the binary file at path %s\n", binaryPath) |
| 41 | + |
| 42 | + // Example: |
| 43 | + // docker run --entrypoint "rcodesign" --rm -v "/path/to/darwin-arm64/node_exporter:/node_exporter" |
| 44 | + // quay.io/prometheus/golang-builder:1.21-main sign /node_exporter |
| 45 | + err := sh.RunCommand("docker", "run", "--entrypoint", |
| 46 | + "rcodesign", "--rm", "-v", mountPathConcat, |
| 47 | + dockerMainBuilderImage, "sign", mountPath) |
| 48 | + if err != nil { |
| 49 | + fmt.Printf("Couldn't sign the binary as intended: %s", err) |
| 50 | + } |
| 51 | +} |
0 commit comments