Skip to content
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
14 changes: 2 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,12 @@ ENV GO111MODULE=on \
GOARM=${TARGETVARIANT}

WORKDIR /go/src/github.com/open-policy-agent/gatekeeper

COPY pkg/ pkg/
COPY third_party/ third_party/
COPY vendor/ vendor/
COPY main.go main.go
COPY apis/ apis/
COPY go.mod .

RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest}" -o manager main.go
COPY . .
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs the risk of copying temp files, such as .output into the system, which may bloat the binary and/or lead to inadvertent disclosures of a publisher's machine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just the builder image, it is not published

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, makes sense

RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest}" -o manager

FROM $BASEIMAGE

WORKDIR /

COPY --from=builder /go/src/github.com/open-policy-agent/gatekeeper/manager .

USER 65532:65532

ENTRYPOINT ["/manager"]
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ BENCHMARK_FILE_NAME ?= benchmarks.txt
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(abspath $(ROOT_DIR)/bin)

BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh)
BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed hostname, i am not sure if there is value but I can re-add if anyone thinks this is important


LDFLAGS := "-X github.com/open-policy-agent/gatekeeper/pkg/version.Version=$(VERSION) \
-X github.com/open-policy-agent/gatekeeper/pkg/version.Vcs=$(BUILD_COMMIT) \
-X github.com/open-policy-agent/gatekeeper/pkg/version.Timestamp=$(BUILD_TIMESTAMP) \
-X github.com/open-policy-agent/gatekeeper/pkg/version.Hostname=$(BUILD_HOSTNAME) \
-X main.frameworksVersion=$(FRAMEWORKS_VERSION) \
-X main.opaVersion=$(OPA_VERSION)"

Expand Down
9 changes: 0 additions & 9 deletions build/get-build-commit.sh

This file was deleted.

3 changes: 0 additions & 3 deletions build/get-build-hostname.sh

This file was deleted.

3 changes: 0 additions & 3 deletions build/get-build-timestamp.sh

This file was deleted.

8 changes: 0 additions & 8 deletions build/vendormanifests.go

This file was deleted.

6 changes: 2 additions & 4 deletions gator.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ ENV GO111MODULE=on \
GOARCH=${TARGETARCH} \
GOARM=${TARGETVARIANT}

COPY . /tmp/gatekeeper

WORKDIR /tmp/gatekeeper/cmd/gator

COPY . /go/src/github.com/open-policy-agent/gatekeeper
WORKDIR /go/src/github.com/open-policy-agent/gatekeeper/cmd/gator
RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest -X main.frameworksVersion=latest -X main.opaVersion=latest}" -o /gator

FROM --platform=$BUILDPLATFORM $BASEIMAGE as build
Expand Down
30 changes: 22 additions & 8 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@ package version
import (
"fmt"
"runtime"
"runtime/debug"
)

// Vcs is is the commit hash for the binary build.
var Vcs string

// Timestamp is the date for the binary build.
var Timestamp string

// Version is the gatekeeper version.
var Version string

// GetUserAgent returns a user agent of the format: gatekeeper/<version> (<goos>/<goarch>) <vcs>/<timestamp>.
// GetUserAgent returns a user agent of the format: gatekeeper/<version> (<goos>/<goarch>) <vcsrevision><-vcsdirty>/<vcstimestamp>.
func GetUserAgent() string {
return fmt.Sprintf("gatekeeper/%s (%s/%s) %s/%s", Version, runtime.GOOS, runtime.GOARCH, Vcs, Timestamp)
vcsrevision := "unknown"
vcstimestamp := "unknown"
vcsdirty := ""

if info, ok := debug.ReadBuildInfo(); ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this PR!

QQ, what happens when !ok to the version here? even this would even happen at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the code it looks like it defaults to "unknown/unknown"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the build fail instead of returning unknown/unknown?

Copy link
Copy Markdown
Member Author

@sozercan sozercan Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wouldn't happen in our CI. If someone is randomly building GK with a super old version of Go, do we support it or care that it says "unknown"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is mostly for our CI, I'm ok leave it as unknown for now unless someone raises an issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO unknown/unknown is fine in order to avoid unnecessary brittleness for people hacking on G8r. If we wanted to ensure our builds aren't affected, we could test that the flag returns an expected result?

for _, v := range info.Settings {
switch v.Key {
case "vcs.revision":
vcsrevision = v.Value
case "vcs.modified":
if v.Value == "true" {
vcsdirty = "-dirty"
}
case "vcs.time":
vcstimestamp = v.Value
}
}
}

return fmt.Sprintf("gatekeeper/%s (%s/%s) %s%s/%s", Version, runtime.GOOS, runtime.GOARCH, vcsrevision, vcsdirty, vcstimestamp)
}