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

Summary: Add docker support. #47

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
docker/log/**

# Editor directories and files
.idea
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ npm run build
### Customize the configuration

See [Configuring quasar.conf.js](https://v2.quasar.dev/quasar-cli/quasar-conf-js).

## Docker

Docker image can be created by the exection of the docker build script.
In this process, vircadia web sdk (https://github.com/vircadia/vircadia-web-sdk) will be cloned and compiled. There is a product "vircadia-web-sdk-[VERSION].tgz" where VERION is the web-sdk version. Consult the vircadia-web-sdk doc for the exact version number. As of 2/8/2022, the default version is 2022.1.2. Make sure that the right version is passed when execute it.
The version argument is passed at the build-docker.sh "--build-arg WEB_SDK_VER".
Port 8080 is open for this. Its log can be found at the local "log" directory.

```
cd docker && ./build-docker.sh
```

Docker image "vercadia-web" will be created and this image can be used as a part of docker-compose. Please consult vircadia-domain-server-docker (https://github.com/vircadia/vircadia-domain-server-docker).
62 changes: 62 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM ubuntu:20.04 as web-base

RUN apt update && apt install -y git curl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use apt-get instead of plain apt to get rid of the warning "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUN apt-get update && apt-get upgrade && apt-get install -y git curl
That is, shouldn't there be an "upgrade" after the "update"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... it doesn't hurt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... it doesn't hurt.

RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh && \
bash ./nodesource_setup.sh && \
apt install nodejs && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installs NodeJS v14. The SDK's package-lock.json is version 2 which implies NodeJS v16. There are some warning because of this. Might need to use NVM or similar to get a different NodeJS version.
Also, v-web-sdk should probably have an "engine:" section added to its package.json.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering what would be the right. if so, let's update to 16.

rm ./nodesource_setup.sh

FROM web-base as web-sdk-builder
RUN apt update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 'update' necessary since it was done in the base image?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... drop it.

# checkout repo
RUN mkdir -p /usr/local/src && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Docker layer caching might use a cached layer even if the v-web sources have changed, adding a ADD https://api.github.com/repos/vircadia/vircadia-web/git/refs/heads/master vircadia-web-git-version.json before this RUN will break the cache if the sources have changed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!!! Add this line.

Copy link
Author

@hasbegun hasbegun Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this line causes an error like following:

21 40.93 npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
#21 41.21 npm WARN deprecated [email protected]: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
#21 50.11 npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
#21 71.51 npm ERR! code ERR_SOCKET_TIMEOUT
#21 71.51 npm ERR! network Socket timeout
#21 71.51 npm ERR! network This is a problem related to network connectivity.

Any idea why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw those errors also but figured they were related to v-web-sdk configuration/versioning. Maybe need a revisit of the v-web-sdk build independent of the Docker image. Wonder what v-web-sdk has for package-lock and other requirements.

cd /usr/local/src && \
git clone --depth 1 --branch master https://github.com/vircadia/vircadia-web-sdk.git

RUN cd /usr/local/src/vircadia-web-sdk && \
npm install && npm run build && npm pack

FROM web-base
# RUN apt update
RUN npm install -g @vue/cli && npm install -g @quasar/cli

# Default is 2022.1.2. Make sure this version alligns with web-sdk version.
ARG WEB_SDK_VER=2022.1.2

# default is 'vircadia'
ARG REPO=vircadia
# default is 'master'
ARG BRANCH=master

# checkout repo
RUN mkdir -p /usr/local/src && \
cd /usr/local/src && \
git clone --depth 1 --branch ${BRANCH} https://github.com/${REPO}/vircadia-web.git

COPY --from=web-sdk-builder /usr/local/src/vircadia-web-sdk/vircadia-web-sdk-${WEB_SDK_VER}.tgz /usr/local/src/
RUN cd /usr/local/src && \
tar zxvf vircadia-web-sdk-${WEB_SDK_VER}.tgz && npm install -g ./package

RUN cd /usr/local/src/vircadia-web && npm i && npm run build

ENV USER=cadia
ENV VIRCADIAWEB=vircadia-web

# Add a user for the server to run under
RUN adduser --disabled-password --gecos 'vircadia user' ${USER}

RUN apt update && apt install -y sudo vim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 'update' necessary since we are derived from 'web-base'?

RUN usermod -aG sudo ${USER} && \
echo '%sudo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure adding to sudo. If this is a deployed version, the whole point of creating a user to run the app is so there run environment is somewhat safe. Maybe have some "debug build" option?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is only dev and debug. Will comment it out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the proper command to run the app?
I split build
web-base
| - ubuntu20.04
| - node 16, quasar, and vue
|- web-sdk-build => produces vircadia-web-sdk-2022.1.2.tgz
|- web-build => build app
|- web-run => run app
- create cadia user,
- copy /usr/local/src/vircadia-web/package*.json /home/cadia/vircadia-web
- copy /usr/local/src/vircadia-web/dist /home/cadia/vircadia-web/dist
- Run npm install --production
This will remove "sudo".
Can you recommend me a command line that runs the app?

cp /root/.bashrc /home/${USER}/ && \
chown -R --from=root ${USER}:${USER} /home/${USER} && \
touch $HOME/.sudo_as_admin_successful
ENV PATH /home/developer/.local/bin:$PATH

WORKDIR /home/${USER}
USER ${USER}:${USER}
RUN mkdir -p /home/${USER}/${VIRCADIAWEB}/log
COPY --chown=${USER}:${USER} ./files/run-vircadia-web.sh /home/${USER}/

EXPOSE 8080
ENTRYPOINT [ "/home/cadia/run-vircadia-web.sh" ]
11 changes: 11 additions & 0 deletions docker/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/bash
if [ -z "$1" ]
then
WEB_SDK_VER=2022.1.2
echo "Vircadia Web SDK version is not supplied."
else
WEB_SDK_VER=$1
fi
echo "Vircadia Web SDK version ${WEB_SDK_VER} is used."

docker build -t vircadia-web --build-arg WEB_SDK_VER=${WEB_SDK_VER} .
16 changes: 16 additions & 0 deletions docker/files/run-vircadia-web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash

BASE=/home/cadia/vircadia-web

# Default location for logs is in the Iamus sub-directory
LOGDIR=${BASE}/log
# If a log directory is provided in the mounted 'config' dir, use that one
if [[ -d "/home/cadia/vircadia-web/log" ]] ; then
LOGDIR=/home/cadia/vircadia-web/log
fi
mkdir -p "${LOGDIR}"

LOGFILE=${LOGDIR}/$(date --utc "+%Y%m%d.%H%M").log
echo "Log file: ${LOGFILE}"
cd /usr/local/src/vircadia-web
sudo npm run dev >> ${LOGFILE} 2>&1
15 changes: 15 additions & 0 deletions docker/run-docker-vircadia-web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /bin/bash
# Start the metaverseserver with persistant data in local dir

BASE=$(pwd)
cd "${BASE}"

DVERSION=latest

docker run -it --rm \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I first ran the image, I got the error:

vircadia@nyxx:~/vircadia-web-mb/docker> ./run-docker-vircadia-web.sh
Log file: /home/cadia/vircadia-web/log/20220213.1741.log
/home/cadia/run-vircadia-web.sh: line 16: /home/cadia/vircadia-web/log/20220213.1741.log: Permission denied
vircadia@nyxx:~/vircadia-web-mb/docker>

which says that the mounted log directory didn't have the permissions to create files in the mounted directory.
This run file should check and/or change the permissions of the target log directory to allow the Docker account "cadia" to write into the mounted dir.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. need to change how it runs the app. For now it requires sudo. I am going to drop 'sudo' and move app to /home/cadia. Let me do it.

--name=vircadia-web \
-p 8080:8080 \
-p 8081:8081 \
-p 8082:8082 \
--volume ${BASE}/log:/home/cadia/vircadia-web/log \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a "--detach" to run the container as a service in the background.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is to be a service, add a "--restart=unless-stopped"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

vircadia-web:${DVERSION}
Binary file added docker/vircadia-web-sdk-2022.1.1.tgz
Binary file not shown.
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const FalseValue = "false";

export const DefaultConfig: { [key: string]: string } = {
"Default_Metaverse_Url": "https://metaverse.vircadia.com/live",
// docker compose metaverse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance this comment to say this is a debugging option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. will update the comment.

// "Default_Metaverse_Url": "http://localhost:9400",
//////
"Default_Domain_Protocol": "wss:",
"Default_Domain_Port": "40102"
};
Expand Down
1 change: 0 additions & 1 deletion src/vircadia-web-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,4 @@ declare module "@vircadia/web-sdk" {
get avatarList(): AvatarListInterface;
update(): void;
}

}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
"@Store/*": ["./src/store/*"]
}
}

}