Skip to content

1. Setup & Installation

Boris edited this page Jan 20, 2025 · 7 revisions

This guide will help you set up YAR using Docker Compose. Follow the steps below to get everything up and running.

Prerequisites

Before you begin, ensure you have the following installed on your system:


Step 1: Create a new directory

Create a directory where we will store our files.

mkdir yar && cd yar

Step 2: Create the docker-compose file

In the folder you just created, create a new file named docker-compose.yml and add the following content:

services:
  traefik:
    image: traefik:v2.2
    restart: unless-stopped
    command:
      - "--api.insecure=true"
      - "--api.dashboard=false"
      - "--providers.docker=true"
      - "--entrypoints.web.address=:80"
    ports:
      - "${EXTERNAL_PORT}:80"
    networks:
      - yar-network
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  database:
    image: mariadb
    restart: unless-stopped
    env_file:
      - .env
    networks:
      - yar-network
    volumes:
      - yar-database:/var/lib/mysql
    healthcheck:
      test:
        [
          "CMD",
          "/usr/local/bin/healthcheck.sh",
          "--su-mysql",
          "--connect",
          "--innodb_initialized"
        ]

  backend:
    image: borisnl/yar-backend:latest
    restart: unless-stopped
    env_file:
      - .env
    depends_on:
      database:
        condition: service_healthy
    networks:
      - yar-network
    volumes:
      - ./data:/app/data
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.backend.rule=PathPrefix(`/api`)"
      - "traefik.http.routers.backend.entrypoints=web"
      - "traefik.http.routers.backend.middlewares=strip-api-prefix"
      - "traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api"
      - "traefik.http.services.backend.loadbalancer.server.port=3000"

  web:
    image: borisnl/yar-web:latest
    restart: unless-stopped
    env_file:
      - .env
    depends_on:
      - backend
    networks:
      - yar-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web.rule=PathPrefix(`/`)"
      - "traefik.http.routers.web.entrypoints=web"
      - "traefik.http.services.web.loadbalancer.server.port=3000"

volumes:
  yar-database:


networks:
  yar-network:

Step 3: Create the .env file

Next, create a .env file. This file will hold the environment variables required for YAR. Add the necessary configurations as shown below:

NODE_ENV=production

MYSQL_DATABASE=yar
MARIADB_ROOT_PASSWORD=password
DATABASE_URL=mysql://root:${MARIADB_ROOT_PASSWORD}@database/yar

EXTERNAL_PORT=8080
# The domain where the app is running, this only affects production
DOMAIN=http://localhost:${EXTERNAL_PORT}

I strongly recommend changing the root password to a long and secure string.

Step 4: Start the Application

With the docker-compose.yml and .env files in place, you can now start the application using Docker Compose. Run the following command in your terminal:

docker-compose up -d

Step 5: Access the Application

Your YAR application should now be up and running. You can access it via your web browser at http://localhost:port (replace port with the port number defined in your .env file).


Troubleshooting

If you encounter any issues during setup, consider the following steps:

  • Check the .env file for any missing or incorrect values.
  • Review the logs using docker-compose logs for error messages.
  • Ensure Docker and Docker Compose are correctly installed and running.