Skip to content

Commit

Permalink
fix: Fix image build version (#448)
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
  • Loading branch information
helayoty committed Feb 10, 2023
1 parent 5b699e4 commit 616669d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
1 change: 0 additions & 1 deletion .github/workflows/aks-addon-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ concurrency:
on:
pull_request_target:
branches: [master]
types: [ opened, ready_for_review, reopened ]
paths-ignore: ['docs/**', '**.md', '**.mdx', '**.png', '**.jpg']
push:
branches: [master]
Expand Down
26 changes: 6 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IMG_TAG ?= $(subst v,,$(VERSION))
INIT_IMG_TAG ?= 0.1.0
K8S_VERSION ?= 1.23.12

BUILD_DATE ?= $(shell date '+%Y-%m-%dT%H:%M:%S')

## --------------------------------------
## Tooling Binaries
Expand All @@ -62,8 +63,10 @@ docker-buildx-builder:

.PHONY: docker-build-image
docker-build-image: docker-buildx-builder
docker buildx build \
docker buildx build \
--file docker/virtual-kubelet/Dockerfile \
--build-arg BUILD_VERSION=$(IMG_TAG) \
--build-arg BUILD_DATE="$(BUILD_DATE)" \
--output=$(OUTPUT_TYPE) \
--platform="$(BUILDPLATFORM)" \
--pull \
Expand All @@ -78,9 +81,6 @@ docker-build-init-image: docker-buildx-builder
--pull \
--tag $(INIT_IMAGE):$(INIT_IMG_TAG) .

.PHONY: build
build: bin/virtual-kubelet

.PHONY: clean
clean: files := bin/virtual-kubelet bin/virtual-kubelet.tgz
clean:
Expand All @@ -104,7 +104,7 @@ e2e-test:
INIT_IMG_REPO=$(INIT_IMG_NAME) INIT_IMG_TAG=$(INIT_IMG_TAG) \
LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) \
K8S_VERSION=$(K8S_VERSION) \
$(AKS_E2E_SCRIPT) go test -timeout 30m -v ./e2e
$(AKS_E2E_SCRIPT) go test -timeout 60m -v ./e2e

.PHONY: aks-addon-e2e-test
aks-addon-e2e-test:
Expand All @@ -113,7 +113,7 @@ aks-addon-e2e-test:
INIT_IMG_REPO=$(INIT_IMG_NAME) INIT_IMG_TAG=$(INIT_IMG_TAG) \
LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) \
K8S_VERSION=$(K8S_VERSION) \
$(AKS_ADDON_E2E_SCRIPT) go test -timeout 30m -v ./e2e
$(AKS_ADDON_E2E_SCRIPT) go test -timeout 60m -v ./e2e

.PHONY: vet
vet:
Expand Down Expand Up @@ -153,20 +153,6 @@ test-loganalytics-json:
chmod a+x hack/ci/create_loganalytics_auth.sh
hack/ci/create_loganalytics_auth.sh

bin/virtual-kubelet: BUILD_VERSION ?= $(IMG_TAG)
bin/virtual-kubelet: BUILD_DATE ?= $(shell date -u '+%Y-%m-%d-%H:%M UTC')
bin/virtual-kubelet: VERSION_FLAGS := -ldflags='-X "main.buildVersion=$(BUILD_VERSION)" -X "main.buildTime=$(BUILD_DATE)"'

FILTER_TESTS = $(filter-out $(wildcard **/*_test.go), $1)
FILTER_E2E = $(filter-out $(wildcard e2e/**), $1)
FILTER_HACK = $(filter-out $(wildcard hack/**), $1)
GO_FILES = $(wildcard **/*.go)
GO_BIN_DEPS = $(call FILTER_HACK, $(call FILTER_TESTS, $(call FILTER_E2E, $(GO_FILES))))

# Add dependencies for all .go files except those in e2e and test files.
bin/%: $(GO_BIN_DEPS)
CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o bin/$(*) $(VERSION_FLAGS) ./cmd/$(*)

.PHONY: release-manifest
release-manifest:
@sed -i -e 's/^VERSION ?= .*/VERSION ?= ${VERSION}/' ./Makefile
Expand Down
8 changes: 7 additions & 1 deletion docker/virtual-kubelet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH
ARG BUILD_VERSION
ARG BUILD_DATE
SHELL ["/bin/bash", "-c"]
WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -15,11 +17,15 @@ RUN \
--mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . .

RUN --mount=type=cache,target=${GOCACHE} \
--mount=type=cache,id=vk-azure-aci,sharing=locked,target=/go/pkg/mod \
GOARM="${TARGETVARIANT#v}" make build GOARM="$GOARM"
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build \
-ldflags "-X main.BuildVersion=$BUILD_VERSION" -ldflags "-X main.BuildTime=${BUILD_DATE}" \
-ldflags '-extldflags "-static"' \
-o bin/virtual-kubelet cmd/virtual-kubelet/*

FROM --platform=$BUILDPLATFORM gcr.io/distroless/static
COPY --from=builder /workspace/bin/virtual-kubelet /usr/bin/virtual-kubelet
Expand Down

0 comments on commit 616669d

Please sign in to comment.