From ab967ad6c7ec1a139234e5c9884a31b9105e1730 Mon Sep 17 00:00:00 2001 From: Ashish Date: Tue, 19 Dec 2023 16:08:42 +0530 Subject: [PATCH] changes for run-in-development --- Dockerfile_Dev | 95 ++++++++++++++++++++++++++++++++++ packages/client/vite.config.ts | 6 ++- packages/common/src/config.ts | 3 +- scripts/build_microk8s.sh | 77 ++++++++++++++++++--------- scripts/start-server.sh | 7 ++- 5 files changed, 160 insertions(+), 28 deletions(-) create mode 100644 Dockerfile_Dev diff --git a/Dockerfile_Dev b/Dockerfile_Dev new file mode 100644 index 0000000000..fe4ffda471 --- /dev/null +++ b/Dockerfile_Dev @@ -0,0 +1,95 @@ +# not slim because we need github depedencies +FROM node:18-buster-slim + +RUN apt-get update +RUN apt-get install -y build-essential meson python3-testresources python3-venv python3-pip git procps git-lfs +# Create app directory +WORKDIR /app + +RUN npm install -g npm lerna cross-env rimraf --loglevel notice + +# to make use of caching, copy only package files and install dependencies +COPY package.json . +COPY packages/client/package.json ./packages/client/ +COPY packages/client-core/package.json ./packages/client-core/ +COPY packages/common/package.json ./packages/common/ +COPY packages/editor/package.json ./packages/editor/ +COPY packages/engine/package.json ./packages/engine/ +COPY packages/instanceserver/package.json ./packages/instanceserver/ +COPY packages/hyperflux/package.json ./packages/hyperflux/ +COPY packages/engine/package.json ./packages/engine/ +COPY packages/matchmaking/package.json ./packages/matchmaking/ +COPY packages/server/package.json ./packages/server/ +COPY packages/server-core/package.json ./packages/server-core/ +COPY packages/taskserver/package.json ./packages/taskserver/ +COPY packages/xrui/package.json ./packages/xrui/ +COPY packages/ui/package.json ./packages/ui/ +COPY packages/projects/package.json ./packages/projects/ +COPY project-package-jsons ./ +COPY patches/ ./patches/ + +#RUN npm ci --verbose # we should make lockfile or shrinkwrap then use npm ci for predicatble builds + +ARG NODE_ENV +RUN npm install --loglevel notice --legacy-peer-deps + +COPY . . + +# copy then compile the code + +ARG MYSQL_HOST +ARG MYSQL_PORT +ARG MYSQL_USER +ARG MYSQL_PASSWORD +ARG MYSQL_DATABASE +ARG SERVER_HOST +ARG SERVER_PORT +ARG VITE_APP_HOST +ARG VITE_APP_PORT +ARG VITE_SERVER_HOST +ARG VITE_SERVER_PORT +ARG VITE_FILE_SERVER +ARG VITE_MEDIATOR_SERVER +ARG VITE_LOGIN_WITH_WALLET +ARG VITE_8TH_WALL +ARG VITE_INSTANCESERVER_HOST +ARG VITE_INSTANCESERVER_PORT +ARG VITE_LOCAL_BUILD +ARG VITE_READY_PLAYER_ME_URL +ARG VITE_DISABLE_LOG +ARG VITE_AVATURN_URL +ARG VITE_AVATURN_API +ENV MYSQL_HOST=$MYSQL_HOST +ENV MYSQL_PORT=$MYSQL_PORT +ENV MYSQL_USER=$MYSQL_USER +ENV MYSQL_PASSWORD=$MYSQL_PASSWORD +ENV MYSQL_DATABASE=$MYSQL_DATABASE +ENV SERVER_HOST=$SERVER_HOST +ENV SERVER_PORT=$SERVER_PORT +ENV VITE_APP_HOST=$VITE_APP_HOST +ENV VITE_APP_PORT=$VITE_APP_PORT +ENV VITE_SERVER_HOST=$VITE_SERVER_HOST +ENV VITE_SERVER_PORT=$VITE_SERVER_PORT +ENV VITE_FILE_SERVER=$VITE_FILE_SERVER +ENV VITE_MEDIATOR_SERVER=$VITE_MEDIATOR_SERVER +ENV VITE_LOGIN_WITH_WALLET=$VITE_LOGIN_WITH_WALLET +ENV VITE_8TH_WALL=$VITE_8TH_WALL +ENV VITE_INSTANCESERVER_HOST=$VITE_INSTANCESERVER_HOST +ENV VITE_INSTANCESERVER_PORT=$VITE_INSTANCESERVER_PORT +ENV VITE_LOCAL_BUILD=$VITE_LOCAL_BUILD +ENV VITE_READY_PLAYER_ME_URL=$VITE_READY_PLAYER_ME_URL +ENV VITE_DISABLE_LOG=$VITE_DISABLE_LOG +ENV VITE_AVATURN_URL=$VITE_AVATURN_URL +ENV VITE_AVATURN_API=$VITE_AVATURN_API + +ARG CACHE_DATE +RUN npx cross-env ts-node --swc scripts/check-db-exists.ts +RUN npm run build-client + +RUN rm -r packages/client/public + +RUN bash ./scripts/setup_helm.sh + +ENV APP_ENV=development + +CMD ["scripts/start-server.sh","development"] \ No newline at end of file diff --git a/packages/client/vite.config.ts b/packages/client/vite.config.ts index 67b58a5f12..f819e6f6c6 100755 --- a/packages/client/vite.config.ts +++ b/packages/client/vite.config.ts @@ -234,7 +234,9 @@ export default defineConfig(async () => { resetSWFiles() - const isDevOrLocal = process.env.APP_ENV === 'development' || process.env.VITE_LOCAL_BUILD === 'true' + const isDevOrLocal = + process.env.FORCE_DEV_LOCAL_FALSE !== 'true' && + (!(process.env.APP_ENV === 'development') || process.env.VITE_LOCAL_BUILD === 'true') let base = `https://${process.env['APP_HOST'] ? process.env['APP_HOST'] : process.env['VITE_APP_HOST']}/` @@ -258,7 +260,7 @@ export default defineConfig(async () => { overlay: false } : false, - host: process.env['VITE_APP_HOST'], + host: true, port: process.env['VITE_APP_PORT'], headers: { 'Origin-Agent-Cluster': '?1' diff --git a/packages/common/src/config.ts b/packages/common/src/config.ts index 2c528921e8..9d1ead3e9e 100644 --- a/packages/common/src/config.ts +++ b/packages/common/src/config.ts @@ -27,7 +27,8 @@ Ethereal Engine. All Rights Reserved. * Config settings (for client and isomorphic engine usage). */ const localBuildOrDev = - globalThis.process.env['APP_ENV'] === 'development' || globalThis.process.env['VITE_LOCAL_BUILD'] === 'true' + globalThis.process.env['FORCE_DEV_LOCAL_FALSE'] !== 'true' && + (!(globalThis.process.env['APP_ENV'] === 'development') || globalThis.process.env['VITE_LOCAL_BUILD'] === 'true') export function validateEmail(email: string): boolean { return /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(email) diff --git a/scripts/build_microk8s.sh b/scripts/build_microk8s.sh index b68d78ef4d..424b69d4d3 100755 --- a/scripts/build_microk8s.sh +++ b/scripts/build_microk8s.sh @@ -4,6 +4,7 @@ set -x TAG=$1 CLEAN=$2 +APP_ENV=$3 if [ -z "$SERVER_HOST" ] then @@ -157,30 +158,58 @@ echo "Tag is: $TAG" # docker tag $REGISTRY_HOST:32000/root-builder $REGISTRY_HOST:32000/root-builder:$TAG # docker push $REGISTRY_HOST:32000/root-builder:$TAG -docker buildx build \ - --network=host \ - --cache-to type=inline \ - -t $REGISTRY_HOST:32000/etherealengine \ - --build-arg NODE_ENV=$NODE_ENV \ - --build-arg MYSQL_HOST=$MYSQL_HOST \ - --build-arg MYSQL_PORT=$MYSQL_PORT \ - --build-arg MYSQL_PASSWORD=$MYSQL_PASSWORD \ - --build-arg MYSQL_USER=$MYSQL_USER \ - --build-arg MYSQL_DATABASE=$MYSQL_DATABASE \ - --build-arg SERVER_HOST=$SERVER_HOST \ - --build-arg SERVER_PORT=$SERVER_PORT \ - --build-arg VITE_APP_HOST=$VITE_APP_HOST \ - --build-arg VITE_SERVER_HOST=$VITE_SERVER_HOST \ - --build-arg VITE_FILE_SERVER=$VITE_FILE_SERVER \ - --build-arg VITE_MEDIATOR_SERVER=$VITE_MEDIATOR_SERVER \ - --build-arg VITE_INSTANCESERVER_HOST=$VITE_INSTANCESERVER_HOST \ - --build-arg VITE_READY_PLAYER_ME_URL=$VITE_READY_PLAYER_ME_URL \ - --build-arg VITE_DISABLE_LOG=$VITE_DISABLE_LOG \ - --build-arg VITE_8TH_WALL=$VITE_8TH_WALL \ - --build-arg VITE_LOGIN_WITH_WALLET=$VITE_LOGIN_WITH_WALLET \ - --build-arg VITE_AVATURN_URL=$VITE_AVATURN_URL \ - --build-arg VITE_AVATURN_API=$VITE_AVATURN_API . - +if [[ "$APP_ENV" == "development" ]]; then + docker buildx build \ + --network=host \ + --cache-to type=inline \ + -t $REGISTRY_HOST:32000/etherealengine \ + -f Dockerfile_Dev \ + --build-arg NODE_ENV=$NODE_ENV \ + --build-arg APP_ENV=$APP_ENV \ + --build-arg MYSQL_HOST=$MYSQL_HOST \ + --build-arg MYSQL_PORT=$MYSQL_PORT \ + --build-arg MYSQL_PASSWORD=$MYSQL_PASSWORD \ + --build-arg MYSQL_USER=$MYSQL_USER \ + --build-arg MYSQL_DATABASE=$MYSQL_DATABASE \ + --build-arg SERVER_HOST=$SERVER_HOST \ + --build-arg SERVER_PORT=$SERVER_PORT \ + --build-arg VITE_APP_HOST=$VITE_APP_HOST \ + --build-arg VITE_SERVER_HOST=$VITE_SERVER_HOST \ + --build-arg VITE_FILE_SERVER=$VITE_FILE_SERVER \ + --build-arg VITE_MEDIATOR_SERVER=$VITE_MEDIATOR_SERVER \ + --build-arg VITE_INSTANCESERVER_HOST=$VITE_INSTANCESERVER_HOST \ + --build-arg VITE_READY_PLAYER_ME_URL=$VITE_READY_PLAYER_ME_URL \ + --build-arg VITE_DISABLE_LOG=$VITE_DISABLE_LOG \ + --build-arg VITE_8TH_WALL=$VITE_8TH_WALL \ + --build-arg VITE_LOGIN_WITH_WALLET=$VITE_LOGIN_WITH_WALLET \ + --build-arg VITE_AVATURN_URL=$VITE_AVATURN_URL \ + --build-arg VITE_AVATURN_API=$VITE_AVATURN_API . +else + docker buildx build \ + --network=host \ + --cache-to type=inline \ + -t $REGISTRY_HOST:32000/etherealengine \ + -f Dockerfile \ + --build-arg NODE_ENV=$NODE_ENV \ + --build-arg MYSQL_HOST=$MYSQL_HOST \ + --build-arg MYSQL_PORT=$MYSQL_PORT \ + --build-arg MYSQL_PASSWORD=$MYSQL_PASSWORD \ + --build-arg MYSQL_USER=$MYSQL_USER \ + --build-arg MYSQL_DATABASE=$MYSQL_DATABASE \ + --build-arg SERVER_HOST=$SERVER_HOST \ + --build-arg SERVER_PORT=$SERVER_PORT \ + --build-arg VITE_APP_HOST=$VITE_APP_HOST \ + --build-arg VITE_SERVER_HOST=$VITE_SERVER_HOST \ + --build-arg VITE_FILE_SERVER=$VITE_FILE_SERVER \ + --build-arg VITE_MEDIATOR_SERVER=$VITE_MEDIATOR_SERVER \ + --build-arg VITE_INSTANCESERVER_HOST=$VITE_INSTANCESERVER_HOST \ + --build-arg VITE_READY_PLAYER_ME_URL=$VITE_READY_PLAYER_ME_URL \ + --build-arg VITE_DISABLE_LOG=$VITE_DISABLE_LOG \ + --build-arg VITE_8TH_WALL=$VITE_8TH_WALL \ + --build-arg VITE_LOGIN_WITH_WALLET=$VITE_LOGIN_WITH_WALLET \ + --build-arg VITE_AVATURN_URL=$VITE_AVATURN_URL \ + --build-arg VITE_AVATURN_API=$VITE_AVATURN_API . +fi docker tag $REGISTRY_HOST:32000/etherealengine $REGISTRY_HOST:32000/etherealengine:$TAG docker push $REGISTRY_HOST:32000/etherealengine:$TAG diff --git a/scripts/start-server.sh b/scripts/start-server.sh index da75577c2f..4c45c9cb32 100755 --- a/scripts/start-server.sh +++ b/scripts/start-server.sh @@ -1,5 +1,10 @@ #!/bin/bash +APP_ENV=$1 [ "$SERVER_MODE" = "task" ] && (cd packages/taskserver && npm run start) -[ "$SERVER_MODE" = "client" ] && (cd packages/client && npm run start) +if [ "$APP_ENV" = "development" ]; then + [ "$SERVER_MODE" = "client" ] && (cd packages/client && npm run dev) + else + [ "$SERVER_MODE" = "client" ] && (cd packages/client && npm run start) +fi [ "$SERVER_MODE" = "realtime" ] && (cd packages/instanceserver && npm run start) [ "$SERVER_MODE" = "api" ] && (cd packages/server && npm run start) \ No newline at end of file