Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codesign utility function #284

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@ usage: promu [<flags>] <command> [<args> ...]
promu is the utility tool for building and releasing Prometheus projects

Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
-c, --config=".promu.yml" Path to config file
-v, --verbose Verbose output
-v, --[no-]verbose Verbose output

Commands:
help [<command>...]
help [<command>...]
Show help.

build [<flags>] [<binary-names>...]
build [<flags>] [<binary-names>...]
Build a Go project

check licenses [<flags>] [<location>...]
check licenses [<flags>] [<location>...]
Inspect source files for each file in a given directory

check changelog [<flags>]
check changelog [<flags>]
Check that CHANGELOG.md follows the guidelines

checksum [<location>...]
checksum [<location>...]
Calculate the SHA256 checksum for each file in the given location

crossbuild [<flags>] [<tarballs>]
codesign <path>
Code sign the darwin binary using rcodesign.

crossbuild [<flags>] [<tarballs>]
Crossbuild a Go project using Golang builder Docker images

info
info
Print info about current project and exit

release [<flags>] [<location>...]
release [<flags>] [<location>...]
Upload all release files to the Github release

tarball [<flags>] [<location>...]
tarball [<flags>] [<location>...]
Create a tarball from the built Go project

version [<flags>]
version [<flags>]
Print the version and exit
```

Expand Down
51 changes: 51 additions & 0 deletions cmd/codesign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright © 2024 Prometheus Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"path/filepath"

"github.com/prometheus/promu/util/sh"
)

var (
codesigncmd = app.Command("codesign", "Code sign the darwin binary using rcodesign.")
binaryPath = codesigncmd.Arg("path", "Absolute path to binary to be signed").Required().String()
)

func runCodeSign(binaryPath string) {
codeSignGoBinary(binaryPath)
}

func codeSignGoBinary(binaryPath string) {
var (
goVersion = config.Go.Version
dockerMainBuilderImage = fmt.Sprintf("%s:%s-main", dockerBuilderImageName, goVersion)
mountPath = fmt.Sprintf("/%s", filepath.Base(binaryPath))
mountPathConcat = fmt.Sprintf("%s:%s", binaryPath, mountPath)
)
fmt.Printf("> using rcodesign to sign the binary file at path %s\n", binaryPath)

// Example:
// docker run --entrypoint "rcodesign" --rm -v "/path/to/darwin-arm64/node_exporter:/node_exporter"
// quay.io/prometheus/golang-builder:1.21-main sign /node_exporter
err := sh.RunCommand("docker", "run", "--entrypoint",
"rcodesign", "--rm", "-v", mountPathConcat,
dockerMainBuilderImage, "sign", mountPath)
if err != nil {
fmt.Printf("Couldn't sign the binary as intended: %s", err)
}
}
2 changes: 2 additions & 0 deletions cmd/promu.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func Execute() {
runTarball(optArg(*tarBinariesLocation, 0, "."))
case versioncmd.FullCommand():
runVersion()
case codesigncmd.FullCommand():
runCodeSign(*binaryPath)
}
}

Expand Down