Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Rebase cronjobber to native cronjob code using kubebuilder #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 0 additions & 8 deletions .dockerignore

This file was deleted.

86 changes: 27 additions & 59 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,27 @@
ARG GO_VERSION=1.15

FROM golang:${GO_VERSION}-alpine AS builder

RUN mkdir /user \
&& echo 'daemon:x:2:2:daemon:/:' > /user/passwd \
&& echo 'daemon:x:2:' > /user/group

RUN apk add --no-cache ca-certificates git
RUN go get -u github.com/golang/dep/cmd/dep

WORKDIR ${GOPATH}/src/github.com/hiddeco/cronjobber

COPY ./Gopkg.toml ./Gopkg.lock ./
RUN dep ensure -vendor-only

COPY . ./

ARG VERSION
ARG VCS_REF

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
-X github.com/hiddeco/cronjobber/pkg/version.VERSION=${VERSION} \
-X github.com/hiddeco/cronjobber/pkg/version.REVISION=${VCS_REF}" \
-a -installsuffix 'static' -o /cronjobber ./cmd/cronjobber/*

FROM scratch AS cronjobber

# Static labels
LABEL maintainer="Hidde Beydals <[email protected]>" \
org.opencontainers.image.title="cronjobber" \
org.opencontainers.image.description="Cronjobber is the Kubernetes cronjob controller patched with time zone support" \
org.opencontainers.image.url="https://github.com/hiddeco/cronjobber" \
org.opencontainers.image.source="[email protected]:hiddeco/cronjobber" \
org.opencontainers.image.vendor="Hidde Beydals" \
org.label-schema.schema-version="1.0" \
org.label-schema.name="cronjobber" \
org.label-schema.description="Cronjobber is the Kubernetes cronjob controller patched with time zone support" \
org.label-schema.url="https://github.com/hiddeco/cronjobber" \
org.label-schema.vcs-url="[email protected]:hiddeco/cronjobber" \
org.label-schema.vendor="Hidde Beydals"

COPY --from=builder /user/group /user/passwd /etc/
COPY --from=builder /cronjobber /cronjobber

USER daemon:daemon

ENTRYPOINT ["/cronjobber"]

ARG VCS_REF
ARG BUILD_DATE

# Dynamic labels
# Besides being informative these will also ensure each
# build ends up with a unique hash.
LABEL org.opencontainers.image.revision="$VCS_REF" \
org.opencontainers.image.created="$BUILD_DATE" \
org.label-schema.vcs-ref="$VCS_REF" \
org.label-schema.build-date="$BUILD_DATE"
# Build the manager binary
FROM golang:1.17 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# 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
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

# 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
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading