Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(makefile): reorganize docker build and push targets #3995

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
68 changes: 52 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,61 @@ aws-sdk-model-override:
./scripts/aws_sdk_model_override/cleanup.sh ; \
fi

.PHONY: docker-push
docker-push: aws-load-balancer-controller-push
# Docker build targets (without pushing)
.PHONY: docker-build
docker-build:
docker build . --target bin \
--tag $(IMG) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--platform ${IMG_PLATFORM}

.PHONY: docker-buildx
docker-buildx:
docker buildx build . --target bin \
--tag $(IMG) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--platform ${IMG_PLATFORM} \
--load

.PHONY: ko-build
ko-build: ko
KO_DOCKER_REPO=$(firstword $(subst :, ,${IMG})) \
GIT_VERSION=$(shell git describe --tags --dirty --always) \
GIT_COMMIT=$(shell git rev-parse HEAD) \
BUILD_DATE=$(shell date +%Y-%m-%dT%H:%M:%S%z) \
ko build --tags $(word 2,$(subst :, ,${IMG})) --platform=${IMG_PLATFORM} --bare --sbom ${IMG_SBOM} .

# Push commands
.PHONY: docker-push-classic
docker-push-classic: docker-build
docker push $(IMG)

.PHONY: docker-buildx-push
docker-buildx-push:
docker buildx build . --target bin \
--tag $(IMG) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--push \
--platform ${IMG_PLATFORM}

.PHONY: ko-push
ko-push: ko
KO_DOCKER_REPO=$(firstword $(subst :, ,${IMG})) \
GIT_VERSION=$(shell git describe --tags --dirty --always) \
GIT_COMMIT=$(shell git rev-parse HEAD) \
BUILD_DATE=$(shell date +%Y-%m-%dT%H:%M:%S%z) \
ko build --tags $(word 2,$(subst :, ,${IMG})) --platform=${IMG_PLATFORM} --bare --sbom ${IMG_SBOM} --push .

# Default push methods using ko (for backward compatibility)
.PHONY: aws-load-balancer-controller-push
aws-load-balancer-controller-push: ko
KO_DOCKER_REPO=$(firstword $(subst :, ,${IMG})) \
GIT_VERSION=$(shell git describe --tags --dirty --always) \
GIT_COMMIT=$(shell git rev-parse HEAD) \
BUILD_DATE=$(shell date +%Y-%m-%dT%H:%M:%S%z) \
ko build --tags $(word 2,$(subst :, ,${IMG})) --platform=${IMG_PLATFORM} --bare --sbom ${IMG_SBOM} .
aws-load-balancer-controller-push: ko-push

.PHONY: docker-push
docker-push: aws-load-balancer-controller-push

# Push the docker image using docker buildx
docker-push-w-buildx:
docker buildx build . --target bin \
--tag $(IMG) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--push \
--platform ${IMG_PLATFORM}

# find or download controller-gen
# download controller-gen if necessary
Expand Down
Loading