Skip to content

Commit

Permalink
modify script to build container image
Browse files Browse the repository at this point in the history
  • Loading branch information
tenzen-y committed Nov 12, 2021
1 parent 2392b88 commit 8ff0d76
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 33 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
HAS_LINT := $(shell command -v golangci-lint;)
COMMIT := v1beta1-$(shell git rev-parse --short=7 HEAD)
KATIB_REGISTRY := docker.io/kubeflowkatib
CPU_ARCH ?= amd64

# Run tests
.PHONY: test
Expand Down Expand Up @@ -48,11 +49,12 @@ endif
cd ./pkg/apis/manager/health && ./build.sh

# Build images for the Katib v1beta1 components.
build: generate
ifeq ($(and $(REGISTRY),$(TAG)),)
$(error REGISTRY and TAG must be set. Usage: make build REGISTRY=<registry> TAG=<tag>)
#build: generate
build:
ifeq ($(and $(REGISTRY),$(TAG),$(CPU_ARCH)),)
$(error REGISTRY and TAG must be set. Usage: make build REGISTRY=<registry> TAG=<tag> CPU_ARCH=<cpu-architecture>)
endif
bash scripts/v1beta1/build.sh $(REGISTRY) $(TAG)
bash scripts/v1beta1/build.sh $(REGISTRY) $(TAG) $(CPU_ARCH)

# Build and push Katib images from the latest master commit.
push-latest: generate
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ see the following user guides:
## Requirements

- [Go](https://golang.org/) (1.17 or later)
- [Docker](https://docs.docker.com/) (17.05 or later)
- [Docker](https://docs.docker.com/) (20.10 or later)
- [Java](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html) (8 or later)
- [Python](https://www.python.org/) (3.9 or later)
- [kustomize](https://kustomize.io/) (4.0.5 or later)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tensorflow/tensorflow:1.15.4-py3
FROM tensorflow/tensorflow:2.7.0

ENV TARGET_DIR /opt/enas-cnn-cifar10

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tensorflow/tensorflow:1.15.4-gpu-py3
FROM tensorflow/tensorflow:2.7.0-gpu

ENV TARGET_DIR /opt/enas-cnn-cifar10

Expand Down
65 changes: 39 additions & 26 deletions scripts/v1beta1/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,29 @@ set -e

REGISTRY=$1
TAG=$2
ARCH=$3

if [[ -z "$REGISTRY" || -z "$TAG" ]]; then
echo "Image registry and tag must be set"
echo "Usage: $0 <image-registry> <image-tag>" 1>&2
if [[ -z "$REGISTRY" || -z "$TAG" || -z "$ARCH" ]]; then
echo "Image registry, tag and architecture must be set"
echo "Usage: $0 <image-registry> <image-tag> <cpu-architecture>" 1>&2
exit 1
fi

SUPPORTED_CPU_ARCHS=$(docker buildx inspect | grep 'Platforms' | sed -e 's|Platforms: ||' -e 's|,||g' -e 's|linux/||g')
function check_specified_cpu_arch() {
for SUPPORTED_ARCH in $SUPPORTED_CPU_ARCHS; do \
if [ $ARCH = $SUPPORTED_ARCH ]; then \
return 0
fi;
done
echo "CPU architecture '$ARCH' is not supported"
echo "You can use '$SUPPORTED_CPU_ARCHS'"
return 1
}
check_specified_cpu_arch

VERSION="v1beta1"
CMD_PREFIX="cmd"
MACHINE_ARCH=$(uname -m)

echo "Building images for Katib ${VERSION}..."
echo "Image registry: ${REGISTRY}"
Expand All @@ -41,77 +54,77 @@ cd ${SCRIPT_ROOT}

# Katib core images
echo -e "\nBuilding Katib controller image...\n"
docker build -t ${REGISTRY}/katib-controller:${TAG} -f ${CMD_PREFIX}/katib-controller/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/katib-controller:${TAG} -f ${CMD_PREFIX}/katib-controller/${VERSION}/Dockerfile .

echo -e "\nBuilding Katib DB manager image...\n"
docker build -t ${REGISTRY}/katib-db-manager:${TAG} -f ${CMD_PREFIX}/db-manager/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/katib-db-manager:${TAG} -f ${CMD_PREFIX}/db-manager/${VERSION}/Dockerfile .

# TODO (andreyvelich): Switch to ${CMD_PREFIX}/ui/${VERSION}/Dockerfile once old UI is deprecated.
echo -e "\nBuilding Katib UI image...\n"
docker build -t ${REGISTRY}/katib-ui:${TAG} -f ${CMD_PREFIX}/new-ui/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/katib-ui:${TAG} -f ${CMD_PREFIX}/new-ui/${VERSION}/Dockerfile .

echo -e "\nBuilding Katib cert generator image...\n"
docker build -t ${REGISTRY}/cert-generator:${TAG} -f ${CMD_PREFIX}/cert-generator/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/cert-generator:${TAG} -f ${CMD_PREFIX}/cert-generator/${VERSION}/Dockerfile .

echo -e "\nBuilding file metrics collector image...\n"
docker build -t ${REGISTRY}/file-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/file-metricscollector/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/file-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/file-metricscollector/Dockerfile .

echo -e "\nBuilding TF Event metrics collector image...\n"
if [ $MACHINE_ARCH == "ppc64le" ]; then
docker build -t ${REGISTRY}/tfevent-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/tfevent-metricscollector/Dockerfile.ppc64le .
if [ $ARCH == "ppc64le" ]; then
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/tfevent-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/tfevent-metricscollector/Dockerfile.ppc64le .
else
docker build -t ${REGISTRY}/tfevent-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/tfevent-metricscollector/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/tfevent-metrics-collector:${TAG} -f ${CMD_PREFIX}/metricscollector/${VERSION}/tfevent-metricscollector/Dockerfile .
fi

# Suggestion images
echo -e "\nBuilding suggestion images..."

echo -e "\nBuilding hyperopt suggestion...\n"
docker build -t ${REGISTRY}/suggestion-hyperopt:${TAG} -f ${CMD_PREFIX}/suggestion/hyperopt/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-hyperopt:${TAG} -f ${CMD_PREFIX}/suggestion/hyperopt/${VERSION}/Dockerfile .

echo -e "\nBuilding chocolate suggestion...\n"
docker build -t ${REGISTRY}/suggestion-chocolate:${TAG} -f ${CMD_PREFIX}/suggestion/chocolate/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-chocolate:${TAG} -f ${CMD_PREFIX}/suggestion/chocolate/${VERSION}/Dockerfile .

echo -e "\nBuilding hyperband suggestion...\n"
docker build -t ${REGISTRY}/suggestion-hyperband:${TAG} -f ${CMD_PREFIX}/suggestion/hyperband/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-hyperband:${TAG} -f ${CMD_PREFIX}/suggestion/hyperband/${VERSION}/Dockerfile .

echo -e "\nBuilding skopt suggestion...\n"
docker build -t ${REGISTRY}/suggestion-skopt:${TAG} -f ${CMD_PREFIX}/suggestion/skopt/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-skopt:${TAG} -f ${CMD_PREFIX}/suggestion/skopt/${VERSION}/Dockerfile .

echo -e "\nBuilding goptuna suggestion...\n"
docker build -t ${REGISTRY}/suggestion-goptuna:${TAG} -f ${CMD_PREFIX}/suggestion/goptuna/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-goptuna:${TAG} -f ${CMD_PREFIX}/suggestion/goptuna/${VERSION}/Dockerfile .

echo -e "\nBuilding optuna suggestion...\n"
docker build -t ${REGISTRY}/suggestion-optuna:${TAG} -f ${CMD_PREFIX}/suggestion/optuna/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-optuna:${TAG} -f ${CMD_PREFIX}/suggestion/optuna/${VERSION}/Dockerfile .

echo -e "\nBuilding ENAS suggestion...\n"
docker build -t ${REGISTRY}/suggestion-enas:${TAG} -f ${CMD_PREFIX}/suggestion/nas/enas/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-enas:${TAG} -f ${CMD_PREFIX}/suggestion/nas/enas/${VERSION}/Dockerfile .

echo -e "\nBuilding DARTS suggestion...\n"
docker build -t ${REGISTRY}/suggestion-darts:${TAG} -f ${CMD_PREFIX}/suggestion/nas/darts/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/suggestion-darts:${TAG} -f ${CMD_PREFIX}/suggestion/nas/darts/${VERSION}/Dockerfile .

# Early stopping images
echo -e "\nBuilding early stopping images...\n"

echo -e "\nBuilding median stopping rule...\n"
docker build -t ${REGISTRY}/earlystopping-medianstop:${TAG} -f ${CMD_PREFIX}/earlystopping/medianstop/${VERSION}/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/earlystopping-medianstop:${TAG} -f ${CMD_PREFIX}/earlystopping/medianstop/${VERSION}/Dockerfile .

# Training container images
echo -e "\nBuilding training container images..."

echo -e "\nBuilding mxnet mnist training container example...\n"
docker build -t ${REGISTRY}/mxnet-mnist:${TAG} -f examples/${VERSION}/trial-images/mxnet-mnist/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/mxnet-mnist:${TAG} -f examples/${VERSION}/trial-images/mxnet-mnist/Dockerfile .

echo -e "\nBuilding PyTorch mnist training container example...\n"
docker build -t ${REGISTRY}/pytorch-mnist:${TAG} -f examples/${VERSION}/trial-images/pytorch-mnist/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/pytorch-mnist:${TAG} -f examples/${VERSION}/trial-images/pytorch-mnist/Dockerfile .

echo -e "\nBuilding Keras CIFAR-10 CNN training container example for ENAS with GPU support...\n"
docker build -t ${REGISTRY}/enas-cnn-cifar10-gpu:${TAG} -f examples/${VERSION}/trial-images/enas-cnn-cifar10/Dockerfile.gpu .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/enas-cnn-cifar10-gpu:${TAG} -f examples/${VERSION}/trial-images/enas-cnn-cifar10/Dockerfile.gpu .

echo -e "\nBuilding Keras CIFAR-10 CNN training container example for ENAS with CPU support...\n"
docker build -t ${REGISTRY}/enas-cnn-cifar10-cpu:${TAG} -f examples/${VERSION}/trial-images/enas-cnn-cifar10/Dockerfile.cpu .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/enas-cnn-cifar10-cpu:${TAG} -f examples/${VERSION}/trial-images/enas-cnn-cifar10/Dockerfile.cpu .

echo -e "\nBuilding PyTorch CIFAR-10 CNN training container example for DARTS...\n"
docker build -t ${REGISTRY}/darts-cnn-cifar10:${TAG} -f examples/${VERSION}/trial-images/darts-cnn-cifar10/Dockerfile .
docker buildx build --platform linux/$ARCH -t ${REGISTRY}/darts-cnn-cifar10:${TAG} -f examples/${VERSION}/trial-images/darts-cnn-cifar10/Dockerfile .

echo -e "\nAll Katib images with ${TAG} tag have been built successfully!\n"

0 comments on commit 8ff0d76

Please sign in to comment.