Tschuck / battletris

RPG based multiplayer tetris using vue.js
https://battletris.de
GNU General Public License v3.0
8 stars 1 forks source link

Docker deployment #14

Closed janheinrichmerker closed 2 years ago

janheinrichmerker commented 3 years ago

I've had some issues running this nice app in Docker. It seems like at some time, dependencies are not found. My Dockerfile executes the commands mentioned in the readme. Attached you'll find my Dockerfile:

FROM alpine/git:v2.26.2 AS clone
RUN git config --global advice.detachedHead false
RUN git clone https://github.com/Tschuck/battletris.git /app
WORKDIR /app
RUN git checkout 260e0f2f2c087591748be2b3235d0bc2e8189c2a
RUN rm -rf .git

FROM node:14.15.1-stretch AS build
COPY --from=clone /app /app
WORKDIR /app
RUN yarn install
RUN yarn deploy

FROM node:14.15.1-stretch
COPY --from=build /app/.deploy /app
WORKDIR /app
RUN yarn install
EXPOSE 5000
CMD ["yarn", "start"]

This is the output log:

Building tetris
Step 1/17 : FROM alpine/git:v2.26.2 AS clone
 ---> ed0ba0fc6585
Step 2/17 : RUN git config --global advice.detachedHead false
 ---> Running in fd2d5d6555c4
Removing intermediate container fd2d5d6555c4
 ---> 4212e2f39702
Step 3/17 : RUN git clone https://github.com/Tschuck/battletris.git /app
 ---> Running in fda6aab23054
Cloning into '/app'...
Removing intermediate container fda6aab23054
 ---> 6559e1f08955
Step 4/17 : WORKDIR /app
 ---> Running in c186a867174b
Removing intermediate container c186a867174b
 ---> fc6d886c8d3b
Step 5/17 : RUN git checkout 260e0f2f2c087591748be2b3235d0bc2e8189c2a
 ---> Running in 57b33acbcd21
HEAD is now at 260e0f2 add keymaps interfaces and laboratory
Removing intermediate container 57b33acbcd21
 ---> 82b0608511bd
Step 6/17 : RUN rm -rf .git
 ---> Running in e22a3f94b704
Removing intermediate container e22a3f94b704
 ---> b51e36067c77
Step 7/17 : FROM node:14.15.1-stretch AS build
 ---> 5d3b556415e2
Step 8/17 : COPY --from=clone /app /app
 ---> 306ed627c638
Step 9/17 : WORKDIR /app
 ---> Running in 68e193eddcfc
Removing intermediate container 68e193eddcfc
 ---> 5713e60132f1
Step 10/17 : RUN yarn install
 ---> Running in a3320349183d
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
$ yarn install:shared && yarn install:backend && yarn install:frontend
yarn run v1.22.5
$ cd ./shared && yarn install
warning package.json: No license field
info No lockfile found.
warning @battletris/shared: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-jsx-a11y@^6.4.1".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-react@^7.21.5".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-react-hooks@^4 || ^3 || ^2.3.0 || ^1.7.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 14.84s.
yarn run v1.22.5
$ cd ./backend && yarn install
warning package.json: No license field
info No lockfile found.
warning battletris: No license field
[1/4] Resolving packages...
warning sqlite3 > node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
warning sqlite3 > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning sqlite3 > node-gyp > request > har-validator@5.1.5: this library is no longer supported
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > @typescript-eslint/eslint-plugin@3.10.1" has unmet peer dependency "@typescript-eslint/parser@^3.0.0".
warning " > eslint-config-airbnb-base@14.2.1" has unmet peer dependency "eslint-plugin-import@^2.22.1".
warning " > eslint-config-airbnb-typescript@7.2.1" has incorrect peer dependency "@typescript-eslint/eslint-plugin@^2.24.0".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-import@^2.22.1".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-jsx-a11y@^6.4.1".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-react@^7.21.5".
warning "eslint-config-airbnb-typescript > eslint-config-airbnb@18.2.1" has unmet peer dependency "eslint-plugin-react-hooks@^4 || ^3 || ^2.3.0 || ^1.7.0".
warning "eslint-config-airbnb-typescript > @typescript-eslint/parser@2.34.0" has incorrect peer dependency "eslint@^5.0.0 || ^6.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
$ cd ../shared && yarn link && cd ../backend && yarn link @battletris/shared
warning package.json: No license field
warning package.json: No license field
success Registered "@battletris/shared".
info You can now run `yarn link "@battletris/shared"` in the projects where you want to use this package and it will be used instead.
warning package.json: No license field
success Using linked package for "@battletris/shared".
Done in 18.14s.
yarn run v1.22.5
$ cd ./frontend && yarn install
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.1: The platform "linux" is incompatible with this module.
info "fsevents@2.3.1" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@vue/eslint-config-airbnb > eslint-import-resolver-webpack@0.13.0" has unmet peer dependency "webpack@>=1.11.0".
warning " > sass-loader@8.0.2" has unmet peer dependency "webpack@^4.36.0 || ^5.0.0".
[4/4] Building fresh packages...
$ cd ../shared && yarn link && cd ../frontend && yarn link @battletris/shared
warning package.json: No license field
warning package.json: No license field
warning There's already a package called "@battletris/shared" registered. This command has had no effect. If this command was run in another folder with the same name, the other folder is still linked. Please run yarn unlink in the other folder if you want to register this folder.
success Using linked package for "@battletris/shared".
Done in 21.81s.
Done in 55.84s.
Removing intermediate container a3320349183d
 ---> 0326ce3419d7
Step 11/17 : RUN yarn deploy
 ---> Running in 8383d5a78b3d
yarn run v1.22.5
$ yarn build && node prepare-deploy.js
$ yarn build:backend && yarn build:frontend
$ cd ./backend && yarn build
warning package.json: No license field
$ rm -rf ./dist/node_modules && rm -rf ./dist/src && tsc -p tsconfig.json
$ cd ./frontend && yarn build
$ vue-cli-service build --modern && yarn build:copy-statics

-  Building legacy bundle for production...
Starting type checking service...
Using 1 worker with 2048MB memory limit

warn - Tailwind is not purging unused styles because no template paths have been provided.
warn - If you have manually configured PurgeCSS outside of Tailwind or are deliberately not removing unused styles, set `purge: false` in your Tailwind config file to silence this warning.
warn - https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
 ERROR  Failed to compile with 1 error7:57:00 AM

 error  in /app/frontend/src/views/Laboratory.vue

ERROR in /app/frontend/src/views/Laboratory.vue(85,28):
85:28 Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import("/app/frontend/node_modules/@battletris/shared/functions/keymaps/index")'.
  No index signature with a parameter of type 'string' was found on type 'typeof import("/app/frontend/node_modules/@battletris/shared/functions/keymaps/index")'.
    83 |     const keyMapChanged = () => {
    84 |       debugger;
  > 85 |       activeKeyMap.value = KeyMaps[activeKeyMapId.value] as KeyMapInterface;
       |                            ^
    86 |     };
    87 |     keyMapChanged();
    88 | 

 ERROR  Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: Service 'tetris' failed to build: The command '/bin/sh -c yarn deploy' returned a non-zero code: 1
Tschuck commented 3 years ago

Hi. I'm so sorry for the late response. Seems like my mail program hid the message and i hadn't a look into the repo in the last month.

Awesome that you tried it in docker! The error looks like a build error of a unfinished version on the dev branch. I was able finish the work for the keymaps and the custom controls this week, so it should work now out of the box.

Can you try it again with the latest master version? Thanks! :)

janheinrichmerker commented 2 years ago

I had to hack some additional changes even after pulling the latest master version. But now this Dockerfile builds and runs:

FROM alpine/git:v2.26.2 AS clone
RUN git config --global advice.detachedHead false
RUN git clone https://github.com/Tschuck/battletris.git /app
WORKDIR /app
RUN git checkout 35b273d5bae895084ca0aea9708fcd90a1a510a0
RUN rm -rf .git

FROM node:16.13.0-alpine AS build
COPY --from=clone /app /app
WORKDIR /app
RUN yarn install
# Fix deprecated types.
RUN sed -i "s/Record<string, string>/Record<string, string | string[]>/g" backend/src/server/RoomHandler.ts
# Refresh browser data.
RUN cd frontend && npx browserslist@latest --update-db
# Update frontend build target.
RUN sed -i "s/\"target\": \"esnext\"/\"target\": \"es2019\"/g" frontend/tsconfig.json
# Update server.
ARG BATTLETRIS_SERVER="localhost:5000"
RUN sed -i "s/https:\/\/battletris.de/http:\/\/$BATTLETRIS_SERVER/g; s/wss:\/\/battletris.de/ws:\/\/$BATTLETRIS_SERVER/g" frontend/.env.production
RUN yarn deploy

FROM node:16.13.0-alpine
COPY --from=build /app/.deploy /app
WORKDIR /app
RUN yarn install
EXPOSE 5000
CMD ["yarn", "start"]
Tschuck commented 2 years ago

Nice! Looks good thanks. Probably i need to fix some small things, so the replacing would not be necessary.

janheinrichmerker commented 2 years ago

That would be great!

janheinrichmerker commented 2 years ago

Maybe read the server hostname from an environment variable, so that we can have localhost:5000 as default and override this for production easily? Then, after some compatibility updates I can create a pull request with a simple, minimal Dockerfile.

Tschuck commented 2 years ago

Alright. Will test the stuff the next days!

Btw. i found your "spieleabend" repo. Nice idea

janheinrichmerker commented 2 years ago

Thanks! And feel free to reuse it! (Or suggest additional games.)

janheinrichmerker commented 2 years ago

Closing due to inactivity.