sublinks / sublinks-api

MIT License
74 stars 18 forks source link

Add local evironment setup instructions to README.md #96

Open jgrim opened 9 months ago

jgrim commented 9 months ago

Create a set of instructions to get new contributors to the Sublinks API to set up a local development environment quickly and easily.

jgrim commented 8 months ago

docker-compose.yml

version: "3.7"

x-logging: &default-logging
  driver: "json-file"
  options:
    max-size: "50m"
    max-file: "4"

services:
  proxy:
    image: nginx:1-alpine
    ports:
      - "1236:1236"
      - "8536:8536"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro,Z
    restart: always
    depends_on:
      - pictrs
      - lemmy-ui
    logging: *default-logging
    extra_hosts:
      - host.docker.internal:host-gateway

  lemmy-ui:
    image: dessalines/lemmy-ui:0.19.0
    # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
    environment:
      - LEMMY_UI_LEMMY_INTERNAL_HOST=host.docker.internal:8080
      - LEMMY_UI_LEMMY_EXTERNAL_HOST=localhost:1236
      - LEMMY_UI_HTTPS=false
      - LEMMY_UI_DEBUG=true
    restart: always
    logging: *default-logging
    init: true
    extra_hosts:
      - host.docker.internal:host-gateway

  pictrs:
    image: asonix/pictrs:0.4.7
    hostname: pictrs
    ports:
      - "8081:8080"
    environment:
      - PICTRS_OPENTELEMETRY_URL=http://otel:4137
      - PICTRS__API_KEY=API_KEY
      - RUST_LOG=debug
      - RUST_BACKTRACE=full
      - PICTRS__MEDIA__VIDEO_CODEC=vp9
      - PICTRS__MEDIA__GIF__MAX_WIDTH=256
      - PICTRS__MEDIA__GIF__MAX_HEIGHT=256
      - PICTRS__MEDIA__GIF__MAX_AREA=65536
      - PICTRS__MEDIA__GIF__MAX_FRAME_COUNT=400
    user: 991:991
    #volumes:
    #  - ./volumes/pictrs:/mnt:Z
    restart: always
    logging: *default-logging

nginx.conf

worker_processes 1;
events {
    worker_connections 1024;
}
http {
    upstream lemmy {
        # this needs to map to the lemmy (server) docker service hostname
        server "host.docker.internal:8080";
    }
    upstream lemmy-ui {
        # this needs to map to the lemmy-ui docker service hostname
        server "lemmy-ui:1234";
    }

    server {
        # this is the port inside docker, not the public one yet
        listen 1236;
        listen 8536;
        # change if needed, this is facing the public web
        server_name localhost;
        server_tokens off;

        gzip on;
        gzip_types text/css application/javascript image/svg+xml;
        gzip_vary on;

        # Upload limit, relevant for pictrs
        client_max_body_size 20M;

        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";

        # frontend general requests
        location / {
            # distinguish between ui requests and backend
            # don't change lemmy-ui or lemmy here, they refer to the upstream definitions on top
            set $proxpass "http://lemmy-ui";

            if ($http_accept = "application/activity+json") {
              set $proxpass "http://lemmy";
            }
            if ($http_accept = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") {
              set $proxpass "http://lemmy";
            }
            if ($request_method = POST) {
              set $proxpass "http://lemmy";
            }
            proxy_pass $proxpass;

            rewrite ^(.+)/+$ $1 permanent;
            # Send actual client IP upstream
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # backend
        location ~ ^/(api|pictrs|feeds|nodeinfo|version|.well-known) {
            proxy_pass "http://lemmy";
            # proxy common stuff
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

            # Send actual client IP upstream
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}
jgrim commented 8 months ago

db

docker run \
        --name sublinks-db \
        -e MYSQL_ROOT_PASSWORD=root \
        -e MYSQL_DATABASE=sublinks \
        -e MYSQL_USER=sublinks \
        -e MYSQL_PASSWORD=sublinks \
        -p 3306:3306 \
        -d mysql:latest
lazyguru commented 8 months ago

There is already a docker-compose.yml file here in the repo

urda commented 4 months ago

Hello,

@makief01 and I will be taking a stab at this issue and are assigning it to ourselves.

urda commented 4 months ago

So far we think we have:

The idea is to just have the API Java code / project running locally and make the container fleet connect to it from docker. This allows the developer to have access to their debugger without having to setup / learn remote debugging.