Skip to content

Commit

Permalink
Cleanup and added makefile. Bumped version. Closes #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rajch committed May 8, 2021
1 parent 71b0866 commit 75b8956
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 21 deletions.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Bump these on release, and for now manually update the deployment files:
# docker-compose.yml, stack.yml and package.json
VERSION_MAJOR ?= 0
VERSION_MINOR ?= 4
BUILD_NUMBER ?= 0
PATCH_STRING ?=

VERSION_STRING = $(VERSION_MAJOR).$(VERSION_MINOR).$(BUILD_NUMBER)$(PATCH_STRING)

IMAGE_TAG ?= $(VERSION_MAJOR).$(VERSION_MINOR).$(BUILD_NUMBER)
REGISTRY_USER ?= rajchaudhuri

.PHONY: all
all: client server

.PHONY: public
public:
cp -r public/* out/

out/js/client.js: client/*.js
npm run build-client-release

.PHONY: client
client: public out/js/client.js

.PHONY: client-debug
client-debug: public client/*.js
npm run build-client-debug

out/voxel-dockerserver: server/*.go
CGO_ENABLED='0' go build -o out/voxel-dockerserver -ldflags "-X 'main.version=$(VERSION_STRING)'" server/*.go

.PHONY: server
server: out/voxel-dockerserver

.PHONY: debug
debug: public client-debug server

.PHONY: build-docker
build-docker:
docker image build -t $(REGISTRY_USER)/voxel-dockerclient:$(VERSION_STRING) -f Dockerfile .

.PHONY: run-docker
run-docker: build-docker
docker container run --rm --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock --publish 8080:8080 $(REGISTRY_USER)/voxel-dockerclient:$(VERSION_STRING)

.PHONY: clean-docker
clean-docker:
docker image rm $(REGISTRY_USER)/voxel-dockerclient:$(VERSION_STRING)

.PHONY: clean
clean:
rm -rf out/*
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ The dockercraft project turns the official Minecraft client into a docker client
## What is it not?
voxel-dockerclient is not a serious tool for working with docker. It's a fun project (which may grow up to be a teaching aid someday).

> WARNING: Please use voxel-dockerclient on your local machine only.
> It currently doesn't support any authentication.
> WARNING: Please use voxel-dockerclient with care.
> It requires access to the docker socket.
## How to run voxel-dockerclient
### Try it on Play With Docker
The easiest way:

[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/rajch/voxel-dockerclient/master/stack.yml)

### Using the docker image
The easiest way is to pull the docker image, and run from that. The steps are as follows:
The next easiest way is to pull the docker image, and run from that. The steps are as follows:

1. Pull the docker image with

Expand All @@ -23,30 +28,28 @@ The easiest way is to pull the docker image, and run from that. The steps are as
2. Run it with:

```
docker run -d -p 5000:80 -v /var/run/docker.sock:/var/run/docker.sock rajchaudhuri/voxel-dockerclient
docker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock rajchaudhuri/voxel-dockerclient
```

> The `-v /var/run/docker.sock:/var/run/docker.sock` is *very important*.
> This makes the UNIX socket, which the docker daemon listens to by default, available to the container.
> The container needs this to proxy a subset of the Docker remote API to voxel-dockerclient.
> If you leave this out by mistake, voxel-dockerclient will not work.
3. Point your browser to the container. If you run docker directly on your Linux machine, browse to: `http://localhost:5000`.
3. Point your browser to the container. If you run docker directly on your Linux machine, browse to: `http://localhost:8080`.
If you use docker-machine (for example, with the Docker Toolbox on Windows), find the IP address of your docker machine with

```
docker-machine ip default
```
and then browse to that IP address using the port that you mapped in step 2. E.g.: `http://192.17.22.1:5000`
and then browse to that IP address using the port that you mapped in step 2. E.g.: `http://192.17.22.1:8080`

### Building with node.js and golang
Alternatively, if you have node.js and golang installed on your docker host, you can clone the github repository, and build and run voxel-dockerclient yourself. The steps are:
Alternatively, if you have node.js (>=v12.19.0) and golang (>=go1.16.4) installed on your docker host, you can clone the github repository, and build and run voxel-dockerclient yourself. The steps are:

1. Clone the github repository into your Go workspace with:

```
mkdir -p "$GOPATH/src/github.com/rajch"
cd "$GOPATH/src/github.com/rajch"
git clone https://github.com/rajch/voxel-dockerclient.git
```
2. Change to the cloned directory and run
Expand All @@ -57,9 +60,14 @@ Alternatively, if you have node.js and golang installed on your docker host, you
3. Run

```
npm run build-all
npm run build
npm run run-docker
```
or, if you are on Linux, or OSX, or WSL:
```
make
make run-docker
```
4. Browse to `http://localhost:8080`

Your logged-in user needs to be a member of the `docker` group for this to work.
Expand All @@ -79,25 +87,31 @@ docker build -t voxel-dockerclient:local .
```
3. Run
```
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 8081:80 voxel-dockerclient:local
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 voxel-dockerclient:local
```
4. Browse to `http://localhost:8080`

Or, you could use the provided docker compose manifest file, by running:

```
docker-compose up -d
```
4. Browse to `http://localhost:8081`

Your logged-in user needs to be a member of the `docker` group for this to work.

## How to use voxel-dockerclient
Instructions are available [here](https://rajch.github.io/voxel-dockerclient/).

## Browser compatibility
voxel-dockerclient has been tested using recent Chrome and Firefox browsers, on Linux and Windows. Regrettably (*I mean it. I actually like that old browser*), it does not work with Internet Explorer.
voxel-dockerclient has been tested using recent Chrome and Firefox browsers, on Linux and Windows.

## What's next?
I intend to add the following capabilities quickly:
* ~~`docker logs` equivalent~~ ** DONE
* ~~`docker attach` equivalent~~ ** DONE
* `docker pull` equivalent
* A better interface for the `create` command
* *Some* security
* ~~*Some* security~~ ** DONE

In the pipeline, further down, are:
* volumes
Expand All @@ -109,7 +123,7 @@ I don't really know how far I want to take this. I do want voxel-dockerclient to
## How does it work?
~~On the server, voxel-dockerclient uses [Express](http://expressjs.com/) and the excellent [dockerode](https://github.com/apocas/dockerode) node module to provide a proxy for a subset of the Docker remote API.
The voxel-dockerclient server is simply nginx, proxying the docker daemon's UNIX socket.~~
The voxel-dockerclient server is a tiny golang program, which serves the client HTML/CSS/javascript, and provides a proxy for the docker API. At the moment, it proxies the full API with no authorization. This will change.
The voxel-dockerclient server is a tiny golang program, which serves the client HTML/CSS/javascript, and provides a proxy for the docker API. At the moment, it proxies the full API with ~~no~~ some authorization. ~~This will change.~~

On the client, it uses the brilliant [voxeljs](http://voxeljs.com/) family of node modules to render the UI, and the [axios](https://github.com/mzabriskie/axios) node module to communicate with the proxied API.

Expand All @@ -123,4 +137,4 @@ I would like to thank:
* The fine folk of @docker, for Docker
* The fine folk behind the voxeljs family of modules. @github/maxogden, @github/kumavis, @github/deathcap, @github/substack et al. These are really nice.
* The authors of the dockerode and axios modules, although I'm not using dockerode any more.
* My partner, Chitra Raghavan, for contributing the player model, testing, and bearing with me while I was building this
* My partner, Chitra Raghavan (@github/chitradoc), for contributing the player model, testing, and bearing with me while I was building this
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ volumes:

services:
vdcservice:
image: rajchaudhuri/voxel-dockerclient:latest
image: rajchaudhuri/voxel-dockerclient:0.4.0
build:
context: .
dockerfile: Dockerfile
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "voxel-dockerclient",
"version": "0.3.0",
"version": "0.4.0",
"description": "An experimental minecraft-like docker client, built using voxel.js.",
"main": "",
"config": {
"registry_user": "rajchaudhuri"
},
"scripts": {
"check-env": "node -e 'console.log(process.env)'",
"test": "echo \"Error: no test specified\" && exit 1",
"build-public": "copyfiles --up 1 public/css/* public/fonts/* public/js/* public/textures/* public/*.html out && copyfiles -f node_modules/xterm/dist/xterm.js out/js && copyfiles -f node_modules/xterm/dist/xterm.css out/css",
"clean-public": "rimraf out/css out/fonts out/js/*dialog.js out/js/xterm.js out/textures out/*.html",
"build-client-debug": "browserify --debug client/main.js -o out/js/client.js",
"build-client-release": "browserify client/main.js -o out/js/client.js",
"clean-client": "rimraf out/js/client.js",
"build-server": "CGO_ENABLED='0' go build -o out/voxel-dockerserver server/*.go",
"build-server": "CGO_ENABLED='0' go build -o out/voxel-dockerserver -ldflags \"-X 'main.version=${npm_package_version}'\" server/*.go",
"clean-server": "rimraf out/server",
"build-debug": "npm run build-public && npm run build-client-debug && npm run build-server",
"build": "npm run build-public && npm run build-client-release && npm run build-server",
"clean": "rimraf out/",
"build-docker": "docker image build -t ${npm_package_config_registry_user}/voxel-dockerclient:${npm_package_version} -f Dockerfile .",
"run-docker": "npm run build-docker && docker container run --rm --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock --publish 8080:8080 ${npm_package_config_registry_user}/voxel-dockerclient:${npm_package_version}",
"clean": "rimraf out/*",
"standard": "standard client/** public/js/**"
},
"repository": {
Expand Down Expand Up @@ -51,4 +57,4 @@
"rimraf": "^2.6.3",
"standard": "^10.0.3"
}
}
}
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
)

var version = ""

func main() {
// Verify presence of docker socket
conn, err := net.Dial("unix", "/var/run/docker.sock")
Expand Down Expand Up @@ -84,6 +86,7 @@ func main() {
}()

// Start listening using the server
log.Printf("Voxel-dockerserver version: %v\n", version)
log.Println("Server starting on port 8080...")
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Fatalf("The server failed with the following error:%v\n", err)
Expand Down

0 comments on commit 75b8956

Please sign in to comment.