Print Version Number on startup (#1659)
* Changed Dockerfile to get the Enviroment variable from the github actions workflow and pass it to the main.go file Added a function in main.go to fetch the enviroment varible and to have a fallback if the env variable isnt there Added a test for the version to use for this branch only * Update test-version.yaml * Update test-version.yaml * Removed the test because its not needed when we push upstream * Moved the version print in main.go to the Log codeblock as requested by toast-gear Added version as issue#1161 requests. Decided to use a docker tag structure for the userAgent string, with : being a seperator of the name and version * Used ldflags instead like mumoshu recommended Changed Dockerfile to use $VERSION from the workflow Added version.go and the build package Removed the getVersion function as we can just get the value directly * Used ldflags instead like mumoshu recommended Changed Dockerfile to use $VERSION from the workflow Added version.go and the build package Removed the getVersion function as we can just get the value directly * * Removed the default from the go code (set it as N/A) * Changed version from latest to dev inside makefile * Added buildarg for version to the dockerfile in the makerfile * Added VERSION with default dev value as arg inside dockerfile * Cleaned up inside dockerfile * Fix failing test * Fix possible missing VERSION in the ARC UA suffix due to missing build arg in docker-build-push step Co-authored-by: S8338C <viktor.lindgren@seb.se> Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
parent
f0c8c07428
commit
ca97f39fcb
|
|
@ -58,6 +58,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: VERSION=${{ env.VERSION }}
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:latest
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:latest
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: VERSION=canary
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:canary
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:canary
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ WORKDIR /workspace
|
||||||
|
|
||||||
# Make it runnable on a distroless image/without libc
|
# Make it runnable on a distroless image/without libc
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
|
||||||
# Copy the Go Modules manifests
|
# Copy the Go Modules manifests
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
|
@ -25,7 +24,7 @@ RUN go mod download
|
||||||
# With the above commmand,
|
# With the above commmand,
|
||||||
# TARGETOS can be "linux", TARGETARCH can be "amd64", "arm64", and "arm", TARGETVARIANT can be "v7".
|
# 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
|
# 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
|
# to avoid https://github.com/moby/buildkit/issues/2334
|
||||||
|
|
@ -37,7 +36,7 @@ env GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build
|
||||||
RUN --mount=target=. \
|
RUN --mount=target=. \
|
||||||
--mount=type=cache,mode=0777,target=${GOCACHE} \
|
--mount=type=cache,mode=0777,target=${GOCACHE} \
|
||||||
export GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} && \
|
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
|
go build -o /out/github-webhook-server ./cmd/githubwebhookserver
|
||||||
|
|
||||||
# Use distroless as minimal base image to package the manager binary
|
# Use distroless as minimal base image to package the manager binary
|
||||||
|
|
|
||||||
3
Makefile
3
Makefile
|
|
@ -4,7 +4,7 @@ else
|
||||||
NAME ?= summerwind/actions-runner-controller
|
NAME ?= summerwind/actions-runner-controller
|
||||||
endif
|
endif
|
||||||
DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1)
|
DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1)
|
||||||
VERSION ?= latest
|
VERSION ?= dev
|
||||||
RUNNER_VERSION ?= 2.295.0
|
RUNNER_VERSION ?= 2.295.0
|
||||||
TARGETPLATFORM ?= $(shell arch)
|
TARGETPLATFORM ?= $(shell arch)
|
||||||
RUNNER_NAME ?= ${DOCKER_USER}/actions-runner
|
RUNNER_NAME ?= ${DOCKER_USER}/actions-runner
|
||||||
|
|
@ -119,6 +119,7 @@ docker-buildx:
|
||||||
docker buildx build --platform ${PLATFORMS} \
|
docker buildx build --platform ${PLATFORMS} \
|
||||||
--build-arg RUNNER_VERSION=${RUNNER_VERSION} \
|
--build-arg RUNNER_VERSION=${RUNNER_VERSION} \
|
||||||
--build-arg DOCKER_VERSION=${DOCKER_VERSION} \
|
--build-arg DOCKER_VERSION=${DOCKER_VERSION} \
|
||||||
|
--build-arg VERSION=${VERSION} \
|
||||||
-t "${NAME}:${VERSION}" \
|
-t "${NAME}:${VERSION}" \
|
||||||
-f Dockerfile \
|
-f Dockerfile \
|
||||||
. ${PUSH_ARG}
|
. ${PUSH_ARG}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package build
|
||||||
|
|
||||||
|
// This is overridden at build-time using go-build ldflags. dev is the fallback value
|
||||||
|
var Version = "NA"
|
||||||
|
|
@ -3,6 +3,7 @@ package github
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/build"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -134,8 +135,7 @@ func (c *Config) NewClient() (*Client, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
client.UserAgent = "actions-runner-controller/" + build.Version
|
||||||
client.UserAgent = "actions-runner-controller"
|
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
Client: client,
|
Client: client,
|
||||||
|
|
@ -439,7 +439,6 @@ func splitOwnerAndRepo(repo string) (string, string, error) {
|
||||||
}
|
}
|
||||||
return chunk[0], chunk[1], nil
|
return chunk[0], chunk[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEnterpriseApiUrl(baseURL string) (string, error) {
|
func getEnterpriseApiUrl(baseURL string) (string, error) {
|
||||||
baseEndpoint, err := url.Parse(baseURL)
|
baseEndpoint, err := url.Parse(baseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func TestCleanup(t *testing.T) {
|
||||||
|
|
||||||
func TestUserAgent(t *testing.T) {
|
func TestUserAgent(t *testing.T) {
|
||||||
client := newTestClient()
|
client := newTestClient()
|
||||||
if client.UserAgent != "actions-runner-controller" {
|
if client.UserAgent != "actions-runner-controller/NA" {
|
||||||
t.Errorf("UserAgent should be set to actions-runner-controller")
|
t.Errorf("UserAgent should be set to actions-runner-controller/NA")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
main.go
5
main.go
|
|
@ -19,6 +19,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/build"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -62,7 +63,6 @@ func (i *stringSlice) Set(value string) error {
|
||||||
*i = append(*i, value)
|
*i = append(*i, value)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
@ -87,7 +87,6 @@ func main() {
|
||||||
|
|
||||||
commonRunnerLabels commaSeparatedStringSlice
|
commonRunnerLabels commaSeparatedStringSlice
|
||||||
)
|
)
|
||||||
|
|
||||||
var c github.Config
|
var c github.Config
|
||||||
err = envconfig.Process("github", &c)
|
err = envconfig.Process("github", &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -122,7 +121,6 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logger := logging.NewLogger(logLevel)
|
logger := logging.NewLogger(logLevel)
|
||||||
|
|
||||||
c.Log = &logger
|
c.Log = &logger
|
||||||
|
|
||||||
ghClient, err = c.NewClient()
|
ghClient, err = c.NewClient()
|
||||||
|
|
@ -214,6 +212,7 @@ func main() {
|
||||||
|
|
||||||
log.Info(
|
log.Info(
|
||||||
"Initializing actions-runner-controller",
|
"Initializing actions-runner-controller",
|
||||||
|
"version", build.Version,
|
||||||
"default-scale-down-delay", defaultScaleDownDelay,
|
"default-scale-down-delay", defaultScaleDownDelay,
|
||||||
"sync-period", syncPeriod,
|
"sync-period", syncPeriod,
|
||||||
"default-runner-image", runnerImage,
|
"default-runner-image", runnerImage,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue