diff --git a/.github/workflows/publish-arc.yaml b/.github/workflows/publish-arc.yaml index c5bf5481..8b5a7c42 100644 --- a/.github/workflows/publish-arc.yaml +++ b/.github/workflows/publish-arc.yaml @@ -58,6 +58,7 @@ jobs: with: file: Dockerfile platforms: linux/amd64,linux/arm64 + build-args: VERSION=${{ env.VERSION }} push: true tags: | ${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:latest diff --git a/.github/workflows/publish-canary.yaml b/.github/workflows/publish-canary.yaml index 9ac0e860..fb51909e 100644 --- a/.github/workflows/publish-canary.yaml +++ b/.github/workflows/publish-canary.yaml @@ -50,6 +50,7 @@ jobs: with: file: Dockerfile platforms: linux/amd64,linux/arm64 + build-args: VERSION=canary push: true tags: | ${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:canary diff --git a/Dockerfile b/Dockerfile index 715eee67..72438f08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ WORKDIR /workspace # Make it runnable on a distroless image/without libc ENV CGO_ENABLED=0 - # Copy the Go Modules manifests COPY go.mod go.sum ./ @@ -25,7 +24,7 @@ RUN go mod download # With the above commmand, # TARGETOS can be "linux", TARGETARCH can be "amd64", "arm64", and "arm", TARGETVARIANT can be "v7". -ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT +ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT VERSION=dev # We intentionally avoid `--mount=type=cache,mode=0777,target=/go/pkg/mod` in the `go mod download` and the `go build` runs # to avoid https://github.com/moby/buildkit/issues/2334 @@ -37,7 +36,7 @@ env GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build RUN --mount=target=. \ --mount=type=cache,mode=0777,target=${GOCACHE} \ export GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} && \ - go build -o /out/manager main.go && \ + go build -ldflags="-X 'github.com/actions-runner-controller/actions-runner-controller/build.Version=${VERSION}'" -o /out/manager main.go && \ go build -o /out/github-webhook-server ./cmd/githubwebhookserver # Use distroless as minimal base image to package the manager binary diff --git a/Makefile b/Makefile index bf4e65ca..14f1cc49 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ else NAME ?= summerwind/actions-runner-controller endif DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1) -VERSION ?= latest +VERSION ?= dev RUNNER_VERSION ?= 2.295.0 TARGETPLATFORM ?= $(shell arch) RUNNER_NAME ?= ${DOCKER_USER}/actions-runner @@ -119,6 +119,7 @@ docker-buildx: docker buildx build --platform ${PLATFORMS} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ + --build-arg VERSION=${VERSION} \ -t "${NAME}:${VERSION}" \ -f Dockerfile \ . ${PUSH_ARG} diff --git a/build/version.go b/build/version.go new file mode 100644 index 00000000..645ecad8 --- /dev/null +++ b/build/version.go @@ -0,0 +1,4 @@ +package build + +// This is overridden at build-time using go-build ldflags. dev is the fallback value +var Version = "NA" diff --git a/github/github.go b/github/github.go index 90709ce1..4c0d79ac 100644 --- a/github/github.go +++ b/github/github.go @@ -3,6 +3,7 @@ package github import ( "context" "fmt" + "github.com/actions-runner-controller/actions-runner-controller/build" "net/http" "net/url" "os" @@ -134,8 +135,7 @@ func (c *Config) NewClient() (*Client, error) { } } } - - client.UserAgent = "actions-runner-controller" + client.UserAgent = "actions-runner-controller/" + build.Version return &Client{ Client: client, @@ -439,7 +439,6 @@ func splitOwnerAndRepo(repo string) (string, string, error) { } return chunk[0], chunk[1], nil } - func getEnterpriseApiUrl(baseURL string) (string, error) { baseEndpoint, err := url.Parse(baseURL) if err != nil { diff --git a/github/github_test.go b/github/github_test.go index 0dea7250..39409f20 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -155,7 +155,7 @@ func TestCleanup(t *testing.T) { func TestUserAgent(t *testing.T) { client := newTestClient() - if client.UserAgent != "actions-runner-controller" { - t.Errorf("UserAgent should be set to actions-runner-controller") + if client.UserAgent != "actions-runner-controller/NA" { + t.Errorf("UserAgent should be set to actions-runner-controller/NA") } } diff --git a/main.go b/main.go index f15e09c5..603b3d42 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ package main import ( "flag" "fmt" + "github.com/actions-runner-controller/actions-runner-controller/build" "os" "strings" "time" @@ -62,7 +63,6 @@ func (i *stringSlice) Set(value string) error { *i = append(*i, value) return nil } - func main() { var ( err error @@ -87,7 +87,6 @@ func main() { commonRunnerLabels commaSeparatedStringSlice ) - var c github.Config err = envconfig.Process("github", &c) if err != nil { @@ -122,7 +121,6 @@ func main() { flag.Parse() logger := logging.NewLogger(logLevel) - c.Log = &logger ghClient, err = c.NewClient() @@ -214,6 +212,7 @@ func main() { log.Info( "Initializing actions-runner-controller", + "version", build.Version, "default-scale-down-delay", defaultScaleDownDelay, "sync-period", syncPeriod, "default-runner-image", runnerImage,