A preliminary project

Project Address:

  • Original project: github.com/lonng/nanos…
  • Tuned: github.com/Kirk-Wang/n…

This will be a complete, fully implemented Golang game server development tutorial series for DevOps/GitOps and cloud processes on Kubernetes.

This series of tutorials is a complete teardown of the open source Nanoserver project, designed to help you get started on the Golang server backend. Understand the essence of Golang development through practice — Share memory by communication.

The project may also involve work on Linux performance tuning (BPF related tools) and system assurance (SRE).

Guys, server-side programs run on Top of Linux. The reason why the performance is not good, may really be the operating system understanding too little (mutual incentive).

The service side

My adjusted project:

  • Github.com/Kirk-Wang/n…

The original project

  • Github.com/lonng/nanos…

My local environment:

go version
# go version go1.14.14 darwin/amd64
Copy the code

Run MySQL & Adminer using containers

docker-compose.mysql.yaml

version: '3.1'
services:
  db:
    image: mysql
    command: 
      - --default-authentication-plugin=mysql_native_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    restart: always
    networks:
      - db_network
    ports:
      - "3306:3306"
    volumes:
      - 'db_data:/bitnami/mysql/data'
    environment:
      MYSQL_DATABASE: scmj
      MYSQL_ROOT_PASSWORD: 123456
    healthcheck:
      test: ['CMD'.'/opt/bitnami/scripts/mysql/healthcheck.sh']
      interval: 15s
      timeout: 5s
      retries: 6
  adminer:
    image: adminer
    restart: always
    networks:
      - db_network
    ports:
      - 8080: 8080
volumes:
  db_data:
    driver: local
networks:
  db_network:
    driver: "bridge"
Copy the code

Start the

docker-compose -f docker-compose.mysql.yaml up
Docker-compose -f docker-comemage.mysql. Yaml up -d
# docker-comement-f docker-comemess.mysql.yaml down
# docker-compose -f docker-compose.mysql.yaml ps

Clean up data files
# docker volume ls
# docker volume rm nanoserver_db_data
Copy the code

Once started, the container will automatically help us create the database – SCMJ.

Start the server program

After starting MySql, I run the following command:

go run .
Copy the code

Normally you will see the following screenshots (automatically create tables and indexes) :

We can check it out at http://localhost:8080/ :

The client

In Kirk-Wang/ Nanoserver, an APK focused on debugging server logic has been put in place for less.

Installing android Emulator

Here I recommend NetEase’s MuMu simulator.

Install the APK

The mahjong. Apk has been put into the revised project of the author. Here we use multiple helpers, open 4 blanks for bloody battles.

Client Login

We click on wechat to log in.

Login failed……

How to solve it? Read on.

Resolve the client login failure

Of course, this problem, or to solve:

  1. Decompile as the author saysapkTo findappConfig.luac, using the binary editor to change the server address, and then repackage.

  1. Use the proxy directly, as inCharlesRequest address forwarding. (Local debugging of server programs is sufficient.)

Charles requests address forwarding from the client

Using Map Remote to Map to the address of your native debugger is sufficient.

Join guest test channel Konglai

Log in to the game again

Perfect. Done.

Testing & a bloodbath

Create a room

To join the room

Start the game

Viewing Server Logs

DevOps(Drone CI/CD) & DevOps

.drone.yml

kind: pipeline
type: kubernetes
name: NanoServer

steps:

  - name: update Chart.yaml appVersion
    image: busybox
    commands:
      - echo $DRONE_COMMIT
      - '[ -n "$DRONE_COMMIT" ] && ( sed -i "s/APP_VERSION/${DRONE_COMMIT}/g" k8s/nanoserver/nanoserver/Chart.yaml; ) '
      - cat k8s/nanoserver/nanoserver/Chart.yaml

  - name: build Docker Image
    image: plugins/docker
    settings:
      debug: true
      dockerfile: Dockerfile.prod
      repo: hub.your-domain.com/library/nanoserver
      tags: ${DRONE_COMMIT}
      registry: hub.your-domain.com
      username:
        from_secret: docker_user
      password:
        from_secret: docker_pass

  - name: The cloud (HelmV3) -> K8S Cluster
    image: pelotech/drone-helm3
    settings:
      helm_command: upgrade
      chart: ./k8s/nanoserver/nanoserver
      release: nanoserver
      vaules_yaml: ./k8s/nanoserver/values.yaml
      namespace: nano
      api_server:
        from_secret: api_server
      kubernetes_token:
        from_secret: k8s_token
      skip_tls_verify: true

trigger:
  branch:
    - master
Copy the code

GitOps & ArgoCD progressive deployment of declarative cloud native

Author: Weishao wechat: uuhells123 public account: Hackers afternoon tea add my wechat (mutual learning exchange), follow the public account (for more learning materials ~)Copy the code