Skip to content

Commit

Permalink
Improve build
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenlj committed Apr 24, 2024
1 parent 568296a commit 0a97845
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 18 deletions.
45 changes: 45 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
*~
._*
.apdisk
.AppleDB
.AppleDesktop
.AppleDouble
atlassian-ide-plugin.xml
bin
cmake-build-*/
.com.apple.timemachine.donotpresent
com_crashlytics_export_strings.xml
crashlytics-build.properties
crashlytics.properties
.directory
*.dll
.DocumentRevisions-V100
.DS_Store
*.dylib
*.exe
*.exe~
fabric.properties
.fseventsd
.fuse_hidden*
gen
Icon
.idea
.idea_modules/
*.iml
*.iws
.LSOverride
Network Trash Folder
.nfs*
*.out
out
out/
*.so
.Spotlight-V100
.TemporaryItems
Temporary Items
*.test
.Trash-*
.Trashes
.VolumeIcon.icns
.testbin
.envtest
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
google_service_account: gh-elector
push: ${{ github.actor != 'dependabot[bot]' }}
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
multi-platform: true
cache_from: type=gha
cache_to: type=gha,mode=max
outputs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Temporary Items
.Trashes
.VolumeIcon.icns
.testbin
.envtest
35 changes: 20 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM --platform=$BUILDPLATFORM golang:1.22 as builder

ENV os "linux"
ENV arch "amd64"

# download kubebuilder and extract it to tmp
RUN echo ${os}
RUN echo ${arch}
RUN wget -qO - https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_${os}_${arch}.tar.gz | tar -xz -C /tmp/
WORKDIR /workspace

# move to a long-term location and put it on your path
# (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else)
RUN mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder
RUN export PATH=$PATH:/usr/local/kubebuilder/bin
# Copy the Go Modules manifests
COPY go.* .

COPY . /workspace
WORKDIR /workspace
# 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

ARG TARGETOS TARGETARCH
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH
RUN go build std

# Copy rest of project
COPY . /workspace

# Download envtest tools early to avoid re-downloading on every code change
RUN make .envtest

# Run tests
RUN make test

# Run integration tests
RUN make integration_test

# Build
RUN CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} GO111MODULE=on go build -a -installsuffix cgo -o elector cmd/elector/main.go
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o elector cmd/elector/main.go

FROM gcr.io/distroless/static-debian11
WORKDIR /
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
K8S_VERSION := 1.27.1
K8S_VERSION := 1.28.3
SHELL := /bin/bash

elector:
Expand All @@ -8,6 +8,9 @@ test:
go test ./... -count=1 -coverprofile cover.out -short

.ONESHELL:
integration_test:
source <(go run sigs.k8s.io/controller-runtime/tools/setup-envtest use -p env $(K8S_VERSION))
integration_test: .envtest
source .envtest
go test ./pkg/election/... -tags=integration -v -count=1

.envtest:
go run sigs.k8s.io/controller-runtime/tools/setup-envtest use -p env $(K8S_VERSION) > .envtest

0 comments on commit 0a97845

Please sign in to comment.