Skip to content

Commit

Permalink
Fix Earthfile to optimize build
Browse files Browse the repository at this point in the history
  • Loading branch information
MeNsaaH committed Jan 11, 2024
1 parent 5632270 commit f6ba4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
23 changes: 12 additions & 11 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION 0.7

ARG --global GOARCH=amd64
ARG --global USERARCH

test:
BUILD +ci-golang
Expand All @@ -26,8 +26,9 @@ release:
go-deps:
ARG GOLANG_VERSION="1.21"
ARG GOOS=linux
ARG GOARCH=$USERARCH

FROM --platform=linux/$GOARCH golang:$GOLANG_VERSION-bullseye
FROM --platform=linux/$USERARCH golang:$GOLANG_VERSION-bullseye

ENV GO111MODULE=on
ENV CGO_ENABLED=0
Expand Down Expand Up @@ -63,20 +64,20 @@ test-golang:

build-binary:
ARG GOOS=linux
ARG GOARCH=$USERARCH
ARG VARIANT
ARG --required GIT_TAG
ARG --required GIT_COMMIT

FROM --platform=linux/$GOARCH +go-deps
FROM --platform=linux/$USERARCH +go-deps

WORKDIR /src
COPY . /src
RUN GOARM=${VARIANT#v} go build -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
SAVE ARTIFACT kubechecks

build-debug-binary:
LOCALLY
FROM +go-deps
FROM --platform=linux/$USERARCH +go-deps
WORKDIR /src
COPY . /src
RUN go build -gcflags="all=-N -l" -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
Expand Down Expand Up @@ -122,7 +123,7 @@ docker:
VOLUME /app/policies
VOLUME /app/schemas

COPY (+build-binary/kubechecks --platform=linux/$GOARCH --GOARCH=$TARGETARCH --VARIANT=$TARGETVARIANT) .
COPY (+build-binary/kubechecks --platform=linux/$USERARCH --GOARCH=$TARGETARCH --VARIANT=$TARGETVARIANT) .
RUN ./kubechecks help

CMD ["./kubechecks", "controller"]
Expand All @@ -140,9 +141,9 @@ dlv:
docker-debug:
FROM +docker --GIT_TAG=debug --GIT_COMMIT=abcdef

COPY (+build-debug-binary/kubechecks --GOARCH=$GOARCH --VARIANT=$TARGETVARIANT) .
COPY (+build-debug-binary/kubechecks --GOARCH=$USERARCH --VARIANT=$TARGETVARIANT) .

COPY (+dlv/dlv --GOARCH=$GOARCH --VARIANT=$TARGETVARIANT) /usr/local/bin/dlv
COPY (+dlv/dlv --GOARCH=$USERARCH --VARIANT=$TARGETVARIANT) /usr/local/bin/dlv

CMD ["/usr/local/bin/dlv", "--listen=:2345", "--api-version=2", "--headless=true", "--accept-multiclient", "exec", "--continue", "./kubechecks", "controller"]

Expand All @@ -165,7 +166,7 @@ lint-golang:

# install staticcheck
RUN FILE=staticcheck.tgz \
&& URL=https://github.com/dominikh/go-tools/releases/download/$STATICCHECK_VERSION/staticcheck_linux_$GOARCH.tar.gz \
&& URL=https://github.com/dominikh/go-tools/releases/download/$STATICCHECK_VERSION/staticcheck_linux_$USERARCH.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
Expand All @@ -187,7 +188,7 @@ test-helm:
# install kubeconform
ARG KUBECONFORM_VERSION="0.6.4"
RUN FILE=kubeconform.tgz \
&& URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-${GOARCH}.tar.gz \
&& URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-${USERARCH}.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
Expand All @@ -214,7 +215,7 @@ release-helm:

ARG HELM_VERSION="3.8.1"
RUN FILE=helm.tgz \
&& URL=https://get.helm.sh/helm-v${HELM_VERSION}-linux-${GOARCH}.tar.gz \
&& URL=https://get.helm.sh/helm-v${HELM_VERSION}-linux-${USERARCH}.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
Expand Down
5 changes: 0 additions & 5 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,12 @@ test_go(
],
)

arch="arm64" if str(local("uname -m")).strip('\n') == "arm64" else "amd64"

earthly_build(
context='.',
target="+docker-debug",
ref='kubechecks',
image_arg='IMAGE_NAME',
ignore='./dist',
extra_args=[
'--GOARCH={}'.format(arch),
]
)

cmd_button('loc:go mod tidy',
Expand Down

0 comments on commit f6ba4c3

Please sign in to comment.