Skip to content

Commit

Permalink
Add build and install support
Browse files Browse the repository at this point in the history
  • Loading branch information
danieloliveira079 committed May 24, 2020
1 parent 230d5d4 commit 49da58c
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

go:
- "1.14"

script:
- go test -v ./...
- make build
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.14 AS builder

WORKDIR /go/src/github.com/Octops/agones-broadcaster-http

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./bin/broadcaster-http .

FROM alpine

WORKDIR /app

COPY --from=builder /go/src/github.com/Octops/agones-broadcaster-http/bin/broadcaster-http /app/

RUN chmod +x broadcaster-http

ENTRYPOINT ["./broadcaster-http"]
94 changes: 94 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
.PHONY: all build clean fmt test lint vendor install

## overridable Makefile variables
# test to run
TESTSET = .
# benchmarks to run
BENCHSET ?= .

# version (defaults to short git hash)
VERSION ?= $(shell git rev-parse --short HEAD)

# use correct sed for platform
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED := gsed
else
SED := sed
endif

PKG_NAME=github.com/Octops/agones-event-broadcaster

LDFLAGS := -X "${PKG_NAME}/internal/version.Version=${VERSION}"
LDFLAGS += -X "${PKG_NAME}/internal/version.BuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "${PKG_NAME}/internal/version.GitCommit=$(shell git rev-parse HEAD)"
LDFLAGS += -X "${PKG_NAME}/internal/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"

GO := GO111MODULE=on GOPRIVATE=github.com/Octops GOSUMDB=off go
GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG)
GOTEST := $(GO) test -gcflags='-l' -p 3

CURRENT_DIR := $(shell pwd)
FILES := $(shell find internal cmd -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -not -name '*_test.go')
TESTS := $(shell find internal cmd -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -name '*_test.go')

BROADCASTER_BIN := bin/broadcaster-http

DOCKER_IMAGE_TAG ?= octops/agones-broadcaster-http:latest

default: clean build

build: clean $(BROADCASTER_BIN)

$(BROADCASTER_BIN):
CGO_ENABLED=0 GOOS=linux go build -ldflags '$(LDFLAGS)' -a -installsuffix cgo -o $(BROADCASTER_BIN) .

dist:
CGO_ENABLED=0 GOOS=linux go build -ldflags '$(LDFLAGS)' -a -installsuffix cgo -o $(BROADCASTER_BIN) .
CGO_ENABLED=0 GOOS=darwin go build -ldflags '$(LDFLAGS)' -a -installsuffix cgo -o $(BROADCASTER_BIN)-darwin .

clean:
rm -f $(BROADCASTER_BIN)*

get:
$(GO) get ./...
$(GO) mod verify
$(GO) mod tidy

update:
$(GO) get -u -v all
$(GO) mod verify
$(GO) mod tidy

fmt:
gofmt -s -l -w $(FILES) $(TESTS)

lint:
golangci-lint run

test:
$(GOTEST) -run=$(TESTSET) ./...
@echo
@echo Configured tests ran ok.

test-strict:
$(GO) test -p 3 -run=$(TESTSET) -gcflags='-l -m' -race ./...
@echo
@echo Configured tests ran ok.

bench:
DEBUG=0 $(GOTEST) -run=nothing -bench=$(BENCHSET) -benchmem ./...
@echo
@echo Configured benchmarks ran ok.

vendor:
$(GO) mod vendor

docker:
docker build -t $(DOCKER_IMAGE_TAG) .

push: docker
docker push $(DOCKER_IMAGE_TAG)

install:
kubectl apply -f install/install.yaml
71 changes: 71 additions & 0 deletions install/install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: agones-events-controller
labels:
app: agones-event-broadcaster
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: agones-events-controller
labels:
app: agones-event-broadcaster
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["list", "watch"]
- apiGroups: ["agones.dev"]
resources: ["gameservers",]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: agones-events-controller
labels:
app: agones-event-broadcaster
subjects:
- kind: User
name: system:serviceaccount:default:agones-events-controller
apiGroup: rbac.authorization.k8s.io
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: agones-events-controller
---
apiVersion: v1
kind: Service
metadata:
name: agones-broadcaster-http
spec:
selector:
app: agones-broadcaster-http
ports:
- protocol: TCP
port: 8000
targetPort: 8000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: agones-broadcaster-http
labels:
app: agones-broadcaster-http
spec:
selector:
matchLabels:
app: agones-broadcaster-http
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: agones-broadcaster-http
spec:
serviceAccountName: agones-events-controller
containers:
- name: agones-events-controller
image: octops/agones-broadcaster-http:latest
imagePullPolicy: Always

0 comments on commit 49da58c

Please sign in to comment.