mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-08-01 14:31:19 +00:00
Initial Docker rewrite (#190)
* Initial Docker rewrite * Add rebuild * Up * Up * Up * Pre-release * Pack assets with ext games * Remove Makefile Docker because it's broken on Windows and a dup * Add default container name * Update docker-compose.yml * Add app binaries into the system bin folder * Update * Update
This commit is contained in:
parent
bf5b622b1a
commit
9d3e9c1a3b
6 changed files with 83 additions and 30 deletions
16
.dockerignore
vendored
16
.dockerignore
vendored
|
|
@ -1,6 +1,16 @@
|
|||
*/assets/games/*
|
||||
.git
|
||||
.git/
|
||||
.gitignore
|
||||
.github/
|
||||
.idea/
|
||||
|
||||
.env
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
|
||||
LICENSE
|
||||
VERSION
|
||||
docs
|
||||
README.md
|
||||
bin/
|
||||
docs/
|
||||
|
||||
assets/games/
|
||||
|
|
|
|||
1
.env
vendored
Normal file
1
.env
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
CLOUD_GAME_GAMES_PATH=./assets/games
|
||||
48
Dockerfile
vendored
48
Dockerfile
vendored
|
|
@ -1,15 +1,43 @@
|
|||
From golang:1.12
|
||||
# The base cloud-game image
|
||||
ARG BUILD_PATH=/go/src/github.com/giongto35/cloud-game
|
||||
|
||||
RUN apt-get update
|
||||
# build image
|
||||
FROM golang:1.14 AS build
|
||||
ARG BUILD_PATH
|
||||
WORKDIR ${BUILD_PATH}
|
||||
|
||||
RUN apt-get install pkg-config libvpx-dev libopus-dev libopusfile-dev -y
|
||||
# system libs layer
|
||||
RUN apt-get update && apt-get install -y \
|
||||
make \
|
||||
pkg-config \
|
||||
libvpx-dev \
|
||||
libopus-dev \
|
||||
libopusfile-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir -p /cloud-game
|
||||
COPY . /cloud-game/
|
||||
WORKDIR /cloud-game
|
||||
# go deps layer
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Install server dependencies
|
||||
RUN go install ./cmd/coordinator
|
||||
RUN go install ./cmd/worker
|
||||
# app build layer
|
||||
COPY ./ ./
|
||||
RUN make build
|
||||
|
||||
EXPOSE 8000
|
||||
# base image
|
||||
FROM debian:10-slim
|
||||
ARG BUILD_PATH
|
||||
WORKDIR /usr/local/share/cloud-game
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libvpx5 \
|
||||
libopus0 \
|
||||
libopusfile0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=build ${BUILD_PATH}/bin/ ./
|
||||
# it assumed there are only binary files yet
|
||||
RUN cp -s $(pwd)/* /usr/local/bin
|
||||
COPY web ./web
|
||||
COPY assets/emulator/libretro/cores/*.so ./assets/emulator/libretro/cores/
|
||||
|
||||
EXPOSE 8000 9000 3478/tcp 3478/udp
|
||||
|
|
|
|||
18
Makefile
vendored
18
Makefile
vendored
|
|
@ -76,27 +76,19 @@ dev.run: dev.build-local
|
|||
./bin/coordinator --v=5 &
|
||||
./bin/worker --coordinatorhost localhost:8000
|
||||
|
||||
dev.run-docker:
|
||||
docker build . -t cloud-game-local
|
||||
docker stop cloud-game-local || true
|
||||
docker rm cloud-game-local || true
|
||||
# Coordinator and worker should be run separately.
|
||||
docker run --privileged -v $(pwd)/games:/cloud-game/games -d --name cloud-game-local -p 8000:8000 -p 9000:9000 cloud-game-local bash -c "coordinator --v=5 & worker --coordinatorhost localhost:8000"
|
||||
|
||||
# RELEASE
|
||||
# Builds the app for new release.
|
||||
#
|
||||
# Folder structure:
|
||||
# release
|
||||
# - assets/
|
||||
# - games/ (shared between both executables)
|
||||
# - emulator/libretro/cores/ (filtered by extension)
|
||||
# - games/ (shared between both executables)
|
||||
# - emulator/libretro/cores/ (filtered by extension)
|
||||
# - web/
|
||||
# - coordinator
|
||||
# - worker
|
||||
#
|
||||
# params:
|
||||
# - RELEASE_DIR: the name of the output folder (default: _release).
|
||||
# Config params:
|
||||
# - RELEASE_DIR: the name of the output folder (default: release).
|
||||
# - DLIB_TOOL: the name of a dynamic lib copy tool (with params) (e.g., ldd -x -y; defalut: ldd).
|
||||
# - DLIB_SEARCH_PATTERN: a grep filter of the output of the DLIB_TOOL (e.g., mylib.so; default: .*so).
|
||||
# Be aware that this search pattern will return only matched regular expression part and not the whole line.
|
||||
|
|
@ -105,7 +97,7 @@ dev.run-docker:
|
|||
# - DLIB_ALTER: a special flag to use altered dynamic copy lib tool for macOS only.
|
||||
# - CORE_EXT: a file extension of the cores to copy into the release.
|
||||
#
|
||||
# example:
|
||||
# Example:
|
||||
# make release DLIB_TOOL="ldd -x" DLIB_SEARCH_PATTERN=/usr/lib.*\\\\s LIB_EXT=so
|
||||
#
|
||||
RELEASE_DIR ?= release
|
||||
|
|
|
|||
13
README.md
vendored
13
README.md
vendored
|
|
@ -32,10 +32,6 @@ Direct play an existing game: **[Pokemon Emerald](http://cloudretro.io/?id=652e4
|
|||
5. **Horizontally scaled**: The infrastructure is designed to be able to scale under high traffic by adding more instances.
|
||||
6. **Cloud storage**: Game state is storing on online storage, so you can come back and continue playing your incomplete game later.
|
||||
|
||||
## Run on local by Docker
|
||||
|
||||
You try running the server directly by `make dev.run-docker`. It will spawn a docker environment and you can access the service on `localhost:8000`.
|
||||
|
||||
## Development environment
|
||||
|
||||
Install Golang https://golang.org/doc/install . Because the project uses GoModule, so it requires Go1.11 version.
|
||||
|
|
@ -76,6 +72,15 @@ Because the coordinator and workers need to run simultaneously. Workers connect
|
|||
* `go run cmd/coordinator/main.go` - spawn coordinator
|
||||
* `go run cmd/worker/main.go --coordinatorhost localhost:8000` - spawn workers connecting to coordinator
|
||||
|
||||
## Run with Docker
|
||||
|
||||
In case if you want to run the app as a Docker container,
|
||||
use `docker-compose up --build` (`CLOUD_GAME_GAMES_PATH` is env variable for games on your host).
|
||||
It will spawn a docker environment and you can access the service on `localhost:8000`.
|
||||
|
||||
*Note.*
|
||||
Docker for Windows is not supposed to work with provided configuration, use WSL2 instead.
|
||||
|
||||
## Technical Document
|
||||
- [webrtchacks Blog: Open Source Cloud Gaming with WebRTC](https://webrtchacks.com/open-source-cloud-gaming-with-webrtc/)
|
||||
- [Wiki (outdated)](https://github.com/giongto35/cloud-game/wiki)
|
||||
|
|
|
|||
17
docker-compose.yml
vendored
Normal file
17
docker-compose.yml
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
version: '3'
|
||||
services:
|
||||
|
||||
cloud-game:
|
||||
build: .
|
||||
image: cloud-game-local
|
||||
container_name: cloud-game-local
|
||||
privileged: true
|
||||
command: >
|
||||
bash -c "coordinator --v=5 & worker --coordinatorhost localhost:8000"
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- "9000:9000"
|
||||
- "3478:3478/tcp"
|
||||
- "3478:3478/udp"
|
||||
volumes:
|
||||
- ${CLOUD_GAME_GAMES_PATH}:/usr/local/share/cloud-game/assets/games
|
||||
Loading…
Add table
Add a link
Reference in a new issue