Skip to content
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

Setting up Oasis with Docker #433

Closed
murilopolese opened this issue May 10, 2020 · 2 comments
Closed

Setting up Oasis with Docker #433

murilopolese opened this issue May 10, 2020 · 2 comments

Comments

@murilopolese
Copy link

murilopolese commented May 10, 2020

What's the problem you want solved?

I'm struggling to start oasis inside a container to join this other issue. It does work on my Ubuntu14.04 host machine if I have Patchwork running but it does not work on docker running either on my Ubuntu or MacOS machine.

Here is how I reproduced the issue:

Start docker (if you need) and pull node image. I'm using node version 13.

$ docker pull node:13

Start a container with this image with an interactive bash session:

$ docker run -it node bash
root@ac76edd7ad40:/#

Installing oasis package globally:

root@ac76edd7ad40:/# npm -g install fraction/oasis#v2.16.0
/usr/local/bin/oasis -> /usr/local/lib/node_modules/@fraction/oasis/src/index.js

> sodium-native@2.4.9 install /usr/local/lib/node_modules/@fraction/oasis/node_modules/sodium-native
> node-gyp-build "node preinstall.js" "node postinstall.js"


> leveldown@5.6.0 install /usr/local/lib/node_modules/@fraction/oasis/node_modules/leveldown
> node-gyp-build


> sharp@0.25.2 install /usr/local/lib/node_modules/@fraction/oasis/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

ERR! sharp EACCES: permission denied, mkdir '/root/.npm'
info sharp Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/13.12.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@fraction/oasis/node_modules/sharp/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@fraction/oasis/node_modules/sharp/.node-gyp'
gyp ERR! System Linux 4.19.76-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/@fraction/oasis/node_modules/sharp
gyp ERR! node -v v13.12.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

> ejs@2.7.4 postinstall /usr/local/lib/node_modules/@fraction/oasis/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)


> level@5.0.1 postinstall /usr/local/lib/node_modules/@fraction/oasis/node_modules/level
> opencollective-postinstall || exit 0

Thank you for using level!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/level/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: sharp@0.25.2 (node_modules/@fraction/oasis/node_modules/sharp):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: sharp@0.25.2 install: `(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ @fraction/oasis@2.16.0
added 610 packages from 570 contributors in 107.83s

root@ac76edd7ad40:/#

After installing, oasis seems to run:

root@ac76edd7ad40:/# oasis
  oasis No configuration file found at /root/.config/oasis/default.json, using built-in default values. +0ms
  oasis Listening on http://localhost:3000 +784ms
  oasis Starting Scuttlebutt service +0ms
ssb-friends: stream legacy api used

Commit the changes and start again binding the correct ports. To do that we need to exit the container and check what is the id of the container we just left with:

root@ac76edd7ad40:/# exit
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
ac76edd7ad40        node:13             "docker-entrypoint.s…"   9 minutes ago       Exited (130) 2 minutes ago

This time the id was ac76edd7ad40, it can be shortened to ac76:

$ docker commit ac76 oasis:2.16.0
sha256:fbd8ce273413edfa475b4e3bd406ee3652d0bf0c545ba3163b032eb0d00065ca

Run the interactive session again but binding the local port 8000 to the container port 3000:

$ docker run -it -p 8000:3000 oasis:2.16.0 bash
root@a8dfa2fbdb64:/#

As an extra step, check if the port binding is working properly by running an http-server on port 3000 and checking if I can access it on port 8000 of my "host" computer:

root@a8dfa2fbdb64:/# npm install -g http-server
/usr/local/bin/http-server -> /usr/local/lib/node_modules/http-server/bin/http-server
/usr/local/bin/hs -> /usr/local/lib/node_modules/http-server/bin/http-server
+ http-server@0.12.3
added 23 packages from 35 contributors in 3.433s
root@a8dfa2fbdb64:/# cd
root@a8dfa2fbdb64:~# mkdir test
root@a8dfa2fbdb64:~# cd test/
root@a8dfa2fbdb64:~/test# echo "<h1>It works</h1>" > index.html
root@a8dfa2fbdb64:~/test# cat index.html
<h1>It works</h1>
root@a8dfa2fbdb64:~/test# http-server -p 3000 ./
Starting up http-server, serving ./
Available on:
  http://127.0.0.1:3000
  http://172.17.0.2:3000
Hit CTRL-C to stop the server

And in another terminal session on "host" computer see if I get what I should:

curl localhost:8000
<h1>It works</h1>

Then starting oasis:

root@a8dfa2fbdb64:~/test# oasis
  oasis No configuration file found at /root/.config/oasis/default.json, using built-in default values. +0ms
  oasis Listening on http://localhost:3000 +785ms
  oasis Starting Scuttlebutt service +0ms
ssb-friends: stream legacy api used

But now it doesn't serve anything on port 8000:

curl localhost:8000
curl: (52) Empty reply from server

Am I missing something or is this an unexpected behaviour?

@christianbundy
Copy link
Member

Does this also happen when you use the with Docker documentation? There's a Dockerfile in the contrib/ directory that you should be able to use, although at a glance I don't see the difference between your method and the documented method.

@murilopolese
Copy link
Author

Oops, I missed this doc. I did run the Dockerfile and it did run smtoother but I still got locked out.

$ docker run --mount source=ssb,target=/root/.ssb --publish 3000:3000 --rm oasis
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2020-05-10T18:25:21.920Z oasis No configuration file found at /root/.config/oasis/default.json, using built-in default values.
2020-05-10T18:25:22.849Z oasis Listening on http://0.0.0.0:3000
2020-05-10T18:25:22.867Z oasis Starting Scuttlebutt service
ssb-friends: stream legacy api used

So far so good until here but when I ping the addess localhost:3000:

$ curl localhost:3000
Request must be addressed to 0.0.0.0 and non-GET requests must contain non-blob referer.%

The server prints out:

Invalid HTTP hostname: localhost
BadRequestError: Request must be addressed to 0.0.0.0 and non-GET requests must contain non-blob referer.
    at Object.assert (/app/node_modules/http-assert/index.js:8:9)
    at /app/src/http.js:107:9
    at dispatch (/app/node_modules/koa-compose/index.js:42:32)
    at /app/node_modules/koa-mount/index.js:52:32
    at dispatch (/app/node_modules/koa-compose/index.js:42:32)
    at /app/node_modules/koa-compose/index.js:34:12
    at Application.handleRequest (/app/node_modules/koa/lib/application.js:166:12)
    at Server.handleRequest (/app/node_modules/koa/lib/application.js:148:19)
    at Server.emit (events.js:310:20)
    at parserOnIncoming (_http_server.js:786:12)

The browser only renders the following:

Request must be addressed to 0.0.0.0 and non-GET requests must contain non-blob referer.

This is certainly a port binding thing, I did get to access 0.0.0.0:3000 on browser and it works, YAY! I can definitely move on to explore and test more stuff. I saw I can change it with the config file, I think I can figure out how specify the host there.

:) Thanks a lot and sorry for not reading the manual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants