dot-cafe / beam.cafe

🌠 Blazing fast file transfer app focused on user-experience. Fastest way to share files without uploading them.
https://beam.cafe
MIT License
438 stars 14 forks source link

Docker support #4

Closed simonwep closed 3 years ago

simonwep commented 4 years ago

So far you can only install beam.cafe locally - I'd be awesome to make something like a docker-compose file to setup both the front- and backend in one go. The backend-part is just an API (there's already a Dockerfile for beam.cafe.backend - nothing firm yet) but the front-end has to serve files and I don't want to use things like http-server as there will be a nginx-layer on top of both (Should nginx be a part of the docker-cluster or seperated and in the first case: how should the TSL Certificate be handled?).

I'm not sure what would be the best way to do that so Ideas / Suggestion / PRs are highly appreciated.

azrikahar commented 4 years ago

Perhaps a reverse proxy would be fitting here? I am working on a repo about reverse proxies on Docker so I might be biased, but it does feel fitting here so I'll try to take stab at it. Here is a sample setup:

        +-----------+
        |  Traefik  |
        +-----+-----+
              |
      +-------+-------+
      |               |
      v               v
[ beam.com ]   [beam.com/(d|b|ws)]
      +               +
      |               |
      v               v
+-----+-----+   +-----+-----+
| Frontend  |   |  Backend  |
+-----------+   +-----------+

Explanation:


Alternatively, a more one-to-one approach with the current one in beam.cafe.sh would be having a nginx container as the main point of entry and the backend is proxied by it. Basically just containerizing/automating the current recommended deployment steps, though this does also mean it's not as easy to add other services at any moment. This is because we will need to modify the nginx conf file and restarting the nginx service will most likely disrupt the existing streams/uploads (I might be wrong here).

antoinebou12 commented 4 years ago

I think you should put your own auth system In my personal experience traefik is a pain

Also you can change the Dockerfile and used the script in beam.cafe.sh

Tips for a smaller container https://antonfisher.com/posts/2018/03/19/reducing-docker-image-size-of-a-node-js-application/

What I will do is to create 2 separate Dockerfile

===================================================================================================================================================== Frontend (not tested)

###frontend
FROM alpine:current-alpine

WORKDIR /frontend

COPY ./ ./

# install dependency
RUN npm install --production
RUN rm -rf .github .gitignore .eslintrc .editorconfig LICENSE README.md babel.config.js postcss.config.js tsconfig.json webpack.config.dev.js

# Command to start the server
CMD npm run build

===================================================================================================================================================== Backend (not tested)


FROM node:alpine3.11 as build-stage

# Create app directory
WORKDIR /backend

# Copy the important file
COPY . .

# Install app dependencies
RUN npm install

# Build the application for deployment
RUN npm run build

###backend
FROM alpine:current-alpine

WORKDIR /backend

COPY --from=build-stage /backend/dist /backend

# install dependency
RUN npm install --production

# Command to start the server
CMD RUN npm run start

===================================================================================================================================================== +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Create Dockerfile image

cd beam.cafe
docker build . -f Dockerfile -t dotcafe/beam.cafe
cd .. 
cd beam.cafe.backend
docker build . -f Dockerfile -t dotcafe/beam.cafe.backend

Upload to Docker Hub if you want

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

docker-compose.yml (not tested)

version: "3.7"
services:
  beamcafe_frontend:
    image: dotcafe/beam.cafe
    container_name: beamcafe_frontend
    env_file: env/production.env # change the path to your env file
    ports:
      - 8080:8080
    links:
      - beamcafe_backend
    depends_on:
      - beamcafe_backend
    restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"

  beamcafe_backend:
    image: dotcafe/beam.cafe.backend
    container_name: beamcafe_backend
    env_file: env/production.env # change the path to your env file
    ports:
      - 3000:3000
    restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"

=====================================================================================================================================================

docker-compose.yml can be put in Kubernetes easily

I can make make a pull request and test it if you want

simonwep commented 4 years ago

@antoinebou13 That looks fantastic! If you want you could make an PR in both the front- and the backend on a new docker branch (beam.cafe.backend already has such a branch) - this way I can easily try it out and we can track the progress of docker compatibility / integration :D

simonwep commented 3 years ago

Done.