Skip to content

Commit

Permalink
feat: add support for goreleaser, helmify and generate Helm chart (#80)
Browse files Browse the repository at this point in the history
* add support for helmify, goreleaser and generate a Helm chart

* golangci-lint fix

---------

Co-authored-by: Geoff Wilson <[email protected]>
  • Loading branch information
dejanzele and suprjinx authored Feb 7, 2023
1 parent 5e8560f commit a408e3c
Show file tree
Hide file tree
Showing 30 changed files with 13,960 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ bin
testbin/*
Dockerfile.cross

# GoReleaser
dist/

# Test binary, build with `go test -c`
*.test

Expand Down
40 changes: 40 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
project_name: armada-operator

dist: "dist"

builds:
- env: [CGO_ENABLED=0]
mod_timestamp: '{{ .CommitTimestamp }}'
goos:
- linux
goarch:
- amd64

sboms:
- artifacts: archive

env:
- DOCKER_REPO={{ if index .Env "DOCKER_REPO" }}{{ .Env.DOCKER_REPO }}/{{ else }}{{ end }}

dockers:
- image_templates:
- "{{ .Env.DOCKER_REPO }}armada-operator:latest"
- "{{ .Env.DOCKER_REPO }}armada-operator:{{ .Version }}"
dockerfile: Dockerfile
build_flag_templates:
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description=Exposes Armada resources as CRDs for a more Kubernetes-native experience
- --label=org.opencontainers.image.url=https://github.com/armadaproject/armada-operator
- --label=org.opencontainers.image.source=https://github.com/armadaproject/armada-operator
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT

snapshot:
name_template: "{{ .Tag }}"

source:
enabled: true
name_template: "{{ .ProjectName }}_{{ .Version }}_source"
format: "zip"
34 changes: 3 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
# Build the manager binary
FROM golang:1.19 as builder
ARG TARGETOS
ARG TARGETARCH
FROM scratch

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 armada-operator /

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

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} 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"]
ENTRYPOINT ["/armada-operator"]
33 changes: 33 additions & 0 deletions Dockerfile.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build the manager binary
FROM golang:1.19 as builder
ARG TARGETOS
ARG TARGETARCH

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 apis/ apis/
COPY controllers/ controllers/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} 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"]
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
endif

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= armada-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2

Expand Down Expand Up @@ -197,10 +197,15 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in

.PHONY: deploy-to-kind
deploy-to-kind: dev-setup docker-build load-image deploy

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: generate-helm-chart
generate-helm-chart: manifests kustomize helmify
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir deployment/armada-operator

## Kubernetes Dependencies
CERT_MANAGER_MANIFEST ?= "https://github.com/cert-manager/cert-manager/releases/download/v1.6.3/cert-manager.yaml"
.PHONY: install-cert-manager
Expand Down Expand Up @@ -259,6 +264,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
GOTESTSUM ?= $(LOCALBIN)/gotestsum
MOCKGEN ?= $(LOCALBIN)/mockgen
KIND ?= $(LOCALBIN)/kind
HELMIFY ?= $(LOCALBIN)/helmify
## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.10.0
Expand All @@ -280,12 +286,12 @@ $(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: gotestsum
gotestsum: $(GOTESTSUM)## Download gotestsum locally if necessary.
gotestsum: $(GOTESTSUM) ## Download gotestsum locally if necessary.
$(GOTESTSUM): $(LOCALBIN)
test -s $(LOCALBIN)/gotestsum || GOBIN=$(LOCALBIN) go install gotest.tools/[email protected]

.PHONY: mockgen
mockgen: $(MOCKGEN)## Download mockgen locally if necessary.
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
$(MOCKGEN): $(LOCALBIN)
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install github.com/golang/mock/[email protected]

Expand All @@ -294,6 +300,11 @@ kind: $(KIND)
$(KIND): $(LOCALBIN)
test -s $(LOCALBIN)/kind || GOBIN=$(LOCALBIN) go install sigs.k8s.io/[email protected]

.PHONY: helmify
helmify: $(HELMIFY)
$(HELMIFY): $(LOCALBIN)
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/[email protected]

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
Expand Down
23 changes: 23 additions & 0 deletions deployment/armada-operator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions deployment/armada-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: armada-operator
description: A Helm chart for Armada Operator which exposes Armada CRDs for more Kubernetes-native experience
type: application
version: 0.1.0
appVersion: "0.1.0"
Loading

0 comments on commit a408e3c

Please sign in to comment.