Skip to content

Commit

Permalink
Support building images locally on machines with two interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DimpleRajaVamsi committed Jul 13, 2023
1 parent df9a0d5 commit bcaff43
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -34,7 +34,7 @@ RUN wget https://vdc-download.vmware.com/vmwb-repository/dcr-public/2ee5a010-bab
RUN unzip VMware-ovftool-4.4.3-18663434-lin.x86_64.zip -d /

# Setup image Builder code
RUN git clone https://github.com/kubernetes-sigs/image-builder.git
RUN git clone https://github.com/DimpleRajaVamsi/image-builder.git
WORKDIR $IMAGE_BUILDER_REPO_NAME

# Running deps-ova to setup packer goss provisioner
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -9,6 +9,7 @@ MAKEFLAGS += -s
# Default variables
BYOI_IMAGE_NAME = vsphere-tanzu-byoi
DEFAULT_ARTIFACTS_CONTAINER_PORT = 8081
DEFAULT_PACKER_HTTP_PORT = 8082
MAKE_HELPERS_PATH = $(shell pwd)/hack/make-helpers
SUPPORTED_VERSIONS_JSON = $(shell pwd)/supported-versions.json

Expand Down Expand Up @@ -65,7 +66,7 @@ build-image-builder-container:
printf "$$green$$BUILD_IMAGE_BUILDER_CONTAINER_HELP_INFO$$clear\n"
else
build-image-builder-container:
docker build -q -t $(BYOI_IMAGE_NAME) .
docker build --platform=linux/amd64 -q -t $(BYOI_IMAGE_NAME) .
endif

define BUILD_NODE_IMAGE
Expand All @@ -81,10 +82,12 @@ define BUILD_NODE_IMAGE
# IMAGE_ARTIFACTS_PATH: [Required] Node image OVA and packer logs output folder.
# ARTIFACTS_CONTAINER_IP: [Required] Host IP on where artifacts container is running.
# ARTIFACTS_CONTAINER_PORT: [Optional] Artifacts container port, defaults to $(DEFAULT_ARTIFACTS_CONTAINER_PORT)
# PACKER_HTTP_PORT: [Optional] Port used by Packer HTTP server for hosting the Preseed/Autoinstall files,
# defaults to $(DEFAULT_PACKER_HTTP_PORT).
#
# Example:
# make build-node-image OS_TARGET=photon-3 KUBERNETES_VERSION=v1.23.15+vmware.1 TKR_SUFFIX=byoi ARTIFACTS_CONTAINER_IP=1.2.3.4 IMAGE_ARTIFACTS_PATH=$(HOME)/image
# make build-node-image OS_TARGET=photon-3 KUBERNETES_VERSION=v1.23.15+vmware.1 TKR_SUFFIX=byoi ARTIFACTS_CONTAINER_IP=1.2.3.4 IMAGE_ARTIFACTS_PATH=$(HOME)/image ARTIFACTS_CONTAINER_PORT=9090
# make build-node-image OS_TARGET=photon-3 KUBERNETES_VERSION=v1.23.15+vmware.1 TKR_SUFFIX=byoi ARTIFACTS_CONTAINER_IP=1.2.3.4 IMAGE_ARTIFACTS_PATH=$(HOME)/image ARTIFACTS_CONTAINER_PORT=9090 PACKER_HTTP_PORT=9091
endef
.PHONY: build-node-image
ifeq ($(PRINT_HELP),y)
Expand Down
2 changes: 2 additions & 0 deletions build-ova.sh
Expand Up @@ -19,6 +19,7 @@ function checkout_image_builder_branch() {
# Check out image builder with specific commit for the
# corresponding k8s version
cd ${image_builder_root}
git pull
git checkout ${IMAGE_BUILDER_COMMIT_ID}
}

Expand Down Expand Up @@ -48,6 +49,7 @@ function generate_packager_configuration() {
python3 image/scripts/tkg_byoi.py setup \
--artifacts_container_ip ${ARTIFACTS_CONTAINER_IP} \
--artifacts_container_port ${ARTIFACTS_CONTAINER_PORT} \
--packer_http_port ${PACKER_HTTP_PORT} \
--default_config_folder ${default_packer_variables} \
--dest_config ${packer_configuration_folder} \
--tkr_metadata_folder ${tkr_metadata_folder} \
Expand Down
11 changes: 10 additions & 1 deletion hack/make-helpers/build-node-image.sh
Expand Up @@ -21,8 +21,14 @@ if [ -z "$ARTIFACTS_CONTAINER_PORT" ]; then
echo "Using default port for artifacts container $DEFAULT_ARTIFACTS_CONTAINER_PORT"
fi

if [ -z "$PACKER_HTTP_PORT" ]; then
# Makefile creates this environment variables
PACKER_HTTP_PORT=$DEFAULT_PACKER_HTTP_PORT
echo "Using default Packer HTTP port $PACKER_HTTP_PORT"
fi

function build_node_image() {
docker run -d --network host \
docker run -d \
--name $(get_node_image_builder_container_name "$KUBERNETES_VERSION" "$OS_TARGET") \
$(get_node_image_builder_container_labels "$KUBERNETES_VERSION" "$OS_TARGET") \
-v $ROOT/ansible:/image-builder/images/capi/image/ansible \
Expand All @@ -34,6 +40,9 @@ function build_node_image() {
-w /image-builder/images/capi/ \
-e ARTIFACTS_CONTAINER_IP=$ARTIFACTS_CONTAINER_IP -e ARTIFACTS_CONTAINER_PORT=$ARTIFACTS_CONTAINER_PORT -e OS_TARGET=$OS_TARGET \
-e TKR_SUFFIX=$TKR_SUFFIX -e IMAGE_BUILDER_COMMIT_ID=$IMAGE_BUILDER_COMMIT_ID -e KUBERNETES_VERSION=$KUBERNETES_VERSION \
-e PACKER_HTTP_PORT=$PACKER_HTTP_PORT \
-p $PACKER_HTTP_PORT:$DEFAULT_PACKER_HTTP_PORT \
--platform linux/amd64 \
$BYOI_IMAGE_NAME
}

Expand Down
2 changes: 1 addition & 1 deletion hack/make-helpers/run-artifacts-container.sh
Expand Up @@ -22,6 +22,6 @@ if [ "$artifacts_container_image_url" == "null" ]; then
fi

container_name=$(get_artifacts_container_name "$KUBERNETES_VERSION")
docker run -d --name $container_name $(get_artifacts_container_labels $KUBERNETES_VERSION) -p $ARTIFACTS_CONTAINER_PORT:80 $artifacts_container_image_url
docker run -d --name $container_name $(get_artifacts_container_labels $KUBERNETES_VERSION) -p $ARTIFACTS_CONTAINER_PORT:80 --platform linux/amd64 $artifacts_container_image_url

next_hint_msg "Use \"make build-node-image OS_TARGET=<os_target> KUBERNETES_VERSION=${KUBERNETES_VERSION} TKR_SUFFIX=<tkr_suffix> ARTIFACTS_CONTAINER_IP=<artifacts_container_ip> IMAGE_ARTIFACTS_PATH=<image_artifacts_path> ARTIFACTS_CONTAINER_PORT=${ARTIFACTS_CONTAINER_PORT}\" to build node image"
5 changes: 5 additions & 0 deletions packer-variables/packer-http-config.j2
@@ -0,0 +1,5 @@
{
"http_port_max": "{{ packer_http_port }}",
"http_port_min": "{{ packer_http_port }}",
"http_ip": "{{ artifacts_container_ip }}"
}
2 changes: 1 addition & 1 deletion packer-variables/vsphere.j2
Expand Up @@ -21,4 +21,4 @@
"linked_clone": "true",
{# To create a snapshot of the Packer VM after customization #}
"create_snapshot": "true"
}
}
2 changes: 2 additions & 0 deletions scripts/tkg_byoi.py
Expand Up @@ -39,6 +39,8 @@ def parse_args():
help='Artifacts container IP')
setup_group.add_argument('--artifacts_container_port', required=False,
help='Artifacts container port, default value is 8081', default="8081")
setup_group.add_argument('--packer_http_port', required=False,
help='Packer HTTP server port, default value is 8082', default="8082")
setup_group.add_argument('--default_config_folder', required=True,
help='Path to default packer variable configuration folder')
setup_group.add_argument('--tkr_metadata_folder', required=True,
Expand Down
2 changes: 1 addition & 1 deletion supported-versions.json
Expand Up @@ -3,7 +3,7 @@
"supported_os": ["photon-3", "ubuntu-2004-efi"],
"artifacts_image": "projects.registry.vmware.com/tkg/tkg-vsphere-linux-resource-bundle:v1.24.9_vmware.1-tkg.1",
"extra_params": {
"image_builder_commit": "1d4b0445b364712c3ab5d3c6f721b808fa0bfa2e"
"image_builder_commit": "c7efc9bb88b254292467d338c9b5a78d8792a0b1"
}
}
}

0 comments on commit bcaff43

Please sign in to comment.