Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud build script for simple-game-server #3314

Merged
merged 8 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 11 additions & 6 deletions examples/simple-game-server/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
# 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.
ARG WINDOWS_VERSION=ltsc2019

FROM mcr.microsoft.com/windows/servercore:${WINDOWS_VERSION}
# Build Stage
FROM --platform=linux/amd64 golang:1.20.4 as base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "builder" is more common.

Suggested change
FROM --platform=linux/amd64 golang:1.20.4 as base
FROM --platform=linux/amd64 golang:1.20.4 as builder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated with builder


# 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 /app
COPY go.mod go.sum ./
markmandel marked this conversation as resolved.
Show resolved Hide resolved
COPY main.go ./

RUN GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o bin/simple-game-server.exe main.go
markmandel marked this conversation as resolved.
Show resolved Hide resolved

FROM mcr.microsoft.com/windows/servercore:ltsc2019
WORKDIR /server

COPY --from=base /app/bin/simple-game-server.exe /server/simple-game-server.exe

EXPOSE 7654
USER ContainerUser
ENTRYPOINT ["C:\\server\\simple-game-server.exe"]
19 changes: 12 additions & 7 deletions examples/simple-game-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 := $(REGISTRY)/simple-game-server:0.17
endif

ifeq ($(WITH_WINDOWS), 1)
server_tag_linux_amd64 = $(server_tag)-linux-amd64
Expand Down Expand Up @@ -103,15 +108,11 @@ 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

ensure-windows-buildx:
# TODO: Remove `--use` and specify `--builder` for each buildx command once Docker 19.03.13 is available.
# `--use` sets the global default buildx context to $(BUILDX_WINDOWS_BUILDER).
Expand All @@ -133,3 +134,7 @@ gar-check:
#output the tag for this image
echo-image-tag:
@echo $(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
40 changes: 40 additions & 0 deletions examples/simple-game-server/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading