Skip to content

Commit

Permalink
Build kjob in docker to remove goland dependency. (#305)
Browse files Browse the repository at this point in the history
* remove go dependency

Signed-off-by: Piotr Pawłowski <ppawl@google.com>

---------

Signed-off-by: Piotr Pawłowski <ppawl@google.com>
  • Loading branch information
pawloch00 authored Dec 30, 2024
1 parent 0e41cd6 commit 35c55de
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
KUEUE_REPO=https://github.com/kubernetes-sigs/kueue.git
KUEUE_TMP_PATH=/tmp/xpk_tmp/kueue

KUBECTL_VERSION := $(shell curl -L -s https://dl.k8s.io/release/stable.txt)
KUEUE_VERSION=v0.9.1
Expand All @@ -11,11 +10,12 @@ KUBECTL_URL = "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/$(OS)/$(PLATFORM
KUEUECTL_URL = "https://github.com/kubernetes-sigs/kueue/releases/download/$(KUEUE_VERSION)/kubectl-kueue-$(OS)-$(PLATFORM)"

PROJECT_DIR := $(realpath $(shell dirname $(firstword $(MAKEFILE_LIST))))

KJOB_DOCKER_IMG := xpk_kjob
KJOB_DOCKER_CONTAINER := xpk_kjob_container
BIN_PATH=$(PROJECT_DIR)/bin

.PHONY: install
install: check-python check-go check-gcloud install-kueuectl install-kjob pip-install
install: check-python check-gcloud install-kueuectl install-kjob pip-install

.PHONY: install-dev
install-dev: check-python check-gcloud mkdir-bin install-kubectl install-kueuectl install-kjob pip-install install-pytest
Expand All @@ -37,11 +37,12 @@ run-integrationtests:

.PHONY: install-kjob
install-kjob: install-kubectl
git clone --depth 1 --branch $(KUEUE_VERSION) $(KUEUE_REPO) $(KUEUE_TMP_PATH)
make -C $(KUEUE_TMP_PATH)/cmd/experimental/kjobctl kubectl-kjob
mv $(KUEUE_TMP_PATH)/cmd/experimental/kjobctl/bin/kubectl-kjob $(BIN_PATH)/kubectl-kjob
rm -rf $(KUEUE_TMP_PATH)

docker build -f tools/Dockerfile-kjob -t $(KJOB_DOCKER_IMG) tools/
docker run -idt --name $(KJOB_DOCKER_CONTAINER) $(KJOB_DOCKER_IMG)
docker cp $(KJOB_DOCKER_CONTAINER):/kjob/bin/kubectl-kjob $(BIN_PATH)/kubectl-kjob
docker rm -f $(KJOB_DOCKER_CONTAINER)
docker image rm $(KJOB_DOCKER_IMG)
$(BIN_PATH)/kubectl-kjob --help
.PHONY: mkdir-bin
mkdir-bin:
mkdir -p $(BIN_PATH)
Expand All @@ -56,10 +57,6 @@ install-kueuectl: install-kubectl
curl -Lo $(BIN_PATH)/kubectl-kueue $(KUEUECTL_URL)
chmod +x $(BIN_PATH)/kubectl-kueue

.PHONY: check-go
check-go:
go version || (echo "go not installed, use this link to install: https://cloud.google.com/sdk/docs/install" && exit 1)

.PHONY: check-gcloud
check-gcloud:
gcloud version || (echo "gcloud not installed, use this link to install: https://cloud.google.com/sdk/docs/install" && exit 1)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Following tools must be installed:

- python >= 3.10 (download from [here](https://www.python.org/downloads/))
- gcloud (install from [here](https://cloud.google.com/sdk/gcloud#download_and_install_the))
- go ([installation instructions](https://go.dev/doc/install))
- docker ([installation instruction](https://docs.docker.com/engine/install/))
- pip ([installation instruction](https://pip.pypa.io/en/stable/installation/))
- python venv ([installation instruction](https://virtualenv.pypa.io/en/latest/installation.html))
Expand Down
50 changes: 50 additions & 0 deletions tools/Dockerfile-kjob
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Use a google-cloud-cli image as the base
ARG BASE_IMAGE=gcr.io/google.com/cloudsdktool/google-cloud-cli:stable
FROM ${BASE_IMAGE}

# Install necessary tools and libraries
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release \
git \
make \
unzip \
wget

# Install Go
ARG GO_VERSION=1.23.0
RUN wget -q "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O go.tar.gz && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# Set GOPATH and add to PATH
ENV GOPATH /go
ENV PATH $PATH:/usr/local/go/bin:$GOPATH/bin

# Clone the kjob repository
ARG KJOB_BRANCH=main
RUN git clone --branch ${KJOB_BRANCH} https://github.com/kubernetes-sigs/kjob.git /kjob

# Build the gcluster binary
WORKDIR /kjob
RUN make kubectl-kjob

0 comments on commit 35c55de

Please sign in to comment.