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

Add ARG for base image customization #738

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RELEASE_REGISTRY?=gcr.io/k8s-staging-scheduler-plugins
RELEASE_VERSION?=v$(shell date +%Y%m%d)-$(shell git describe --tags --match "v*")
RELEASE_IMAGE:=kube-scheduler:$(RELEASE_VERSION)
RELEASE_CONTROLLER_IMAGE:=controller:$(RELEASE_VERSION)
GO_BASE_IMAGE?=golang

# VERSION is the scheduler's version
#
Expand Down Expand Up @@ -80,6 +81,8 @@ release-image.amd64: clean
REGISTRY=$(RELEASE_REGISTRY) \
IMAGE=$(RELEASE_IMAGE)-amd64 \
CONTROLLER_IMAGE=$(RELEASE_CONTROLLER_IMAGE)-amd64 \
GO_BASE_IMAGE=$(GO_BASE_IMAGE) \
ALPINE_BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
hack/build-images.sh

.PHONY: release-image.arm64v8
Expand All @@ -89,6 +92,8 @@ release-image.arm64v8: clean
REGISTRY=$(RELEASE_REGISTRY) \
IMAGE=$(RELEASE_IMAGE)-arm64 \
CONTROLLER_IMAGE=$(RELEASE_CONTROLLER_IMAGE)-arm64 \
GO_BASE_IMAGE=$(GO_BASE_IMAGE) \
ALPINE_BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
hack/build-images.sh

.PHONY: push-release-images
Expand Down
6 changes: 4 additions & 2 deletions build/controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG ARCH
FROM golang:1.20
ARG GO_BASE_IMAGE=golang
ARG ALPINE_BASE_IMAGE=$ARCH/alpine
FROM $GO_BASE_IMAGE:1.21

WORKDIR /go/src/sigs.k8s.io/scheduler-plugins
COPY . .
ARG ARCH
RUN make build-controller.$ARCH

FROM $ARCH/alpine:3.16
FROM $ALPINE_BASE_IMAGE:3.16

COPY --from=0 /go/src/sigs.k8s.io/scheduler-plugins/bin/controller /bin/controller

Expand Down
6 changes: 4 additions & 2 deletions build/scheduler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG ARCH
FROM golang:1.20
ARG GO_BASE_IMAGE=golang
ARG ALPINE_BASE_IMAGE=$ARCH/alpine
FROM $GO_BASE_IMAGE:1.21

WORKDIR /go/src/sigs.k8s.io/scheduler-plugins
COPY . .
ARG ARCH
ARG RELEASE_VERSION
RUN RELEASE_VERSION=${RELEASE_VERSION} make build-scheduler.$ARCH

FROM $ARCH/alpine:3.16
FROM $ALPINE_BASE_IMAGE:3.16

COPY --from=0 /go/src/sigs.k8s.io/scheduler-plugins/bin/kube-scheduler /bin/kube-scheduler

Expand Down
8 changes: 7 additions & 1 deletion hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ CONTROLLER_DIR="${SCRIPT_ROOT}"/build/controller
REGISTRY=${REGISTRY:-"localhost:5000/scheduler-plugins"}
IMAGE=${IMAGE:-"kube-scheduler:latest"}
CONTROLLER_IMAGE=${CONTROLLER_IMAGE:-"controller:latest"}

RELEASE_VERSION=${RELEASE_VERSION:-"v0.0.0"}

BUILDER=${BUILDER:-"docker"}
Expand All @@ -40,15 +39,22 @@ if [[ "${ARCH}" == "arm64" ]]; then
ARCH="arm64v8"
fi

GO_BASE_IMAGE=${GO_BASE_IMAGE:-"golang"}
ALPINE_BASE_IMAGE=${ALPINE_BASE_IMAGE:-"$ARCH/alpine"}

cd "${SCRIPT_ROOT}"

${BUILDER} build \
-f ${SCHEDULER_DIR}/Dockerfile \
--build-arg ARCH=${ARCH} \
--build-arg RELEASE_VERSION=${RELEASE_VERSION} \
--build-arg GO_BASE_IMAGE=${GO_BASE_IMAGE} \
--build-arg ALPINE_BASE_IMAGE=${ALPINE_BASE_IMAGE} \
-t ${REGISTRY}/${IMAGE} .
${BUILDER} build \
-f ${CONTROLLER_DIR}/Dockerfile \
--build-arg ARCH=${ARCH} \
--build-arg RELEASE_VERSION=${RELEASE_VERSION} \
--build-arg GO_BASE_IMAGE=${GO_BASE_IMAGE} \
--build-arg ALPINE_BASE_IMAGE=${ALPINE_BASE_IMAGE} \
-t ${REGISTRY}/${CONTROLLER_IMAGE} .