Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

feat(windows): Adds demo containers based on Windows #3921

Merged
merged 1 commit into from
Sep 9, 2021
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
42 changes: 38 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ DEMO_TARGETS = bookbuyer bookthief bookstore bookwarehouse tcp-echo-server tcp-c
DEMO_BUILD_TARGETS = $(addprefix build-, $(DEMO_TARGETS))
.PHONY: $(DEMO_BUILD_TARGETS)
$(DEMO_BUILD_TARGETS): NAME=$(@:build-%=%)
ifeq ($(OS), windows)
EXT=.exe
endif
$(DEMO_BUILD_TARGETS):
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./demo/bin/$(NAME)/$(NAME) ./demo/cmd/$(NAME)
GOOS=$(OS) GOARCH=amd64 CGO_ENABLED=0 go build -o ./demo/bin/$(NAME)/$(NAME)$(EXT) ./demo/cmd/$(NAME)
@if [ -f demo/$(NAME).html.template ]; then cp demo/$(NAME).html.template demo/bin/$(NAME); fi

.PHONE: build-bookwatcher
Expand All @@ -189,9 +192,23 @@ DOCKER_DEMO_TARGETS = $(addprefix docker-build-, $(DEMO_TARGETS))
.PHONY: $(DOCKER_DEMO_TARGETS)
$(DOCKER_DEMO_TARGETS): NAME=$(@:docker-build-%=%)
$(DOCKER_DEMO_TARGETS):
make build-$(NAME)
make OS=linux build-$(NAME)
docker build -t $(CTR_REGISTRY)/$(NAME):$(CTR_TAG) -f dockerfiles/Dockerfile.$(NAME) demo/bin/$(NAME)


# docker-build-windows-bookbuyer, etc
# This command can be used to push the images as well if the ARGS is set to --push
# see https://docs.docker.com/engine/reference/commandline/buildx_build/#push
# The reason for that is that on linux we can't load a Windows image so we need to build and push with one command.
DOCKER_WINDOWS_DEMO_TARGETS = $(addprefix docker-build-windows-, $(DEMO_TARGETS))
.PHONY: $(DOCKER_WINDOWS_DEMO_TARGETS)
$(DOCKER_WINDOWS_DEMO_TARGETS): OS = windows
$(DOCKER_WINDOWS_DEMO_TARGETS): NAME=$(@:docker-build-windows-%=%)
$(DOCKER_WINDOWS_DEMO_TARGETS):
make OS=windows build-$(NAME)
@if ! docker buildx ls | grep -q "img-builder "; then echo "Setting buildx img-builder"; docker buildx create --name img-builder --use; fi
docker buildx build --platform "windows/amd64" -t $(CTR_REGISTRY)/$(NAME)-windows:$(CTR_TAG) $(ARGS) -f dockerfiles/Dockerfile.$(NAME).windows demo/bin/$(NAME)

docker-build-init:
docker build -t $(CTR_REGISTRY)/init:$(CTR_TAG) - < dockerfiles/Dockerfile.init

Expand Down Expand Up @@ -231,10 +248,27 @@ VERIFY_TAGS = 0
.PHONY: $(DOCKER_PUSH_TARGETS)
$(DOCKER_PUSH_TARGETS): NAME=$(@:docker-push-%=%)
$(DOCKER_PUSH_TARGETS):
@if [ $(VERIFY_TAGS) != 1 ]; then make docker-build-$(NAME) && docker push "$(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; else bash scripts/publish-image.sh $(NAME); fi
@if [ $(VERIFY_TAGS) != 1 ]; then make docker-build-$(NAME) && docker push "$(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; else bash scripts/publish-image.sh $(NAME) "linux"; fi


DOCKER_PUSH_WINDOWS_TARGETS = $(addprefix docker-push-windows-, $(DEMO_TARGETS))
VERIFY_TAGS = 0
.PHONY: $(DOCKER_PUSH_WINDOWS_TARGETS)
$(DOCKER_PUSH_WINDOWS_TARGETS): NAME=$(@:docker-push-%=%)
$(DOCKER_PUSH_WINDOWS_TARGETS):
@if [ $(VERIFY_TAGS) != 1 ]; then make ARGS=--output=type=registry docker-build-$(NAME); else bash scripts/publish-image.sh $(addprefix windows-, $(NAME)) "windows"; fi


.PHONY: docker-linux-push
docker-linux-push: $(DOCKER_PUSH_TARGETS)

# notably the init container is missing here because we don't use it for windows
OSM_CONTROL_PLANE_TARGETS = $(addprefix docker-push-, init-osm-controller osm-controller osm-injector osm-crds osm-crd-converter)
.PHONY: docker-windows-push
docker-windows-push: $(DOCKER_PUSH_WINDOWS_TARGETS) $(OSM_CONTROL_PLANE_TARGETS)

.PHONY: docker-push
docker-push: $(DOCKER_PUSH_TARGETS)
docker-push: docker-linux-push docker-windows-push

.PHONY: shellcheck
shellcheck:
Expand Down
4 changes: 2 additions & 2 deletions demo/run-osm-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ if [ "$DEPLOY_ON_OPENSHIFT" = true ] ; then
fi

if [ "$PUBLISH_IMAGES" = true ]; then
make docker-push
fi
make docker-linux-push
fi

./scripts/create-container-registry-creds.sh "$K8S_NAMESPACE"

Expand Down
2 changes: 1 addition & 1 deletion demo/run-osm-multicluster-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ docker info > /dev/null || { echo "Docker daemon is not running"; exit 1; }
make build-osm

# Push to registry - needs to happen after registry creation
make docker-push
make docker-linux-push


echo "Kubernetes contexts to be deployed to: $MULTICLUSTER_CONTEXTS"
Expand Down
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.bookbuyer.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY bookbuyer.exe bookbuyer.html.template /
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.bookstore.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY bookstore.exe bookstore.html.template /
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.bookthief.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY bookthief.exe bookthief.html.template /
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.bookwarehouse.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY bookwarehouse.exe /
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.tcp-client.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY tcp-client.exe /
5 changes: 5 additions & 0 deletions dockerfiles/Dockerfile.tcp-echo-server.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BUILD_OS=mcr.microsoft.com/windows/nanoserver
ARG BUILD_TAG=ltsc2022

FROM $BUILD_OS:$BUILD_TAG
COPY tcp-echo-server.exe /
10 changes: 8 additions & 2 deletions scripts/publish-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# shellcheck disable=SC1091

IMAGE_TAG=$1
OS=$2
IMAGE_REPO=openservicemesh

if [ -z "${CTR_TAG}" ]
Expand All @@ -19,6 +20,11 @@ exists=$(echo "$version_list" | jq --arg t "${CTR_TAG}" '.tags | index($t)')

if [[ $exists == null ]]
then
make docker-build-"$IMAGE_TAG"
docker push "$IMAGE_REPO/$IMAGE_TAG:${CTR_TAG}" || { echo "Error pushing images to container registry $(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; exit 1; }
if [[ $OS == "linux" ]]
then
make docker-build-"$IMAGE_TAG"
docker push "$IMAGE_REPO/$IMAGE_TAG:${CTR_TAG}" || { echo "Error pushing images to container registry $(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; exit 1; }
else
make ARGS=--push "docker-build-$(NAME)"
fi
fi