"New Epics". A jẹ erin ni awọn apakan

"New Epics". A jẹ erin ni awọn apakan

Ninu nkan yii, Emi yoo ṣeto agbegbe iṣẹ kan fun idagbasoke ere “Epics”, ati pe yoo tun fọ ere naa funrararẹ si awọn ẹya ti o dara fun lilo ni OpenFaaS. Emi yoo ṣe gbogbo awọn ifọwọyi lori Linux, Emi yoo mu Kubernetes ṣiṣẹ ni minikube nipa lilo VirtualBox. Ẹrọ iṣẹ mi ni awọn ohun kohun ero isise 2 ati 12GB ti Ramu; Mo lo SSD bi disk eto. Emi yoo lo debian 8 gẹgẹbi eto idagbasoke akọkọ mi, pẹlu emacs, sudo, git ati awọn idii apoti foju ti a fi sori ẹrọ, gbogbo ohun miiran yoo fi sii nipasẹ gbigba lati ayelujara lati GitHub ati awọn orisun miiran. A yoo fi sori ẹrọ awọn ohun elo wọnyi ni / usr/agbegbe/bin ayafi bibẹẹkọ pato. Jẹ ki a bẹrẹ!

Ngbaradi agbegbe iṣẹ

Fifi sori Go

A tẹle awọn itọnisọna lati oju opo wẹẹbu osise:

$ curl -L0 https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz -o go.tar.gz
$ sudo tar -C /usr/local -xzf go.tar.gz
$ echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile

Ṣiṣayẹwo iṣẹ ṣiṣe:

$ mkdir -p ~/go/src/hello && cd ~/go/src/hello
$ echo 'package main

import "fmt"

func main() {
fmt.Printf("hello, worldn")
}' > hello.go
$ go build
$ ./hello
hello, world

Fifi faas-cli

A tẹle awọn itọnisọna lati oju opo wẹẹbu osise:

$ curl -sSL https://cli.openfaas.com | sudo -E sh
x86_64
Downloading package https://github.com/openfaas/faas-cli/releases/download/0.11.3/faas-cli as /tmp/faas-cli
Download complete.

Running with sufficient permissions to attempt to move faas-cli to /usr/local/bin
New version of faas-cli installed to /usr/local/bin
Creating alias 'faas' for 'faas-cli'.
  ___                   _____           ____
 / _  _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_  / _  '_ | |_ / _` |/ _` ___ 
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 ___/| .__/ ___|_| |_|_|  __,_|__,_|____/
      |_|

CLI:
 commit:  73004c23e5a4d3fdb7352f953247473477477a64
 version: 0.11.3

Ni afikun, o le mu bash-ipari ṣiṣẹ:

faas-cli completion --shell bash | sudo tee /etc/bash_completion.d/faas-cli

Fifi sori ẹrọ ati tunto Kubernetes

Fun idagbasoke, minikube ti to, nitorinaa fi sii ati kubelet ni / usr / agbegbe / bin, ati fi sori ẹrọ Helm lati fi awọn ohun elo sori ẹrọ:

$ curl https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -o minikube && chmod +x minikube && sudo mv minikube /usr/local/bin/
$ curl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
$ curl https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz | tar -xzvf - linux-amd64/helm --strip-components=1; sudo mv helm /usr/local/bin

Lọlẹ minikube:

$ minikube start
  minikube v1.6.2 on Debian 8.11
  Automatically selected the 'virtualbox' driver (alternates: [])
  Downloading VM boot image ...
    > minikube-v1.6.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
    > minikube-v1.6.0.iso: 150.93 MiB / 150.93 MiB [-] 100.00% 5.67 MiB p/s 27s
  Creating virtualbox VM (CPUs=2, Memory=8192MB, Disk=20000MB) ...
  Preparing Kubernetes v1.17.0 on Docker '19.03.5' ...
  Downloading kubeadm v1.17.0
  Downloading kubelet v1.17.0
  Pulling images ...
  Launching Kubernetes ...  Waiting for cluster to come online ...
  Done! kubectl is now configured to use "minikube"

A ṣayẹwo:

$ kubectl get pods --all-namespaces
NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE
kube-system   coredns-6955765f44-knlcb           1/1     Running   0          29m
kube-system   coredns-6955765f44-t9cpn           1/1     Running   0          29m
kube-system   etcd-minikube                      1/1     Running   0          28m
kube-system   kube-addon-manager-minikube        1/1     Running   0          28m
kube-system   kube-apiserver-minikube            1/1     Running   0          28m
kube-system   kube-controller-manager-minikube   1/1     Running   0          28m
kube-system   kube-proxy-hv2wc                   1/1     Running   0          29m
kube-system   kube-scheduler-minikube            1/1     Running   0          28m
kube-system   storage-provisioner                1/1     Running   1          29m

Fifi OpenFaaS sori ẹrọ

Awọn olupilẹṣẹ ṣeduro ṣiṣẹda awọn aye orukọ 2 lati ṣiṣẹ pẹlu:

$ kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
namespace/openfaas created
namespace/openfaas-fn created

Ṣafikun ibi ipamọ kan fun helm:

$ helm repo add openfaas https://openfaas.github.io/faas-netes/
"openfaas" has been added to your repositories

Aworan naa ni agbara lati ṣeto ọrọ igbaniwọle ṣaaju fifi sori ẹrọ, jẹ ki a lo ki o fi data iwọle pamọ bi aṣiri k8s:

$ PASSWORD=verysecurerandompasswordstring
$ kubectl -n openfaas create secret generic basic-auth --from-literal=basic-auth-user=admin --from-literal=basic-auth-password="$PASSWORD"
secret/basic-auth created

Jẹ ki a ran:

$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "openfaas" chart repository
Update Complete.  Happy Helming!
$ helm upgrade openfaas --install openfaas/openfaas --namespace openfaas --set functionNamespace=openfaas-fn --set generateBasicAuth=false
Release "openfaas" does not exist. Installing it now.
NAME: openfaas
LAST DEPLOYED: Fri Dec 25 10:28:22 2019
NAMESPACE: openfaas
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
To verify that openfaas has started, run:

  kubectl -n openfaas get deployments -l "release=openfaas, app=openfaas"

Lẹhin akoko diẹ, a ṣiṣẹ aṣẹ ti a daba:

$ kubectl -n openfaas get deployments -l "release=openfaas, app=openfaas"
NAME                READY   UP-TO-DATE   AVAILABLE   AGE
alertmanager        1/1     1            1           114s
basic-auth-plugin   1/1     1            1           114s
faas-idler          1/1     1            1           114s
gateway             1/1     1            1           114s
nats                1/1     1            1           114s
prometheus          1/1     1            1           114s
queue-worker        1/1     1            1           114s

Ṣiṣayẹwo iṣẹ ṣiṣe:

$ kubectl rollout status -n openfaas deploy/gateway
deployment "gateway" successfully rolled out
$ kubectl port-forward -n openfaas svc/gateway 8080:8080 &
[1] 6985
Forwarding from 127.0.0.1:8080 -> 8080
$ echo -n $PASSWORD | faas-cli login --username admin --password-stdin
Calling the OpenFaaS server to validate the credentials...
Handling connection for 8080
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
credentials saved for admin http://127.0.0.1:8080
$ faas-cli list
Function                        Invocations     Replicas

Fifi Mongodb sori ẹrọ

A fi sori ẹrọ ohun gbogbo nipa lilo Helm:

$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
$ helm install stable/mongodb --generate-name
NAME: mongodb-1577466908
LAST DEPLOYED: Fri Dec 25 11:15:11 2019
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **

MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:

    mongodb-1577466908.default.svc.cluster.local

To get the root password run:

    export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default mongodb-1577466908 -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)

To connect to your database run the following command:

    kubectl run --namespace default mongodb-1577466908-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host mongodb-1577466908 --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/mongodb-1577466908 27017:27017 &
    mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD

A ṣayẹwo:

kubectl run --namespace default mongodb-1577466908-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host mongodb-1577466908 --authenticationDatabase admin -u root -p $(kubectl get secret --namespace default mongodb-1577466908 -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
If you don't see a command prompt, try pressing enter.

> db.version();
4.0.14

Tẹ ctrl+D lati jade kuro ninu apoti naa.

Ṣiṣeto awọn emacs

Ni opo, ohun gbogbo ti wa ni tunto tẹlẹ gẹgẹbi Arokọ yi, nitorina Emi kii yoo lọ sinu alaye.

Kikan awọn ere sinu awọn iṣẹ

Ibaraṣepọ pẹlu awọn iṣẹ ni a ṣe nipasẹ ilana http, ijẹrisi ipari-si-opin laarin awọn iṣẹ oriṣiriṣi ti pese nipasẹ JWT. Mongodb ti wa ni lo lati fi àmi, bi daradara bi game ipinle, player data, lesese ti gbogbo awọn ere ati awọn miiran alaye. Jẹ ká ya a jo wo ni awọn julọ awon awọn ẹya ara ẹrọ.

registration

Iṣagbewọle ti iṣẹ yii jẹ JSON pẹlu orukọ apeso ere ati ọrọ igbaniwọle. Nigbati a ba pe iṣẹ yii, a ṣayẹwo pe inagijẹ yii ko si ni ibi ipamọ data; ti ayẹwo naa ba ṣaṣeyọri, alias ati hash ọrọ igbaniwọle ni a fi sii sinu aaye data. Iforukọsilẹ ni a nilo lati kopa ninu ere.

ẹnu

Iṣagbewọle iṣẹ jẹ JSON pẹlu oruko apeso ere kan ati ọrọ igbaniwọle; ti orukọ apeso kan ba wa ninu ibi ipamọ data ati ọrọ igbaniwọle ti wa ni aṣeyọri pẹlu eyiti o ti fipamọ tẹlẹ ninu ibi ipamọ data, JWT kan yoo da pada, eyiti o gbọdọ kọja si awọn iṣẹ miiran nigbati wọn ba wa. ti a npe ni. Awọn igbasilẹ iṣẹ lọpọlọpọ tun fi sii sinu ibi ipamọ data, fun apẹẹrẹ, akoko iwọle to kẹhin, ati bẹbẹ lọ.

Wo akojọ awọn ere

Olumulo ti ko gba aṣẹ le beere atokọ ti gbogbo awọn ere ayafi awọn ti nṣiṣe lọwọ. Olumulo ti a fun ni aṣẹ tun rii atokọ ti awọn ere ti nṣiṣe lọwọ. Abajade iṣẹ naa jẹ JSON ti o ni awọn atokọ ti awọn ere (ID ere, orukọ ti eniyan le ka, ati bẹbẹ lọ).

Ere ẹda

Iṣẹ naa n ṣiṣẹ pẹlu awọn olumulo ti a fun ni aṣẹ nikan; nọmba ti o pọju ti awọn oṣere gba ni titẹ sii, ati awọn ayeraye ere (fun apẹẹrẹ, awọn ohun kikọ lati mu ṣiṣẹ ninu ere yii, nọmba ti o pọju awọn oṣere, ati bẹbẹ lọ). Paramita lọtọ ti ere naa jẹ wiwa ọrọ igbaniwọle kan fun didapọ, eyiti o fun ọ laaye lati ṣẹda awọn ere ti kii ṣe gbangba. Nipa aiyipada, a ṣẹda ere ti gbogbo eniyan. Abajade iṣẹ naa jẹ JSON, eyiti o ni aaye aṣeyọri ẹda, idamo ere alailẹgbẹ, ati awọn aye miiran.

Dida a game

Iṣẹ naa ṣiṣẹ nikan pẹlu awọn olumulo ti a fun ni aṣẹ, titẹ sii jẹ ID ere ati ọrọ igbaniwọle rẹ, ti eyi jẹ ere ti kii ṣe gbangba, abajade jẹ JSON pẹlu awọn aye ere. Olumulo ti a fun ni aṣẹ ti o darapọ mọ ere naa, ati ẹlẹda ere naa, ni a pe ni alabaṣe ere.

Wiwo awọn iṣẹlẹ ere

Olumulo laigba aṣẹ le beere atokọ ti awọn iṣẹlẹ fun awọn ere aiṣiṣẹ, ati pe olumulo ti a fun ni aṣẹ le gba atokọ ti awọn iṣẹlẹ fun eyikeyi ere ti nṣiṣe lọwọ. Afikun paramita si iṣẹ le jẹ nọmba iṣẹlẹ ti olumulo ti ni tẹlẹ. Ni ọran yii, awọn iṣẹlẹ nikan ti o waye nigbamii ni yoo da pada ninu atokọ naa. Nipa ifilọlẹ iṣẹ yii loorekoore, olumulo ti a fun ni aṣẹ wo ohun ti n ṣẹlẹ ninu ere naa. Iṣẹ yii tun da ibeere iṣe pada, eyiti olumulo le dahun si lilo iṣẹ fifiranṣẹ iṣẹlẹ ti ere.

Fifiranṣẹ iṣẹlẹ ere

Iṣẹ naa ṣiṣẹ nikan fun awọn olukopa ere: o ṣee ṣe lati bẹrẹ ere, ṣe gbigbe, dibo, kọ ifọrọranṣẹ ti o han ninu atokọ ti awọn iṣẹlẹ ere, bbl
Olumulo ti a fun ni aṣẹ ti o ṣẹda ere naa bẹrẹ pinpin awọn ipa si gbogbo awọn olukopa ninu ere, pẹlu ara wọn, wọn gbọdọ jẹrisi ipa wọn nipa lilo iṣẹ kanna. Ni kete ti gbogbo awọn ipa ti jẹrisi, ere naa yipada laifọwọyi si ipo alẹ.

game statistiki

Iṣẹ naa ṣiṣẹ fun awọn olukopa ere nikan; o fihan ipo ere naa, atokọ ati nọmba awọn oṣere (awọn orukọ apeso), awọn ipa ati ipo wọn (gbe tabi rara), ati alaye miiran. Gẹgẹbi iṣẹ iṣaaju, ohun gbogbo ṣiṣẹ nikan fun awọn olukopa ere.

Awọn iṣẹ ifilọlẹ ni igbakọọkan

Ti ere naa ko ba ti ṣe ifilọlẹ fun igba diẹ nigbati o ṣẹda ere naa, yoo yọkuro laifọwọyi lati atokọ ti awọn ere ti nṣiṣe lọwọ nipa lilo iṣẹ mimọ.

Iṣẹ-ṣiṣe igbakọọkan miiran ni fi agbara mu ipo ere lati alẹ si ọjọ ati sẹhin fun awọn ere eyiti eyi ko ṣẹlẹ lakoko titan (fun apẹẹrẹ, ẹrọ orin ti o nilo lati fesi si iṣẹlẹ ere kan ko firanṣẹ ojutu rẹ fun idi kan. ).

Ikede

  • Ifihan
  • Ṣiṣeto ayika idagbasoke, fifọ iṣẹ-ṣiṣe si awọn iṣẹ
  • Iṣẹ ẹhin
  • Iṣẹ iwaju
  • Ṣiṣeto CICD, siseto idanwo
  • Bẹrẹ igba ere idanwo kan
  • Awọn esi

orisun: www.habr.com

Fi ọrọìwòye kun