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

Reorganizing Project Layout #119

Merged
merged 38 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
00c200c
root module & automated docker detection & building
khaines Dec 16, 2021
7dc315c
moved initcontainer to root module
khaines Dec 16, 2021
edde070
moving e2e test executable to cmd path
khaines Dec 16, 2021
95c169f
moving nodeagent to cmd path
khaines Dec 16, 2021
09f7a3f
moving operator to cmd path
khaines Dec 16, 2021
c7ce04e
moving operator library to the pkg folder
khaines Dec 16, 2021
695ac41
moving gameserverapi to cmd path
khaines Dec 16, 2021
241e80f
moving allocator to cmd path
khaines Dec 16, 2021
b7fb5ae
doing some tidying of referenced packages
khaines Dec 16, 2021
4b8145d
correcting casing of module and of references
khaines Dec 16, 2021
0e95268
isolating common build environment to its own image
khaines Dec 16, 2021
b5a59c8
tweaking dockerfiles to work with the new process
khaines Dec 16, 2021
601d757
corrected sample docker paths for building.
khaines Dec 17, 2021
4376e1b
updating makefile to create tagged containers for local deployment
khaines Dec 17, 2021
b4a4f67
go 1.17
khaines Dec 17, 2021
8fd9f45
updating go.mod
khaines Dec 17, 2021
ba66703
pathing fixes
khaines Dec 20, 2021
e714450
removing unneeded sudo references in makefile
khaines Dec 20, 2021
70a2974
updating github actions to use go 1.17.5
khaines Dec 20, 2021
02f0fb6
updating more github action steps to reflect changes in paths
khaines Dec 21, 2021
1fa98fc
one more path to update
khaines Dec 21, 2021
1749673
update push target to use generated names
khaines Dec 21, 2021
0e58fa2
updating the create install targets
khaines Dec 21, 2021
a2a049f
kubebuilder compromise for pathing
khaines Dec 21, 2021
6c59e4a
updating dockerfile for operator to reflect recent update
khaines Dec 21, 2021
47d519f
adjusting variables for the create-install-files target to deal with …
khaines Dec 21, 2021
3a9a80c
ensuring image-tag is bound for local test
khaines Dec 21, 2021
1dc57a6
reverting some unrequired quotes
khaines Dec 22, 2021
2d832c9
PR feedback
khaines Dec 22, 2021
2236e3d
Adding `make clean` to developer docs where it is appropriate.
khaines Dec 23, 2021
14a9542
Merge branch 'khaines/reorg-housekeeping' of github.com:khaines/thund…
khaines Dec 23, 2021
99203e5
Reordering lines in build dockerfile to improve caching of modules.
khaines Dec 23, 2021
327559f
Using the correct variable scope for the image tag when making dev in…
khaines Dec 23, 2021
05e72f3
using the init container tag env
khaines Dec 23, 2021
ecac808
deleting the workspace file since it isn't needed
khaines Dec 23, 2021
ea59d00
further unification of image tag use
khaines Dec 23, 2021
2994ab4
fixing some `operator/` paths to 'pkg/operator'
khaines Dec 23, 2021
57fa962
typo
khaines Dec 24, 2021
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
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -27,17 +27,17 @@ jobs:
uses: actions/setup-go@v2.1.3
with:
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
go-version: 1.16.5
go-version: 1.17.5
- name: build Docker images
run: make builddockerlocal
- name: GameServer API service unit tests
run: cd tools/gameserverapi && GIN_MODE=release go test
run: cd cmd/gameserverapi && GIN_MODE=release go test
- name: initcontainer unit tests
run: cd initcontainer && go test
run: cd cmd/initcontainer && go test
- name: nodeagent unit tests
run: cd nodeagent && go test
run: cd cmd/nodeagent && go test
- name: operator unit tests
run: IMAGE_NAME_SAMPLE=thundernetes-netcore-sample IMAGE_NAME_INIT_CONTAINER=thundernetes-initcontainer TAG=$(git rev-list HEAD --max-count=1 --abbrev-commit) make -C operator test
run: IMAGE_NAME_SAMPLE=thundernetes-netcore-sample IMAGE_NAME_INIT_CONTAINER=thundernetes-initcontainer TAG=$(git rev-list HEAD --max-count=1 --abbrev-commit) make -C pkg/operator test
- name: install kind binaries
run: make installkind
- name: create kind cluster
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and push Docker images
run: export $(grep -v '^#' .versions | xargs -d '\n') && make build push
run: export $(grep -v '^#' .versions | xargs -d '\n') && make push
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@

/**/GameLogs/*

installfilesdev
installfilesdev


.uptodate
6 changes: 1 addition & 5 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#!/bin/bash
export OPERATOR_TAG=0.1.0
export NODE_AGENT_TAG=0.1.0
export INIT_CONTAINER_TAG=0.1.0
export NETCORE_SAMPLE_TAG=0.1.0
export OPENARENA_SAMPLE_TAG=0.1.0
export IMAGE_TAG=0.1.0
114 changes: 69 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
NS ?= ghcr.io/playfab

NS ?= ghcr.io/playfab/

export IMAGE_NAME_OPERATOR=thundernetes-operator
export IMAGE_NAME_NODE_AGENT=thundernetes-nodeagent
export IMAGE_NAME_INIT_CONTAINER=thundernetes-initcontainer
export IMAGE_NAME_NETCORE_SAMPLE=thundernetes-netcore-sample
export IMAGE_NAME_OPENARENA_SAMPLE=thundernetes-openarena-sample
export IMAGE_NAME_NETCORE_SAMPLE=thundernetes-netcore
export IMAGE_NAME_OPENARENA_SAMPLE=thundernetes-openarena

export OPERATOR_TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
export NODE_AGENT_TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
export INIT_CONTAINER_TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
export NETCORE_SAMPLE_TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
export OPENARENA_SAMPLE_TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
IMAGE_TAG ?= $(shell git rev-list HEAD --max-count=1 --abbrev-commit)

# local e2e with kind
export KIND_CLUSTER_NAME=kind
Expand All @@ -20,43 +17,65 @@ export KIND_CLUSTER_NAME=kind
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

build:
docker build -f ./operator/Dockerfile -t $(NS)/$(IMAGE_NAME_OPERATOR):$(OPERATOR_TAG) ./operator
docker build -f ./nodeagent/Dockerfile -t $(NS)/$(IMAGE_NAME_NODE_AGENT):$(NODE_AGENT_TAG) ./nodeagent
docker build -f ./initcontainer/Dockerfile -t $(NS)/$(IMAGE_NAME_INIT_CONTAINER):$(INIT_CONTAINER_TAG) ./initcontainer
docker build -f ./samples/netcore/Dockerfile -t $(NS)/$(IMAGE_NAME_NETCORE_SAMPLE):$(NETCORE_SAMPLE_TAG) ./samples/netcore
docker build -f ./samples/openarena/Dockerfile -t $(NS)/$(IMAGE_NAME_OPENARENA_SAMPLE):$(OPENARENA_SAMPLE_TAG) ./samples/openarena
# Support gsed on OSX (installed via brew), falling back to sed. On Linux
# systems gsed won't be installed, so will use sed as expected.
SED ?= $(shell which gsed 2>/dev/null || which sed)

GIT_REVISION := $(shell git rev-parse --short HEAD)
UPTODATE := .uptodate
# Automated DockerFile building
# By convention, every directory with a Dockerfile in it will build an image called ghcr.io/playfab/<directory name>
# An .uptodate file will be created in the directory to indicate that the Dockerfile has been built.
%/$(UPTODATE): %/Dockerfile
@echo
docker build --build-arg=revision=$(GIT_REVISION) -t $(NS)thundernetes-$(shell basename $(@D)) -t $(NS)thundernetes-$(shell basename $(@D)):$(IMAGE_TAG) -f $(@D)/Dockerfile .
@echo
touch $@

# We don't want find to scan inside a bunch of directories, to speed up Dockerfile dectection.
khaines marked this conversation as resolved.
Show resolved Hide resolved
DONT_FIND := -name vendor -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o -name packaging -prune -o -name build-env -prune -o

# Get a list of directories containing Dockerfiles
DOCKERFILES := $(shell find . $(DONT_FIND) -type f -name 'Dockerfile' -print)
UPTODATE_FILES := $(patsubst %/Dockerfile,%/$(UPTODATE),$(DOCKERFILES))
DOCKER_IMAGE_DIRS := $(patsubst %/Dockerfile,%,$(DOCKERFILES))
IMAGE_NAMES := $(foreach dir,$(DOCKER_IMAGE_DIRS),$(patsubst %,$(NS)thundernetes-%,$(shell basename $(dir))))
images:
$(info $(IMAGE_NAMES))
@echo > /dev/null

buildimage: #creates a docker image as a build environment for thundernetes
docker build -t thundernetes-src:$(GIT_REVISION) -f build-env/Dockerfile .

build: buildimage $(UPTODATE_FILES)
khaines marked this conversation as resolved.
Show resolved Hide resolved

push:
docker push $(NS)/$(IMAGE_NAME_OPERATOR):$(OPERATOR_TAG)
docker push $(NS)/$(IMAGE_NAME_NODE_AGENT):$(NODE_AGENT_TAG)
docker push $(NS)/$(IMAGE_NAME_INIT_CONTAINER):$(INIT_CONTAINER_TAG)
docker push $(NS)/$(IMAGE_NAME_NETCORE_SAMPLE):$(NETCORE_SAMPLE_TAG)
docker push $(NS)/$(IMAGE_NAME_OPENARENA_SAMPLE):$(OPENARENA_SAMPLE_TAG)

builddockerlocal:
docker build -f operator/Dockerfile -t $(IMAGE_NAME_OPERATOR):$(OPERATOR_TAG) ./operator
docker build -f nodeagent/Dockerfile -t $(IMAGE_NAME_NODE_AGENT):$(NODE_AGENT_TAG) ./nodeagent
docker build -f initcontainer/Dockerfile -t $(IMAGE_NAME_INIT_CONTAINER):$(INIT_CONTAINER_TAG) ./initcontainer
docker build -f samples/netcore/Dockerfile -t $(IMAGE_NAME_NETCORE_SAMPLE):$(NETCORE_SAMPLE_TAG) ./samples/netcore
docker build -f samples/openarena/Dockerfile -t $(IMAGE_NAME_OPENARENA_SAMPLE):$(OPENARENA_SAMPLE_TAG) ./samples/openarena
push: build
for image in $(IMAGE_NAMES); do \
docker push $$image:$(IMAGE_TAG); \
done

builddockerlocal: build
for image in $(IMAGE_NAMES); do \
localname=`echo $$image| $(SED) -e 's:$(NS)::g'`; \
docker tag $$image:$(IMAGE_TAG) $$localname:$(IMAGE_TAG); \
done

installkind:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
mkdir -p ./operator/testbin/bin
mv ./kind ./operator/testbin/bin/kind
mkdir -p ./pkg/operator/testbin/bin
mv ./kind ./pkg/operator/testbin/bin/kind

createkindcluster:
./operator/testbin/bin/kind create cluster --config ./e2e/kind-config.yaml
./pkg/operator/testbin/bin/kind create cluster --config ./e2e/kind-config.yaml

deletekindcluster:
./operator/testbin/bin/kind delete cluster
./pkg/operator/testbin/bin/kind delete cluster

e2elocal:
kubectl config use-context kind-$(KIND_CLUSTER_NAME)
chmod +x ./e2e/run.sh
./e2e/run.sh config-$(KIND_CLUSTER_NAME) local
IMAGE_TAG=${IMAGE_TAG} ./e2e/run.sh config-$(KIND_CLUSTER_NAME) local

createcrds:
make -C operator install
Expand All @@ -68,19 +87,24 @@ cleanall:

create-install-files:
. .versions && \
IMG=$(NS)/$(IMAGE_NAME_OPERATOR):$${OPERATOR_TAG} \
IMAGE_NAME_INIT_CONTAINER=$(NS)/$(IMAGE_NAME_INIT_CONTAINER) \
IMAGE_NAME_NODE_AGENT=$(NS)/$(IMAGE_NAME_NODE_AGENT) \
INIT_CONTAINER_TAG=$${INIT_CONTAINER_TAG} \
NODE_AGENT_TAG=$${NODE_AGENT_TAG} \
make -C operator create-install-files
IMG=$(NS)$(IMAGE_NAME_OPERATOR):$${IMAGE_TAG} \
IMAGE_NAME_INIT_CONTAINER=$(NS)$(IMAGE_NAME_INIT_CONTAINER) \
IMAGE_NAME_NODE_AGENT=$(NS)$(IMAGE_NAME_NODE_AGENT) \
INIT_CONTAINER_TAG=$${IMAGE_TAG} \
NODE_AGENT_TAG=$${IMAGE_TAG} \
make -C pkg/operator create-install-files

create-install-files-dev:
mkdir -p ./installfilesdev && \
INSTALL_FILES_FOLDER=installfilesdev \
IMG=$(NS)/$(IMAGE_NAME_OPERATOR):$${OPERATOR_TAG} \
IMAGE_NAME_INIT_CONTAINER=$(NS)/$(IMAGE_NAME_INIT_CONTAINER) \
IMAGE_NAME_NODE_AGENT=$(NS)/$(IMAGE_NAME_NODE_AGENT) \
INIT_CONTAINER_TAG=$${INIT_CONTAINER_TAG} \
NODE_AGENT_TAG=$${NODE_AGENT_TAG} \
make -C operator create-install-files
INSTALL_FILES_FOLDER=../../installfilesdev \
IMG=$(NS)$(IMAGE_NAME_OPERATOR):$${IMAGE_TAG} \
IMAGE_NAME_INIT_CONTAINER=$(NS)$(IMAGE_NAME_INIT_CONTAINER) \
IMAGE_NAME_NODE_AGENT=$(NS)$(IMAGE_NAME_NODE_AGENT) \
INIT_CONTAINER_TAG=$${IMAGE_TAG} \
NODE_AGENT_TAG=$${IMAGE_TAG} \
make -C pkg/operator create-install-files

clean:
docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true
rm -rf -- $(UPTODATE_FILES) $(EXES) .cache dist
go clean ./...
13 changes: 13 additions & 0 deletions build-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# build stage
FROM golang:1.17 as builder

WORKDIR /workspace
# Copy the Go Module code
COPY cmd/ ./cmd
COPY e2e/ ./e2e
COPY pkg/ ./pkg
COPY go.mod ./go.mod
khaines marked this conversation as resolved.
Show resolved Hide resolved
COPY go.sum ./go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/cmd/main.go → cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/google/uuid"
mpsv1alpha1 "github.com/playfab/thundernetes/operator/api/v1alpha1"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
dgkanatsios marked this conversation as resolved.
Show resolved Hide resolved
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion e2e/cmd/utilities.go → cmd/e2e/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/pkg/errors"
mpsv1alpha1 "github.com/playfab/thundernetes/operator/api/v1alpha1"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
Expand Down
16 changes: 3 additions & 13 deletions tools/gameserverapi/Dockerfile → cmd/gameserverapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# build stage
FROM golang:1.16 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod ./
COPY go.sum ./
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY *.go ./
ARG revision
FROM thundernetes-src:$revision as builder

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o thundernetes-gameserver-api-service
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o thundernetes-gameserver-api-service ./cmd/gameserverapi
khaines marked this conversation as resolved.
Show resolved Hide resolved

# Use distroless as minimal base image to package the binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/gameserverapi/main.go → cmd/gameserverapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
mpsv1alpha1 "github.com/playfab/thundernetes/operator/api/v1alpha1"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
mpsv1alpha1 "github.com/playfab/thundernetes/operator/api/v1alpha1"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down
12 changes: 12 additions & 0 deletions cmd/initcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# build stage
# build stage
ARG revision
FROM thundernetes-src:$revision as builder

RUN go build -o initcontainer ./cmd/initcontainer/

# final stage
FROM alpine:3.12
WORKDIR /app
COPY --from=builder /workspace/initcontainer /app/
ENTRYPOINT ./initcontainer
File renamed without changes.
File renamed without changes.
16 changes: 3 additions & 13 deletions nodeagent/Dockerfile → cmd/nodeagent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# build stage
FROM golang:1.16 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod ./
COPY go.sum ./
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY *.go ./
ARG revision
FROM thundernetes-src:$revision as builder

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o thundernetes-nodeagent
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o thundernetes-nodeagent ./cmd/nodeagent

# Use distroless as minimal base image to package the binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Release new thundernetes version

- Make sure you update `.version` file on the root of this repository with the new version
- Run `make clean` to ensure any cached artifacts of old builds are deleted.
- Run `make create-install-files`
- Push and merge
- Run the GitHub Actions workflow [here](https://github.com/PlayFab/thundernetes/actions/workflows/publish.yml)
Expand Down Expand Up @@ -68,7 +69,7 @@ for i in {1..50}; do SESSION_ID=$(uuidgen); curl --key ~/private.pem --cert ~/pu
## Run end to end tests locally

```bash
make deletekindcluster && make builddockerlocal && make createkindcluster && make e2elocal
make clean deletekindcluster builddockerlocal createkindcluster e2elocal
```

## Run controller locally
Expand Down Expand Up @@ -225,7 +226,7 @@ gameserverbuild-sample-gqhrm Healthy StandingBy 52.183.88.255 80:10319
Project was bootstrapped using [kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) using the following commands:

```bash
kubebuilder init --domain playfab.com --repo github.com/playfab/thundernetes/operator
kubebuilder init --domain playfab.com --repo github.com/playfab/thundernetes/pkg/operator
kubebuilder create api --group mps --version v1alpha1 --kind GameServer
kubebuilder create api --group mps --version v1alpha1 --plural gameserverbuilds --kind GameServerBuild
kubebuilder create api --group mps --version v1alpha1 --plural gameserverdetails --kind GameServerDetail
Expand Down Expand Up @@ -261,7 +262,7 @@ To test your changes to thundernetes to a Kubernetes cluster, you can use the fo

- The Makefile on the root of the project contains a variable `NS` that points to the container registry that you use during development. So you'd need to either set the variable in your environment (`export NS=<your-container-registry>`) or set it before calling `make` (like `NS=<your-container-registry> make build push`).
- Login to your container registry (`docker login`)
- Run `make build push` to build the container images and push them to your container registry
- Run `make clean build push` to build the container images and push them to your container registry
khaines marked this conversation as resolved.
Show resolved Hide resolved
- Run `create-install-files-dev` to create the install files for the cluster
- Checkout the `installfilesdev` folder for the generated install files. This file is included in .gitignore so it will never be committed.
- Test your changes as required.
Expand Down
15 changes: 0 additions & 15 deletions e2e/cmd/go.mod

This file was deleted.

Loading