diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..2564b97dc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# common +**/node_modules +.git + +# client module +www/js +www/js-lib +www/js-bundles +www/media/music +www/resource_packs/bbmodel/*.json +www/resource_packs/bbmodel/textures/*.png +www/resource_packs/bbmodel/textures/*.jpg +www/resource_packs/bbmodel/textures/*.jpeg +www/resource_packs/base/textures +www/resource_packs/base/blocks.json + +# server module +node_server/js_server \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0fa39808a..dba577124 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/world +/storage www/js-gen www/js-bundles www/js-lib diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a42cf42ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +FROM node:19.7.0-alpine + +WORKDIR /app + +# Install necessary dependencies +RUN apk add --no-cache git wget fontconfig + +# Create folders +RUN mkdir -p \ + /app/webcraft \ + /app/webcraft/node_server \ + /app/webcraft/ff-worker + +# Copy package.json files +COPY package.json /app/webcraft/package.json +COPY node_server/package.json /app/webcraft/node_server/package.json +COPY ff-worker/package.json /app/webcraft/ff-worker/package.json + +# Install all dependencies +# TODO: Use npm ci instead of npm install after removing package-lock from .gitignore +RUN cd /app/webcraft && \ + npm install && \ + cd /app/webcraft/node_server && \ + npm install && \ + cd /app/webcraft/ff-worker && \ + npm install + +# Download resourcepacks +RUN mkdir -p /app/resource-packs && \ + wget -q -O /app/resource-packs/depixel.zip https://dl.dropboxusercontent.com/s/vjob09w2pn2gv1m/Depixel.zip && \ + unzip /app/resource-packs/depixel.zip -d /app/resource-packs/depixel && \ + rm /app/resource-packs/depixel.zip && \ + git clone --depth=1 --branch=main https://github.com/sciner/webcraft-texturepack /app/resource-packs/1 && \ + rm -rf /app/resource-packs/1/.git + +# Copy all files +COPY . /app/webcraft + +# Create music folder +RUN mkdir -p /app/music && \ + cp /app/webcraft/doc/examples/music.json /app/music/music.json + +# Compile assets +RUN cd /app/webcraft/node_server && \ + npm run compile-assets + +# Compile typescript +RUN cd /app/webcraft && \ + npm run build:www && \ + npm run types:server + +# Compile ff_worker +RUN cd /app/webcraft/ff-worker && \ + npm run start + +WORKDIR /app/webcraft/node_server + +CMD npm run start \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..f05d7ffec --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '2' + + +services: + app: + build: . + volumes: + - ./storage:/app/webcraft/storage + ports: + - 5700:5700 \ No newline at end of file diff --git a/node_server/conf.json b/node_server/conf.json index adf764e4a..3884b44bd 100644 --- a/node_server/conf.json +++ b/node_server/conf.json @@ -1,7 +1,7 @@ { "AppVersion": "0.0.3", "AppCode": "madcraft", - "ServerIP": "127.0.0.1", + "ServerIP": "0.0.0.0", "Port": 5700, "Addr": ":5700", "JSONRPCEndpoint": "/api/", diff --git a/node_server/server_game.ts b/node_server/server_game.ts index 2a029e8fe..a4cfe0224 100644 --- a/node_server/server_game.ts +++ b/node_server/server_game.ts @@ -104,7 +104,7 @@ export class ServerGame { console.log(`>>>>>>> BEFORE LOAD WORLD ${world_guid} <<<<<<<`); const p = performance.now(); const worldTitlePromise = this.db.getWorld(world_guid); - const conn = await SQLiteServerConnector.connect(`../world/${world_guid}/world.sqlite`); + const conn = await SQLiteServerConnector.connect(`../storage/world/${world_guid}/world.sqlite`); const world = new ServerWorld(BLOCK); const db_world = await DBWorld.openDB(conn, world); const title = (await worldTitlePromise).title; @@ -129,7 +129,7 @@ export class ServerGame { // Start websocket server async start(config) { - const conn = await SQLiteServerConnector.connect('./game.sqlite3'); + const conn = await SQLiteServerConnector.connect('../storage/game.sqlite3'); await DBGame.openDB(conn).then((db) => { this.db = db; (global as any).Log = new GameLog(this.db);