cmd/containerbuild: default to ttl.sh for third party contributions (#51)
* cmd/containerbuild: default to ttl.sh for third party contributions Closes #48 Signed-off-by: Xe Iaso <me@xeiaso.net> * track comment tags Signed-off-by: Xe Iaso <me@xeiaso.net> * empty commit to make sure double-commenting doesn't work Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
86b8c6c5f2
commit
95dddb5549
2 changed files with 50 additions and 0 deletions
12
.github/workflows/docker.yml
vendored
12
.github/workflows/docker.yml
vendored
|
@ -16,6 +16,7 @@ permissions:
|
||||||
packages: write
|
packages: write
|
||||||
attestations: write
|
attestations: write
|
||||||
id-token: write
|
id-token: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -57,6 +58,17 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
go run ./cmd/containerbuild --docker-repo ghcr.io/techarohq/anubis --slog-level debug
|
go run ./cmd/containerbuild --docker-repo ghcr.io/techarohq/anubis --slog-level debug
|
||||||
|
|
||||||
|
- name: "Comment about where to test this"
|
||||||
|
uses: thollander/actions-comment-pull-request@v3
|
||||||
|
with:
|
||||||
|
message: |
|
||||||
|
You can try this PR out by using the following docker image:
|
||||||
|
|
||||||
|
```
|
||||||
|
${{ steps.build.outputs.docker_image }}
|
||||||
|
```
|
||||||
|
comment-tag: ${{ steps.build.outputs.docker_image }}
|
||||||
|
|
||||||
- name: Generate artifact attestation
|
- name: Generate artifact attestation
|
||||||
uses: actions/attest-build-provenance@v2
|
uses: actions/attest-build-provenance@v2
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -19,9 +19,25 @@ var (
|
||||||
dockerLabels = flag.String("docker-labels", os.Getenv("DOCKER_METADATA_OUTPUT_LABELS"), "Docker image labels")
|
dockerLabels = flag.String("docker-labels", os.Getenv("DOCKER_METADATA_OUTPUT_LABELS"), "Docker image labels")
|
||||||
dockerRepo = flag.String("docker-repo", "registry.int.xeserv.us/techaro/anubis", "Docker image repository for Anubis")
|
dockerRepo = flag.String("docker-repo", "registry.int.xeserv.us/techaro/anubis", "Docker image repository for Anubis")
|
||||||
dockerTags = flag.String("docker-tags", os.Getenv("DOCKER_METADATA_OUTPUT_TAGS"), "newline separated docker tags including the registry name")
|
dockerTags = flag.String("docker-tags", os.Getenv("DOCKER_METADATA_OUTPUT_TAGS"), "newline separated docker tags including the registry name")
|
||||||
|
githubActor = flag.String("github-actor", "", "GitHub actor")
|
||||||
|
githubEventName = flag.String("github-event-name", "", "GitHub event name")
|
||||||
|
pullRequestID = flag.Int("pull-request-id", -1, "GitHub pull request ID")
|
||||||
slogLevel = flag.String("slog-level", "INFO", "logging level (see https://pkg.go.dev/log/slog#hdr-Levels)")
|
slogLevel = flag.String("slog-level", "INFO", "logging level (see https://pkg.go.dev/log/slog#hdr-Levels)")
|
||||||
|
|
||||||
|
knownContributors = []string{
|
||||||
|
"Xe",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func inList(needle string, haystack []string) bool {
|
||||||
|
for _, h := range haystack {
|
||||||
|
if h == needle {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flagenv.Parse()
|
flagenv.Parse()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -29,6 +45,27 @@ func main() {
|
||||||
internal.InitSlog(*slogLevel)
|
internal.InitSlog(*slogLevel)
|
||||||
|
|
||||||
koDockerRepo := strings.TrimRight(*dockerRepo, "/"+filepath.Base(*dockerRepo))
|
koDockerRepo := strings.TrimRight(*dockerRepo, "/"+filepath.Base(*dockerRepo))
|
||||||
|
|
||||||
|
if *githubEventName == "pull_request" && !inList(*githubActor, knownContributors) {
|
||||||
|
if *pullRequestID == -1 {
|
||||||
|
log.Fatal("Must set --pull-request-id when --github-event-name=pull_request")
|
||||||
|
}
|
||||||
|
|
||||||
|
*dockerRepo = fmt.Sprintf("ttl.sh/techaro/pr-%d/anubis", *pullRequestID)
|
||||||
|
*dockerTags = fmt.Sprintf("ttl.sh/techaro/pr-%d/anubis:24h", *pullRequestID)
|
||||||
|
koDockerRepo = fmt.Sprintf("ttl.sh/techaro/pr-%d", *pullRequestID)
|
||||||
|
|
||||||
|
slog.Info(
|
||||||
|
"Building image for pull request",
|
||||||
|
"docker-repo", *dockerRepo,
|
||||||
|
"docker-tags", *dockerTags,
|
||||||
|
"github-event-name", *githubEventName,
|
||||||
|
"pull-request-id", *pullRequestID,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
setOutput("docker_image", strings.SplitN(*dockerTags, "\n", 2)[0])
|
||||||
|
|
||||||
version, err := run("git describe --tags --always --dirty")
|
version, err := run("git describe --tags --always --dirty")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -129,6 +166,7 @@ func run(command string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
slog.Debug("running command", "command", command)
|
||||||
cmd := exec.Command(bin, "-c", command)
|
cmd := exec.Command(bin, "-c", command)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue