Skip to content

Add redis #5

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ serde_json = "1.0"

actix = "0.7"
actix-web = "0.7"

redis = "0.10.0"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ cargo run
## Run With Docker
```
docker-compose up
```

## notes
```
kompose convert
kubectl apply -f actix-service.yaml actix-doployment.yaml
kubectl apply -f redis-service.yaml redis-doployment.yaml redis-data-persistentvolumeclaim.yaml
kubectl expose deployment/actix --type="NodePort" --port 3001 --name=mp
```
32 changes: 32 additions & 0 deletions actix-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 ()
creationTimestamp: null
labels:
io.kompose.service: actix
name: actix
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: actix
spec:
containers:
- env:
- name: RUST_ENV
value: docker
- name: RUST_LOG
value: debug
image: generalset/multiplayer_server:init
name: actix
ports:
- containerPort: 3001
resources: {}
restartPolicy: Always
status: {}
19 changes: 19 additions & 0 deletions actix-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 ()
creationTimestamp: null
labels:
io.kompose.service: actix
name: actix
spec:
ports:
- name: "3001"
port: 3001
targetPort: 3001
selector:
io.kompose.service: actix
status:
loadBalancer: {}
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
version: '3'
services:
actix:
image: generalset/multiplayer_server:init
environment:
- RUST_ENV=docker
- RUST_LOG=debug
build: .
ports:
- '3001:3001'
- '3001:3001'
depends_on:
- redis
redis:
image: redis
ports:
- '6379:6379'
volumes:
- redis-data:/data
volumes:
redis-data:
14 changes: 14 additions & 0 deletions redis-data-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis-data
name: redis-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
35 changes: 35 additions & 0 deletions redis-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 ()
creationTimestamp: null
labels:
io.kompose.service: redis
name: redis
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis
spec:
containers:
- image: redis
name: redis
ports:
- containerPort: 6379
resources: {}
volumeMounts:
- mountPath: /data
name: redis-data
restartPolicy: Always
volumes:
- name: redis-data
persistentVolumeClaim:
claimName: redis-data
status: {}
19 changes: 19 additions & 0 deletions redis-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 ()
creationTimestamp: null
labels:
io.kompose.service: redis
name: redis
spec:
ports:
- name: "6379"
port: 6379
targetPort: 6379
selector:
io.kompose.service: redis
status:
loadBalancer: {}
23 changes: 6 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ extern crate actix;
extern crate actix_web;
extern crate serde;
extern crate serde_json;
extern crate redis;
extern crate set;
extern crate rand;

use std::env;
use rand::prelude::*;
use serde_json::{Result as JSON_Result};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -177,30 +177,19 @@ fn main() {

let sys = actix::System::new("multiplayer-server");

// Start server actor in separate thread
let server = Arbiter::start(|_| server::Server::default());

// Create Http server with websocket support
let env = match env::var("RUST_ENV") {
Result::Ok(env) => env,
_ => "development".to_string(),
};
let address = match env.as_str() {
"docker" => "0.0.0.0:3001",
_ => "127.0.0.1:3001",
};
error!("{}", address);
HttpServer::new(move || {
// Start server actor in separate thread
let addr = Arbiter::start(|_| server::Server::default());

// Websocket sessions state
let state = WsSessionState {
addr: server.clone(),
};
let state = WsSessionState { addr };

App::with_state(state)
// websocket
.resource("/", |r| r.route().f(chat_route))

}).bind(address)
}).bind("0.0.0.0:3001")
.unwrap()
.start();

Expand Down
Loading