Skip to content

Commit db1bc74

Browse files
committed
Add codesign to flags
Signed-off-by: Alper Polat <[email protected]> Add rcodesign as a new utility function Signed-off-by: Alper Polat <[email protected]> Update year to 2024 Signed-off-by: Alper Polat <[email protected]> Update README Signed-off-by: Alper Polat <[email protected]> Indicate that the binary to be signed is darwin binary Signed-off-by: Alper Polat <[email protected]> Gofumpt to get rid of linter warnings Signed-off-by: Alper Polat <[email protected]>
1 parent 7977551 commit db1bc74

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,42 @@ usage: promu [<flags>] <command> [<args> ...]
88
promu is the utility tool for building and releasing Prometheus projects
99
1010
Flags:
11-
-h, --help Show context-sensitive help (also try --help-long and --help-man).
11+
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
1212
-c, --config=".promu.yml" Path to config file
13-
-v, --verbose Verbose output
13+
-v, --[no-]verbose Verbose output
1414
1515
Commands:
16-
help [<command>...]
16+
help [<command>...]
1717
Show help.
1818
19-
build [<flags>] [<binary-names>...]
19+
build [<flags>] [<binary-names>...]
2020
Build a Go project
2121
22-
check licenses [<flags>] [<location>...]
22+
check licenses [<flags>] [<location>...]
2323
Inspect source files for each file in a given directory
2424
25-
check changelog [<flags>]
25+
check changelog [<flags>]
2626
Check that CHANGELOG.md follows the guidelines
2727
28-
checksum [<location>...]
28+
checksum [<location>...]
2929
Calculate the SHA256 checksum for each file in the given location
3030
31-
crossbuild [<flags>] [<tarballs>]
31+
codesign <path>
32+
Code sign the darwin binary using rcodesign.
33+
34+
crossbuild [<flags>] [<tarballs>]
3235
Crossbuild a Go project using Golang builder Docker images
3336
34-
info
37+
info
3538
Print info about current project and exit
3639
37-
release [<flags>] [<location>...]
40+
release [<flags>] [<location>...]
3841
Upload all release files to the Github release
3942
40-
tarball [<flags>] [<location>...]
43+
tarball [<flags>] [<location>...]
4144
Create a tarball from the built Go project
4245
43-
version [<flags>]
46+
version [<flags>]
4447
Print the version and exit
4548
```
4649

cmd/codesign.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

cmd/promu.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func Execute() {
137137
runTarball(optArg(*tarBinariesLocation, 0, "."))
138138
case versioncmd.FullCommand():
139139
runVersion()
140+
case codesigncmd.FullCommand():
141+
runCodeSign(*binaryPath)
140142
}
141143
}
142144

0 commit comments

Comments
 (0)