docs/content/4.backend/1.deploy.md

4.8 KiB

title
Deploy

Deploying the backend

The only officially recognized hosting method is through Docker (or similar container runtimes). It can be scaled horizontally to all your heart's content and is the safest way to host the backend.

For configuration, check out the configuration reference.

::alert{type="info"} The postgres database will need to be populated with migrations if postgres.migrateOnBoot isn't enabled. ::

Method 1 - Docker Deployment

This method provides a straightforward setup with minimal configuration. For more extensive customization, see the Configuration Reference.

Prerequisites

Setup

  1. Create docker-compose.yml:

    version: '3.8'
    
    services:
      postgres:
        image: postgres
        environment:
          POSTGRES_USER: movie_web_user 
          POSTGRES_DB: movie_web_backend 
          POSTGRES_PASSWORD: YourPasswordHere 
        ports:
          - "5432:5432" 
        networks:
          - movie-web-network
    
      movie-web:
        image: ghcr.io/movie-web/backend:latest
        environment:
          MWB_POSTGRES__CONNECTION: postgresql://movie_web_user:YourPasswordHere@postgres:5432/movie_web_backend
          MWB_CRYPTO__SESSION_SECRET: 32CharacterLongStringHere 
          MWB_META__NAME: unofficial-movie-web 
          MWB_POSTGRES__MIGRATE_ON_BOOT: "true" 
        ports:
          - "80:80"
        depends_on:
          - postgres
        networks:
          - movie-web-network
    
    networks:
      movie-web-network: 
        driver: bridge
    

    Important:

    • Replace YourPasswordHere with your secure database password.
    • Generate a strong session secret and replace 32CharacterLongStringHere.
  2. Start the Backend: Open a terminal in the directory containing docker-compose.yml and execute:

    docker-compose up -d 
    

Accessing Your Backend

Your backend should be accessible on (YourPrivateIP):80. To share it outside your local network, you'll need to configure port forwarding or cloudflared tunnel.

Optional: Using a Reverse Proxy For SSL and domain configuration, consider setting up a reverse proxy like Nginx.

  • If you do use a reverse proxy, you may need to add MWB_SERVER__CORS: "example.com movie.example.com".
  • Dependent on your setup you may also need MWB_SERVER__TRUST_PROXY: true, and MWB_SERVER__TRUST_CLOUDFLARE: true.

Method 2 - Railway (Easy)

Railway provides a simple deployment process and $5 of initial credit, usually enough to run the backend for several months.

Deploy on Railway

  1. Create or Log in to Railway: Visit https://railway.app and either create an account or log in.
  2. Deploy with One Click: Click the "Deploy on Railway" button above.
  3. Configure Environment Variables: Fill in the required environment variables or modify the defaults.
  4. Deploy: Click the "Deploy" button.
  5. Access Your Deployment: Once deployment is complete, retrieve the URL from your Railway Deployments page.

Congratulations! You've successfully deployed the backend. Proceed to set up the client.

Method 2 - Railway (Easy)

Railway offers you $5 of credit once you verify your account, which is enough to run the backend for around 5 months (~$0.90 per month).

Deploy on Railway

  1. Login to your Railway account if you have one, otherwise create one here.
    1. If you are signing up, then verify your account by clicking the link in the email Railway sends you.
    2. If you created your account with an email, then to verify your account further, go to your account, then plans and verify your account with a GitHub account.
  2. Click the Deploy on Railway button above.
  3. If a Configure button is displayed, click on it and allow Railway to access your GitHub account.
  4. Fill in the required variables or change the default values.
  5. The Deploy button at the bottom of the template should be active, click on it.
  6. Once the Backend service has deployed, copy the URL from the Deployments page. (Might take a second for it to be available after the service has deployed)
  7. Congratulations! You have deployed the backend, you can now set up the client.