Skip to content

Commit d5062ce

Browse files
committed
Convert Go example into multi-stage Docker build
Reducing dependencies to working with the examples, this has been converted into a multi stage Docker build. This also removes the client, as nobody is using it, as netcat works perfectly.
1 parent b92ad1d commit d5062ce

10 files changed

Lines changed: 17 additions & 111 deletions

File tree

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# build
16+
FROM golang:1.10.3 as builder
17+
WORKDIR /go/src/simple-udp
18+
19+
COPY examples/simple-udp/main.go .
20+
COPY . /go/src/agones.dev/agones
21+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server .
22+
23+
# final image
1524
FROM alpine:3.7
1625

1726
RUN adduser -D server
18-
19-
COPY ./bin/server /home/server/server
20-
27+
COPY --from=builder /go/src/simple-udp/server /home/server/server
2128
RUN chown -R server /home/server && \
2229
chmod o+x /home/server/server
2330

examples/simple-udp/Makefile

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ REPOSITORY = gcr.io/agones-images
2828
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
2929
project_path := $(dir $(mkfile_path))
3030
server_tag = $(REPOSITORY)/udp-server:0.3
31-
package = agones.dev/agones/examples/simple-udp
31+
root_path = $(realpath $(project_path)/../..)
3232

3333
# _____ _
3434
# |_ _|_ _ _ __ __ _ ___| |_ ___
@@ -37,19 +37,6 @@ package = agones.dev/agones/examples/simple-udp
3737
# |_|\__,_|_| \__, |\___|\__|___/
3838
# |___/
3939

40-
# build both client and server
41-
build: build-server build-client
42-
43-
# Build the server
44-
build-server:
45-
CGO_ENABLED=0 go build -o $(project_path)/server/bin/server -a -installsuffix cgo $(package)/server
46-
4740
# Build a docker image for the server, and tag it
48-
build-server-image:
49-
docker build $(project_path)/server/ --tag=$(server_tag)
50-
51-
# Build the client
52-
build-client:
53-
go build -o $(project_path)/client/bin/client $(package)/client
54-
55-
41+
build:
42+
cd $(root_path) && docker build -f $(project_path)/Dockerfile --tag=$(server_tag) .

examples/simple-udp/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simple UDP Server
22

3-
A very simple UDP logging server and client, for the purposes of demoing and testing
3+
A very simple UDP logging server, for the purposes of demoing and testing
44
running a UDP based server on Agones.
55

66
## Server
@@ -10,7 +10,5 @@ When it receives a text packet, it will send back "ACK:<text content>" as an ech
1010

1111
If it receives the text "EXIT", then it will `sys.Exit(0)`
1212

13-
## Client
14-
Client will read in from stdin and send each line to the server.
15-
16-
Address defaults to `localhost:7654` but can be changed through the `address` flag.
13+
To learn how to deploy your edited version of go server to gcp, please check out this link: [Edit Your First Game Server (Go)](../../../docs/edit_first_game_server.md),
14+
or also look at the [`Makefile`](./Makefile).

examples/simple-udp/client/main.go

Lines changed: 0 additions & 85 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Google Inc. All Rights Reserved.
1+
// Copyright 2018 Google Inc. All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

examples/simple-udp/server/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)