diff --git a/examples/simple-game-server/Dockerfile.windows b/examples/simple-game-server/Dockerfile.windows index e2f14d67d4..2c66e96dd5 100644 --- a/examples/simple-game-server/Dockerfile.windows +++ b/examples/simple-game-server/Dockerfile.windows @@ -16,16 +16,27 @@ # Use `--build-arg WINDOWS_VERSION=` to select the correct base image # See https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility # for details. + +# Build Stage ARG WINDOWS_VERSION=ltsc2019 +FROM --platform=linux/amd64 golang:1.20.4 as builder +WORKDIR /go/src +COPY . agones.dev/agones + +WORKDIR /go/src/agones.dev/agones/examples/simple-game-server + +RUN GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o simple-game-server.exe main.go + +RUN ls -ltr /go/src/agones.dev/agones/examples/simple-game-server FROM mcr.microsoft.com/windows/servercore:${WINDOWS_VERSION} -# Unlike the Linux image the binary is built on the host since buildx cannot -# invoke RUN commands for Windows Containers and multi-stage images -# cannot copy data between OSes. -COPY ["bin/simple-game-server.exe", "/server/simple-game-server.exe"] +WORKDIR / + +COPY --from=builder /go/src/agones.dev/agones/examples/simple-game-server/simple-game-server.exe /server -WORKDIR /server EXPOSE 7654 USER ContainerUser + ENTRYPOINT ["C:\\server\\simple-game-server.exe"] + diff --git a/examples/simple-game-server/Makefile b/examples/simple-game-server/Makefile index d25d1898bf..dc3da019b5 100644 --- a/examples/simple-game-server/Makefile +++ b/examples/simple-game-server/Makefile @@ -23,7 +23,8 @@ # \_/ \__,_|_| |_|\__,_|_.__/|_|\___|___/ # -REGISTRY ?= us-docker.pkg.dev/agones-images/examples +REPOSITORY ?= +PROD_REPO ?= us-docker.pkg.dev/agones-images/examples BUILDX_WINDOWS_BUILDER = windows-builder # Versions of Windows Server to support, default is Windows Server 2019. # For the full list of tags see https://hub.docker.com/_/microsoft-windows-servercore. @@ -37,7 +38,11 @@ WITH_ARM64 ?= 1 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) project_path := $(dir $(mkfile_path)) -server_tag = $(REGISTRY)/simple-game-server:0.17 +ifeq ($(REPOSITORY),) + server_tag := simple-game-server:0.17 +else + server_tag := $(REPOSITORY)/simple-game-server:0.17 +endif ifeq ($(WITH_WINDOWS), 1) server_tag_linux_amd64 = $(server_tag)-linux-amd64 @@ -103,14 +108,10 @@ push-windows-images: $(foreach winver, $(WINDOWS_VERSIONS), push-windows-image-$ push-windows-image-%: $(MAKE) WINDOWS_DOCKER_PUSH_ARGS=--push build-windows-image-$* -build-windows-image-%: build-windows-binary ensure-windows-buildx +build-windows-image-%: ensure-windows-buildx cd $(root_path) && DOCKER_CLI_EXPERIMENTAL=enabled \ docker buildx build --platform windows/amd64 --builder $(BUILDX_WINDOWS_BUILDER) -f $(project_path)Dockerfile.windows \ - --tag=$(server_tag)-windows_amd64-$* --build-arg WINDOWS_VERSION=$* examples/simple-game-server/ $(WINDOWS_DOCKER_PUSH_ARGS) - -# Builds the server binary for Windows (amd64). -build-windows-binary: - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o bin/simple-game-server.exe main.go + --tag=$(server_tag)-windows_amd64-$* --build-arg WINDOWS_VERSION=$* . $(WINDOWS_DOCKER_PUSH_ARGS) ensure-windows-buildx: # TODO: Remove `--use` and specify `--builder` for each buildx command once Docker 19.03.13 is available. @@ -128,8 +129,12 @@ build-linux-image-arm64: # check if hosted on Google Artifact Registry gar-check: - gcloud container images describe $(server_tag) + gcloud container images describe $(PROD_REPO)/$(server_tag) #output the tag for this image echo-image-tag: - @echo $(server_tag) + @echo $(PROD_REPO)/$(server_tag) + +# build and push the simple-game-server image with specified tag +cloud-build: + cd $(root_path) && gcloud builds submit --config=./examples/simple-game-server/cloudbuild.yaml \ No newline at end of file diff --git a/examples/simple-game-server/cloudbuild.yaml b/examples/simple-game-server/cloudbuild.yaml new file mode 100644 index 0000000000..593cb19406 --- /dev/null +++ b/examples/simple-game-server/cloudbuild.yaml @@ -0,0 +1,40 @@ +# Copyright 2023 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. + +steps: + # + # Creates the initial make + docker build platform + # + - name: "ubuntu" + script: | + echo 'FROM gcr.io/cloud-builders/docker\nRUN apt-get install make\nENTRYPOINT [\"/usr/bin/make\"]' > Dockerfile.build + - name: gcr.io/cloud-builders/docker + id: build-make-docker + entrypoint: "docker" + args: ["build", "-f", "Dockerfile.build", "-t", "make-docker", "."] + + # build and push simple-game-server image to GCR + - name: "make-docker" + id: push + dir: "/workspace/examples/simple-game-server" + env: + - REPOSITORY=${_REPOSITORY} + script: | + make push +options: + dynamic_substitutions: true + +substitutions: + _REPOSITORY: us-docker.pkg.dev/${PROJECT_ID}/examples +timeout: 1800s