Skip to content

Commit

Permalink
Ramp up (#85)
Browse files Browse the repository at this point in the history
* Fix tests

* Fix request body validation

* Fix Dockerfile entry point command

* Replace Prototool with Buf

* Update Go version on CI

* Update Go version on CI

* Run mod tidy

* Remove cluster test + Fix standalone test

* Remove test in code

* Remove CI step

* Remove CI step dependency

* Update release pipeline

* Update deprecated github actions used

* Remove deprecated commands

* Fix typo in go.yaml

* Fix GITHUB_OUTPUT usage

* More actions version updates

* Change podium-dev image creation trigger

* Remove file that should not have been included
  • Loading branch information
miguelreiswildlife committed Jul 24, 2023
1 parent 9eca4e9 commit a422b44
Show file tree
Hide file tree
Showing 32 changed files with 6,997 additions and 4,617 deletions.
162 changes: 79 additions & 83 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ jobs:
slave3-port: 5005
- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/checkout@v2
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v3
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.15
go-version: '1.20'
- name: Setup env
run: make setup
- name: Test
Expand All @@ -55,143 +55,139 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile _build/test-coverage-all.out -service=github

test-cluster:
runs-on: ubuntu-latest
services:
redis:
image: redis:4
options: '--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5'
ports:
- '6379:6379'
steps:
- name: Instantiate redis cluster
uses: vishnudxb/redis-cluster@1.0.5
with:
master1-port: 5000
master2-port: 5001
master3-port: 5002
slave1-port: 5003
slave2-port: 5004
slave3-port: 5005
- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/checkout@v2
- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Setup env
run: make setup
- name: Test
run: make test
env:
PODIUM_REDIS_CLUSTER_ENABLED: true
- name: Coverage
run: make coverage
env:
PODIUM_REDIS_CLUSTER_ENABLED: true
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile _build/test-coverage-all.out -service=github
# test-cluster:
# runs-on: ubuntu-latest
# services:
# redis:
# image: redis:4
# options: '--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5'
# ports:
# - '6379:6379'
# steps:
# - name: Instantiate redis cluster
# uses: vishnudxb/redis-cluster@1.0.5
# with:
# master1-port: 5000
# master2-port: 5001
# master3-port: 5002
# slave1-port: 5003
# slave2-port: 5004
# slave3-port: 5005
# - id: go-cache-paths
# run: |
# echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
# echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
# - uses: actions/checkout@v3
# - name: Go Build Cache
# uses: actions/cache@v3
# with:
# path: ${{ steps.go-cache-paths.outputs.go-build }}
# key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
# # Cache go mod cache, used to speedup builds
# - name: Go Mod Cache
# uses: actions/cache@v3
# with:
# path: ${{ steps.go-cache-paths.outputs.go-mod }}
# key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: '1.20'
# - name: Setup env
# run: make setup
# - name: Test
# run: make test
# env:
# PODIUM_REDIS_CLUSTER_ENABLED: true
# - name: Coverage
# run: make coverage
# env:
# PODIUM_REDIS_CLUSTER_ENABLED: true
# - name: Install goveralls
# env:
# GO111MODULE: on
# run: go get github.com/mattn/goveralls
# - name: Send coverage
# env:
# COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: goveralls -coverprofile _build/test-coverage-all.out -service=github

# Triggered on tag creations, except dev/x.x.x, leaderboard/x.x.x and client/x.x.x
build_and_deploy_podium:
needs:
- test-standalone
- test-cluster
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'leaderboard/') && !contains(github.ref, 'client/')
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'dev/') && !contains(github.ref, 'leaderboard/') && !contains(github.ref, 'client/')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set env
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
- name: Build and push tag
id: docker_build_tag
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./build/Dockerfile
push: true
tags: tfgco/podium:${{ env.VERSION }}
- name: Build and push latest
id: docker_build_latest
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./build/Dockerfile
push: true
tags: tfgco/podium:latest

# To push a podium-dev image, create a dev/x.x.x tag
build_and_deploy_podium_dev:
needs:
- test-standalone
- test-cluster
runs-on: ubuntu-latest
if: (!startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'leaderboard/') && !contains(github.ref, 'client/'))
if: (startsWith(github.ref, 'refs/tags/') && contains(github.ref, 'dev/') && !contains(github.ref, 'leaderboard/') && !contains(github.ref, 'client/'))
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set env
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15.2
- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
- name: Build and push tag
id: docker_build_tag
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./build/Dockerfile
push: true
tags: tfgco/podium-dev:${{ env.VERSION }}
- name: Build and push latest
id: docker_build_latest
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./build/Dockerfile
Expand Down
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ MYIP = $(shell ifconfig | egrep inet | egrep -v inet6 | egrep -v 127.0.0.1 | awk
OS = "$(shell uname | awk '{ print tolower($$0) }')"
PROTOTOOL := go run github.com/uber/prototool/cmd/prototool
LOCAL_GO_MODCACHE = $(shell go env | grep GOMODCACHE | cut -d "=" -f 2 | sed 's/"//g')
GINKGO := go run github.com/onsi/ginkgo/ginkgo@v1.16.5
BUF := go run github.com/bufbuild/buf/cmd/buf@v1.24.0

help: Makefile ## Show list of commands
@echo "Choose a command run in "$(PROJECT_NAME)":"
Expand All @@ -27,7 +29,7 @@ clear-hooks: ## Remove pre-commit git hooks
@cd .git/hooks && rm pre-commit

setup: setup-hooks ## Install local dependencies and tidy go mods
@go get -u github.com/onsi/ginkgo/ginkgo
@go get github.com/onsi/ginkgo/ginkgo
@go get github.com/gordonklaus/ineffassign
@go get github.com/uber/prototool/cmd/prototool
@go mod download
Expand All @@ -44,13 +46,13 @@ run: ## Execute the project
test: test-podium test-leaderboard test-client ## Execute all tests

test-podium: ## Execute all API tests
@ginkgo --cover -r -nodes=1 -skipPackage=leaderboard,client ./
$(GINKGO) --cover -r -nodes=1 --skipPackage=leaderboard,client ./

test-leaderboard: ## Execute all leaderboard tests
@cd leaderboard && ginkgo --cover -r -nodes=1 ./
@cd leaderboard && $(GINKGO) --cover -r -nodes=1 ./

test-client: ## Execute all client tests
@cd client && ginkgo --cover -r -nodes=1 ./
@cd client && $(GINKGO) --cover -r -nodes=1 ./

coverage: ## Generate code coverage file
@rm -rf _build
Expand All @@ -65,7 +67,7 @@ docker-build: ## Build docker-compose services
@docker build -f ./build/Dockerfile -t podium .

docker-run: ## Run podium inside Docker
@docker run -i -t --rm -e PODIUM_REDIS_HOST=$(MYIP) -e PODIUM_REDIS_PORT=6379 -p 8080:80 podium
@docker run -i -t --rm -e PODIUM_REDIS_HOST=$(MYIP) -e PODIUM_REDIS_PORT=6379 -p 8880:8880 podium

docker-run-redis: ## Run a redis instance in Docker
@docker run --name=redis -d -p 6379:6379 redis:6.0.9-alpine
Expand Down Expand Up @@ -106,6 +108,16 @@ rtfd: ## Build and open podium documentation
mock-lib: ## Generate mocks
@mockgen github.com/topfreegames/podium/lib PodiumInterface | sed 's/mock_lib/mocks/' > lib/mocks/podium.go

proto-setup:
@go install google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
@$(BUF) mod update



proto: ## Generate protobuf files
@rm proto/podium/api/v1/*.go > /dev/null 2>&1 || true
@${PROTOTOOL} generate
@$(BUF) generate

Loading

0 comments on commit a422b44

Please sign in to comment.