Files
actions-runner-controller/Dockerfile

60 lines
2.4 KiB
Docker
Raw Permalink Normal View History

2020-01-28 15:03:23 +09:00
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.19.4 as builder
2020-01-28 15:03:23 +09:00
WORKDIR /workspace
# Make it runnable on a distroless image/without libc
ENV CGO_ENABLED=0
2022-03-03 01:40:45 +00:00
# Copy the Go Modules manifests
COPY go.mod go.sum ./
2022-03-03 01:40:45 +00:00
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer.
#
# Also, we need to do this before setting TARGETPLATFORM/TARGETOS/TARGETARCH/TARGETVARIANT
# so that go mod cache is shared across platforms.
RUN go mod download
2020-01-28 15:03:23 +09:00
# Copy the go source
# COPY . .
2022-03-03 01:40:45 +00:00
# Usage:
# docker buildx build --tag repo/img:tag -f ./Dockerfile . --platform linux/amd64,linux/arm64,linux/arm/v7
#
# With the above commmand,
# TARGETOS can be "linux", TARGETARCH can be "amd64", "arm64", and "arm", TARGETVARIANT can be "v7".
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>
2022-08-23 06:40:16 +02:00
ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT VERSION=dev
2022-03-03 01:40:45 +00:00
# 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
# We can use docker layer cache so the build is fast enogh anyway
# We also use per-platform GOCACHE for the same reason.
ENV GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build
2020-01-28 15:03:23 +09:00
# Build
RUN --mount=target=. \
2022-03-03 01:40:45 +00:00
--mount=type=cache,mode=0777,target=${GOCACHE} \
2022-03-07 10:00:20 +09:00
export GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} && \
go build -trimpath -ldflags="-s -w -X 'github.com/actions/actions-runner-controller/build.Version=${VERSION}'" -o /out/manager main.go && \
go build -trimpath -ldflags="-s -w" -o /out/github-runnerscaleset-listener ./cmd/githubrunnerscalesetlistener && \
go build -trimpath -ldflags="-s -w" -o /out/github-webhook-server ./cmd/githubwebhookserver && \
go build -trimpath -ldflags="-s -w" -o /out/actions-metrics-server ./cmd/actionsmetricsserver && \
go build -trimpath -ldflags="-s -w" -o /out/sleep ./cmd/sleep
2020-01-28 15:03:23 +09:00
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
2020-01-28 15:03:23 +09:00
WORKDIR /
COPY --from=builder /out/manager .
COPY --from=builder /out/github-webhook-server .
COPY --from=builder /out/actions-metrics-server .
COPY --from=builder /out/github-runnerscaleset-listener .
COPY --from=builder /out/sleep .
USER 65532:65532
2020-01-28 15:03:23 +09:00
ENTRYPOINT ["/manager"]