From 1d0fb489c39abc18e116d7b9a6fe1f984a62d23f Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Fri, 26 Apr 2019 23:39:21 +0200 Subject: [PATCH 1/8] build: Start adding implementation --- Dockerfile.dev | 43 +++++++++++++++++++ skaffold.yaml | 13 ++++++ stack.dev.yaml | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 Dockerfile.dev create mode 100644 skaffold.yaml create mode 100644 stack.dev.yaml diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 000000000..7bf77adb7 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,43 @@ +FROM node:10-jessie +#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy' +WORKDIR /app/ui + +COPY ui/package.json ui/yarn.lock ./ +RUN yarn install --pure-lockfile # This caches your deps +COPY ui /app/ui +RUN yarn build + +FROM rust:1.33 + +# create a new empty shell project +WORKDIR /app +RUN USER=root cargo new server +WORKDIR /app/server + +# copy over your manifests +COPY server/Cargo.toml server/Cargo.lock ./ + +# this build step will cache your dependencies +RUN mkdir -p ./src/bin \ + && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs +RUN cargo build --release --bin lemmy +RUN rm -r ./target/release/.fingerprint/server-* + +# copy your source tree +# RUN rm -rf ./src/ +COPY server/src ./src/ +COPY server/migrations ./migrations/ + +# build for release +RUN cargo build --frozen --release --bin lemmy +RUN mv /app/server/target/release/lemmy /app/lemmy + +# Get diesel-cli on there just in case +# RUN cargo install diesel_cli --no-default-features --features postgres + +# The output image +# FROM debian:stable-slim +# RUN apt-get -y update && apt-get install -y postgresql-client +# COPY --from=rust /app/server/target/release/lemmy /app/lemmy +# COPY --from=0 /app/ui/dist /app/dist +EXPOSE 8536 diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 000000000..4bb4ef5d6 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,13 @@ +apiVersion: skaffold/v1beta9 +kind: Config +profiles: + - name: lemmy--dev--no-sync + build: + artifacts: + - image: registry.gitlab.com/pojntfx/lemmy/lemmy + docker: + dockerfile: Dockerfile.dev + deploy: + kubectl: + manifests: + - stack.dev.yaml diff --git a/stack.dev.yaml b/stack.dev.yaml new file mode 100644 index 000000000..e00b2fe4c --- /dev/null +++ b/stack.dev.yaml @@ -0,0 +1,113 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres +data: + POSTGRES_PASSWORD: rrr + POSTGRES_USER: rrr + POSTGRES_DB: rrr + PGDATA: /var/lib/postgresql/data/pgdata + DATABASE_URL: postgres://rrr:rrr@postgres:5432/rrr +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:11.2-alpine + resources: + limits: + memory: 128Mi + cpu: 500m + ports: + - containerPort: 5432 + envFrom: + - configMapRef: + name: postgres + volumeMounts: + - name: postgres + mountPath: /var/lib/postgresql/data + volumes: + - name: postgres + persistentVolumeClaim: + claimName: postgres +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + selector: + app: postgres + ports: + - port: 5432 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: lemmy +data: + LEMMY_FRONT_END_DIR: /app/dist +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lemmy +spec: + selector: + matchLabels: + app: lemmy + template: + metadata: + labels: + app: lemmy + spec: + containers: + - name: lemmy + command: + - /bin/sh -c /app/lemmy + envFrom: + - configMapRef: + name: lemmy + - configMapRef: + name: postgres + image: registry.gitlab.com/pojntfx/lemmy/lemmy + resources: + limits: + memory: 128Mi + cpu: 500m + ports: + - containerPort: 8536 +--- +apiVersion: v1 +kind: Service +metadata: + name: lemmy +spec: + type: NodePort + selector: + app: lemmy + ports: + - port: 8536 + nodePort: 30001 From 847e6bfb5ba92ddbdca878baebcc90a53efbf50f Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 27 Apr 2019 02:56:33 +0200 Subject: [PATCH 2/8] build: Add basic sync features and better architecture --- Dockerfile.dev | 43 --------------- README.md | 71 ++++++++++++++++++++----- server/Dockerfile.dev | 17 ++++++ stack.dev.yaml => server/stack.dev.yaml | 32 ++++++----- skaffold.yaml | 18 +++++-- ui/Dockerfile.dev | 12 +++++ ui/stack.dev.yaml | 35 ++++++++++++ 7 files changed, 153 insertions(+), 75 deletions(-) delete mode 100644 Dockerfile.dev create mode 100644 server/Dockerfile.dev rename stack.dev.yaml => server/stack.dev.yaml (77%) create mode 100644 ui/Dockerfile.dev create mode 100644 ui/stack.dev.yaml diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 7bf77adb7..000000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,43 +0,0 @@ -FROM node:10-jessie -#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy' -WORKDIR /app/ui - -COPY ui/package.json ui/yarn.lock ./ -RUN yarn install --pure-lockfile # This caches your deps -COPY ui /app/ui -RUN yarn build - -FROM rust:1.33 - -# create a new empty shell project -WORKDIR /app -RUN USER=root cargo new server -WORKDIR /app/server - -# copy over your manifests -COPY server/Cargo.toml server/Cargo.lock ./ - -# this build step will cache your dependencies -RUN mkdir -p ./src/bin \ - && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs -RUN cargo build --release --bin lemmy -RUN rm -r ./target/release/.fingerprint/server-* - -# copy your source tree -# RUN rm -rf ./src/ -COPY server/src ./src/ -COPY server/migrations ./migrations/ - -# build for release -RUN cargo build --frozen --release --bin lemmy -RUN mv /app/server/target/release/lemmy /app/lemmy - -# Get diesel-cli on there just in case -# RUN cargo install diesel_cli --no-default-features --features postgres - -# The output image -# FROM debian:stable-slim -# RUN apt-get -y update && apt-get install -y postgresql-client -# COPY --from=rust /app/server/target/release/lemmy /app/lemmy -# COPY --from=0 /app/ui/dist /app/dist -EXPOSE 8536 diff --git a/README.md b/README.md index 94238136f..33798d14a 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,16 @@ A link aggregator / reddit clone for the fediverse. -[Lemmy Dev instance](https://dev.lemmy.ml) *for testing purposes only* +[Lemmy Dev instance](https://dev.lemmy.ml) _for testing purposes only_ This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation. - -Front Page|Post ----|--- -![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png) + +| Front Page | Post | +| ----------------------------------------------- | ----------------------------------------------- | +| ![main screen](https://i.imgur.com/y64BtXC.png) | ![chat screen](https://i.imgur.com/vsOr87q.png) | ## Features + - Open source, [AGPL License](/LICENSE). - Self hostable, easy to deploy. - Comes with [docker](#docker). @@ -36,6 +37,7 @@ Front Page|Post - Front end is `~80kB` gzipped. ## About + [Lemmy](https://github.com/dessalines/lemmy) is similar to sites like [Reddit](https://reddit.com), [Lobste.rs](https://lobste.rs), [Raddle](https://raddle.me), or [Hacker News](https://news.ycombinator.com/): you subscribe to forums you're interested in, post links and discussions, then vote, and comment on them. Behind the scenes, it is very different; anyone can easily run a server, and all these servers are federated (think email), and connected to the same universe, called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse). For a link aggregator, this means a user registered on one server can subscribe to forums on any other server, and can have discussions with users registered elsewhere. @@ -45,32 +47,73 @@ The overall goal is to create an easily self-hostable, decentralized alternative Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing. ## Why's it called Lemmy? + - Lead singer from [motorhead](https://invidio.us/watch?v=pWB5JZRGl0U). -- The old school [video game](https://en.wikipedia.org/wiki/Lemmings_(video_game)). +- The old school [video game](). - The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/). Made with [Rust](https://www.rust-lang.org), [Actix](https://actix.rs/), [Inferno](https://www.infernojs.org), [Typescript](https://www.typescriptlang.org/) and [Diesel](http://diesel.rs/). -## Install -### Docker +## Usage + +### Production + +#### Docker + Make sure you have both docker and docker-compose installed. + ``` git clone https://github.com/dessalines/lemmy cd lemmy ./docker_update.sh # This pulls the newest version, builds and runs it ``` + and goto http://localhost:8536 -### Local Development -#### Requirements + + + +### Development + +#### Kubernetes + +This requires: + +- Local or remote Kubernetes Cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) +- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) +- [`skaffold`](https://skaffold.dev/) + +After satisfying the requirements, run the following: + +```bash +skaffold dev -p lemmy--dev +``` + +And goto http://localhost:4444. + +#### Non-Kubernetes + +##### Requirements + - [Rust](https://www.rust-lang.org/) - [Yarn](https://yarnpkg.com/en/) - [Postgres](https://www.sqlite.org/index.html) -#### Set up Postgres DB + +##### Set up Postgres DB + ``` psql -c "create user rrr with password 'rrr' superuser;" -U postgres psql -c 'create database rrr with owner rrr;' -U postgres ``` -#### Running + +##### Running + ``` git clone https://github.com/dessalines/lemmy cd lemmy @@ -79,15 +122,19 @@ cd lemmy # cd ui && yarn start # cd server && cargo watch -x run ``` + and goto http://localhost:8536 ## Documentation + - [ActivityPub API.md](docs/API.md) - [Goals](docs/goals.md) - [Ranking Algorithm](docs/ranking.md) ## Support + Lemmy is free, open-source software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. + - [Support on Patreon](https://www.patreon.com/dessalines). - [Sponsor List](https://dev.lemmy.ml/#/sponsors). - bitcoin: `bc1queu73nwuheqtsp65nyh5hf4jr533r8rr5nsj75` diff --git a/server/Dockerfile.dev b/server/Dockerfile.dev new file mode 100644 index 000000000..3a6f92789 --- /dev/null +++ b/server/Dockerfile.dev @@ -0,0 +1,17 @@ +# Setup env +FROM rust:1.33 +RUN mkdir -p /opt/lemmy/server--dev +WORKDIR /opt/lemmy/server--dev +# Create empty directory where the frontend would normally be +RUN mkdir -p /opt/lemmy/ui--dev/dist +# Enable deps caching +RUN mkdir -p src/bin +RUN echo 'fn main() { println!("Dummy") }' >src/bin/main.rs +# Install deps +COPY Cargo.toml . +COPY Cargo.lock . +RUN cargo build +# Add app +COPY . . +# Run app +CMD cargo run diff --git a/stack.dev.yaml b/server/stack.dev.yaml similarity index 77% rename from stack.dev.yaml rename to server/stack.dev.yaml index e00b2fe4c..9e00e4fb0 100644 --- a/stack.dev.yaml +++ b/server/stack.dev.yaml @@ -38,8 +38,8 @@ spec: image: postgres:11.2-alpine resources: limits: - memory: 128Mi - cpu: 500m + memory: 256Mi + cpu: 512m ports: - containerPort: 5432 envFrom: @@ -66,48 +66,46 @@ spec: apiVersion: v1 kind: ConfigMap metadata: - name: lemmy + name: lemmy-server--dev data: - LEMMY_FRONT_END_DIR: /app/dist + LEMMY_FRONT_END_DIR: /opt/lemmy/ui--dev/dist # not actually used here, polyfill for monolith --- apiVersion: apps/v1 kind: Deployment metadata: - name: lemmy + name: lemmy-server--dev spec: selector: matchLabels: - app: lemmy + app: lemmy-server--dev template: metadata: labels: - app: lemmy + app: lemmy-server--dev spec: containers: - - name: lemmy - command: - - /bin/sh -c /app/lemmy + - name: lemmy-server--dev + image: registry.gitlab.com/pojntfx/lemmy/server.dev envFrom: - - configMapRef: - name: lemmy - configMapRef: name: postgres - image: registry.gitlab.com/pojntfx/lemmy/lemmy + - configMapRef: + name: lemmy-server--dev resources: limits: - memory: 128Mi - cpu: 500m + memory: 256Mi + cpu: 256m ports: - containerPort: 8536 --- apiVersion: v1 kind: Service metadata: - name: lemmy + name: lemmy-server--dev spec: type: NodePort selector: - app: lemmy + app: lemmy-server--dev ports: - port: 8536 nodePort: 30001 diff --git a/skaffold.yaml b/skaffold.yaml index 4bb4ef5d6..d8ab281ba 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -1,13 +1,25 @@ apiVersion: skaffold/v1beta9 kind: Config profiles: - - name: lemmy--dev--no-sync + - name: lemmy--dev build: artifacts: - - image: registry.gitlab.com/pojntfx/lemmy/lemmy + - image: registry.gitlab.com/pojntfx/lemmy/server.dev + context: server docker: dockerfile: Dockerfile.dev + sync: + "**/*.rs": src/ + - image: registry.gitlab.com/pojntfx/lemmy/ui.dev + context: ui + docker: + dockerfile: Dockerfile.dev + sync: + "**/*.ts": src/ + "**/*.tsx": src/ + "**/*.css": src/ deploy: kubectl: manifests: - - stack.dev.yaml + - server/stack.dev.yaml + - ui/stack.dev.yaml diff --git a/ui/Dockerfile.dev b/ui/Dockerfile.dev new file mode 100644 index 000000000..84ebbcadc --- /dev/null +++ b/ui/Dockerfile.dev @@ -0,0 +1,12 @@ +# Setup env +FROM node:10 +RUN mkdir -p /opt/lemmy/ui--dev +WORKDIR /opt/lemmy/ui--dev +# Install deps +COPY package.json . +COPY yarn.lock . +RUN npm install +# Add app +COPY . . +# Run app +CMD npm start diff --git a/ui/stack.dev.yaml b/ui/stack.dev.yaml new file mode 100644 index 000000000..bb7c62e85 --- /dev/null +++ b/ui/stack.dev.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lemmy-ui--dev +spec: + selector: + matchLabels: + app: lemmy-ui--dev + template: + metadata: + labels: + app: lemmy-ui--dev + spec: + containers: + - name: lemmy-ui--dev + image: registry.gitlab.com/pojntfx/lemmy/ui.dev + resources: + limits: + memory: 1024Mi + cpu: 512m + ports: + - containerPort: 4444 +--- +apiVersion: v1 +kind: Service +metadata: + name: lemmy-ui--dev +spec: + type: NodePort + selector: + app: lemmy-ui--dev + ports: + - port: 4444 + nodePort: 30002 From beb4981c22462f4d671fe1098320ff32e1f1c271 Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 27 Apr 2019 03:39:06 +0200 Subject: [PATCH 3/8] build: Fix hot reloading of UI, improve docs --- README.md | 10 ++++++---- server/stack.dev.yaml | 4 ++-- skaffold.yaml | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 33798d14a..cdd8c34c7 100644 --- a/README.md +++ b/README.md @@ -83,19 +83,21 @@ skaffold run -p lemmy--prod #### Kubernetes -This requires: +##### Requirements -- Local or remote Kubernetes Cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) +- Local or remote Kubernetes cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) - [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - [`skaffold`](https://skaffold.dev/) -After satisfying the requirements, run the following: +##### Running ```bash skaffold dev -p lemmy--dev ``` -And goto http://localhost:4444. +And goto http://localhost:4444 (automatically proxies to localhost, both if the cluster is local or remote). + +It hot-reloads the UI and automatically recompiles the server. #### Non-Kubernetes diff --git a/server/stack.dev.yaml b/server/stack.dev.yaml index 9e00e4fb0..7c6905b3b 100644 --- a/server/stack.dev.yaml +++ b/server/stack.dev.yaml @@ -93,8 +93,8 @@ spec: name: lemmy-server--dev resources: limits: - memory: 256Mi - cpu: 256m + memory: 512Mi + cpu: 512m ports: - containerPort: 8536 --- diff --git a/skaffold.yaml b/skaffold.yaml index d8ab281ba..88b7a0de8 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -9,15 +9,15 @@ profiles: docker: dockerfile: Dockerfile.dev sync: - "**/*.rs": src/ + "***/*.rs": . - image: registry.gitlab.com/pojntfx/lemmy/ui.dev context: ui docker: dockerfile: Dockerfile.dev sync: - "**/*.ts": src/ - "**/*.tsx": src/ - "**/*.css": src/ + "***/*.ts": . + "***/*.tsx": . + "***/*.css": . deploy: kubectl: manifests: From 74db51c6cdb0f9ca1353c76318f4ef3668272e2d Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 27 Apr 2019 10:51:08 +0200 Subject: [PATCH 4/8] build: Improve server compile time with cache --- README.md | 8 ++++---- server/Dockerfile.dev | 12 ++++++++---- skaffold.yaml | 2 -- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cdd8c34c7..8e3db3857 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ A link aggregator / reddit clone for the fediverse. -[Lemmy Dev instance](https://dev.lemmy.ml) _for testing purposes only_ +[Lemmy Dev instance](https://dev.lemmy.ml) *for testing purposes only* This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation. -| Front Page | Post | -| ----------------------------------------------- | ----------------------------------------------- | -| ![main screen](https://i.imgur.com/y64BtXC.png) | ![chat screen](https://i.imgur.com/vsOr87q.png) | +|Front Page|Post| +|-----------------------------------------------|----------------------------------------------- | +|![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png) | ## Features diff --git a/server/Dockerfile.dev b/server/Dockerfile.dev index 3a6f92789..c7951ce84 100644 --- a/server/Dockerfile.dev +++ b/server/Dockerfile.dev @@ -1,6 +1,6 @@ # Setup env FROM rust:1.33 -RUN mkdir -p /opt/lemmy/server--dev +RUN USER=root cargo new --bin /opt/lemmy/server--dev WORKDIR /opt/lemmy/server--dev # Create empty directory where the frontend would normally be RUN mkdir -p /opt/lemmy/ui--dev/dist @@ -10,8 +10,12 @@ RUN echo 'fn main() { println!("Dummy") }' >src/bin/main.rs # Install deps COPY Cargo.toml . COPY Cargo.lock . -RUN cargo build +RUN cargo build --release +RUN rm src/bin/main.rs # Add app -COPY . . +COPY src/ src/ +COPY migrations/ migrations/ +RUN rm target/release/deps/lemmy* +RUN cargo build --release # Run app -CMD cargo run +CMD ["/opt/lemmy/server--dev/target/release/lemmy"] diff --git a/skaffold.yaml b/skaffold.yaml index 88b7a0de8..9d1d3cd7d 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -8,8 +8,6 @@ profiles: context: server docker: dockerfile: Dockerfile.dev - sync: - "***/*.rs": . - image: registry.gitlab.com/pojntfx/lemmy/ui.dev context: ui docker: From c83f98ed5ca1eb4d7971a78a1b44eac069a72764 Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 27 Apr 2019 15:49:50 +0200 Subject: [PATCH 5/8] build: Minimize build time with multi-stage build, add Ingress and production versions --- README.md | 82 +++++++++++++++--------------- server/Dockerfile.dev | 15 ++++-- server/Dockerfile.prod | 28 +++++++++++ server/stack.prod.yaml | 110 +++++++++++++++++++++++++++++++++++++++++ skaffold.yaml | 18 ++++++- ui/Dockerfile.dev | 4 +- ui/Dockerfile.prod | 22 +++++++++ ui/stack.prod.yaml | 54 ++++++++++++++++++++ 8 files changed, 285 insertions(+), 48 deletions(-) create mode 100644 server/Dockerfile.prod create mode 100644 server/stack.prod.yaml create mode 100644 ui/Dockerfile.prod create mode 100644 ui/stack.prod.yaml diff --git a/README.md b/README.md index 8e3db3857..8b7999a54 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,20 @@ A link aggregator / reddit clone for the fediverse. -[Lemmy Dev instance](https://dev.lemmy.ml) *for testing purposes only* +[Lemmy Dev instance](https://dev.lemmy.ml) _for testing purposes only_ This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation. -|Front Page|Post| -|-----------------------------------------------|----------------------------------------------- | -|![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png) | +| Front Page | Post | +| ----------------------------------------------- | ----------------------------------------------- | +| ![main screen](https://i.imgur.com/y64BtXC.png) | ![chat screen](https://i.imgur.com/vsOr87q.png) | ## Features - Open source, [AGPL License](/LICENSE). - Self hostable, easy to deploy. - - Comes with [docker](#docker). + - Comes with [Kubernetes](#kubernetes) + - Comes with [Docker](#docker). - Live-updating Comment threads. - Full vote scores `(+/-)` like old reddit. - Moderation abilities. @@ -56,9 +57,39 @@ Made with [Rust](https://www.rust-lang.org), [Actix](https://actix.rs/), [Infern ## Usage -### Production +### Kubernetes -#### Docker +#### Requirements + +- Local or remote Kubernetes cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) +- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) +- [`skaffold`](https://skaffold.dev/) + +#### Production + +```bash +# Deploy the Traefik Ingress +kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml +kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml +# Replace ${IP} with your Ingress' IP +echo "${IP} dev.lemmy.local" >> /etc/hosts +``` + +```bash +skaffold run -p lemmy--prod +``` + +Now go to http://dev.lemmy.local. + +#### Development + +```bash +skaffold dev -p lemmy--dev +``` + +Now go to http://localhost:4444. It automatically proxies to localhost, both if the cluster is local or remote; it also hot-reloads the UI and automatically recompiles and restarts the server. + +### Docker Make sure you have both docker and docker-compose installed. @@ -70,51 +101,22 @@ cd lemmy and goto http://localhost:8536 - - -### Development - -#### Kubernetes - -##### Requirements - -- Local or remote Kubernetes cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) -- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) -- [`skaffold`](https://skaffold.dev/) - -##### Running - -```bash -skaffold dev -p lemmy--dev -``` - -And goto http://localhost:4444 (automatically proxies to localhost, both if the cluster is local or remote). - -It hot-reloads the UI and automatically recompiles the server. - -#### Non-Kubernetes - -##### Requirements +#### Requirements - [Rust](https://www.rust-lang.org/) - [Yarn](https://yarnpkg.com/en/) - [Postgres](https://www.sqlite.org/index.html) -##### Set up Postgres DB +#### Set up Postgres DB ``` psql -c "create user rrr with password 'rrr' superuser;" -U postgres psql -c 'create database rrr with owner rrr;' -U postgres ``` -##### Running +#### Running ``` git clone https://github.com/dessalines/lemmy diff --git a/server/Dockerfile.dev b/server/Dockerfile.dev index c7951ce84..203dd7424 100644 --- a/server/Dockerfile.dev +++ b/server/Dockerfile.dev @@ -1,9 +1,7 @@ # Setup env -FROM rust:1.33 +FROM rust:1.33 AS build RUN USER=root cargo new --bin /opt/lemmy/server--dev WORKDIR /opt/lemmy/server--dev -# Create empty directory where the frontend would normally be -RUN mkdir -p /opt/lemmy/ui--dev/dist # Enable deps caching RUN mkdir -p src/bin RUN echo 'fn main() { println!("Dummy") }' >src/bin/main.rs @@ -17,5 +15,14 @@ COPY src/ src/ COPY migrations/ migrations/ RUN rm target/release/deps/lemmy* RUN cargo build --release + +# Setup env (no Alpine because Rust requires glibc) +FROM ubuntu:18.04 +RUN apt update +RUN apt install postgresql-client -y +# Create empty directory where the frontend would normally be +RUN mkdir -p /opt/lemmy/ui--dev/dist +# Add app +COPY --from=build /opt/lemmy/server--dev/target/release/lemmy . # Run app -CMD ["/opt/lemmy/server--dev/target/release/lemmy"] +CMD ["./lemmy"] diff --git a/server/Dockerfile.prod b/server/Dockerfile.prod new file mode 100644 index 000000000..b375e4781 --- /dev/null +++ b/server/Dockerfile.prod @@ -0,0 +1,28 @@ +# Setup env +FROM rust:1.33 AS build +RUN USER=root cargo new --bin /opt/lemmy/server--prod +WORKDIR /opt/lemmy/server--prod +# Enable deps caching +RUN mkdir -p src/bin +RUN echo 'fn main() { println!("Dummy") }' >src/bin/main.rs +# Install deps +COPY Cargo.toml . +COPY Cargo.lock . +RUN cargo build --release +RUN rm src/bin/main.rs +# Add app +COPY src/ src/ +COPY migrations/ migrations/ +RUN rm target/release/deps/lemmy* +RUN cargo build --release + +# Setup env (no Alpine because Rust requires glibc) +FROM ubuntu:18.04 +RUN apt update +RUN apt install postgresql-client -y +# Create empty directory where the frontend would normally be +RUN mkdir -p /opt/lemmy/ui--prod/dist +# Add app +COPY --from=build /opt/lemmy/server--prod/target/release/lemmy . +# Run app +CMD ["./lemmy"] diff --git a/server/stack.prod.yaml b/server/stack.prod.yaml new file mode 100644 index 000000000..d221de163 --- /dev/null +++ b/server/stack.prod.yaml @@ -0,0 +1,110 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres +data: + POSTGRES_PASSWORD: rrr + POSTGRES_USER: rrr + POSTGRES_DB: rrr + PGDATA: /var/lib/postgresql/data/pgdata + DATABASE_URL: postgres://rrr:rrr@postgres:5432/rrr +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:11.2-alpine + resources: + limits: + memory: 256Mi + cpu: 512m + ports: + - containerPort: 5432 + envFrom: + - configMapRef: + name: postgres + volumeMounts: + - name: postgres + mountPath: /var/lib/postgresql/data + volumes: + - name: postgres + persistentVolumeClaim: + claimName: postgres +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + selector: + app: postgres + ports: + - port: 5432 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: lemmy-server--prod +data: + LEMMY_FRONT_END_DIR: /opt/lemmy/ui--prod/dist # not actually used here, polyfill for monolith +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lemmy-server--prod +spec: + selector: + matchLabels: + app: lemmy-server--prod + template: + metadata: + labels: + app: lemmy-server--prod + spec: + containers: + - name: lemmy-server--prod + image: registry.gitlab.com/pojntfx/lemmy/server.prod + envFrom: + - configMapRef: + name: postgres + - configMapRef: + name: lemmy-server--prod + resources: + limits: + memory: 512Mi + cpu: 512m + ports: + - containerPort: 8536 +--- +apiVersion: v1 +kind: Service +metadata: + name: lemmy-server--prod +spec: + selector: + app: lemmy-server--prod + ports: + - port: 8536 + targetPort: 8536 diff --git a/skaffold.yaml b/skaffold.yaml index 9d1d3cd7d..9aeaa5859 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -19,5 +19,19 @@ profiles: deploy: kubectl: manifests: - - server/stack.dev.yaml - - ui/stack.dev.yaml + - "**/*.dev.yaml" + - name: lemmy--prod + build: + artifacts: + - image: registry.gitlab.com/pojntfx/lemmy/server.prod + context: server + docker: + dockerfile: Dockerfile.prod + - image: registry.gitlab.com/pojntfx/lemmy/ui.prod + context: ui + docker: + dockerfile: Dockerfile.prod + deploy: + kubectl: + manifests: + - "**/*.prod.yaml" diff --git a/ui/Dockerfile.dev b/ui/Dockerfile.dev index 84ebbcadc..37f9e34c7 100644 --- a/ui/Dockerfile.dev +++ b/ui/Dockerfile.dev @@ -1,5 +1,5 @@ # Setup env -FROM node:10 +FROM node:10-alpine RUN mkdir -p /opt/lemmy/ui--dev WORKDIR /opt/lemmy/ui--dev # Install deps @@ -9,4 +9,4 @@ RUN npm install # Add app COPY . . # Run app -CMD npm start +CMD ["npm", "start"] diff --git a/ui/Dockerfile.prod b/ui/Dockerfile.prod new file mode 100644 index 000000000..9c478e67a --- /dev/null +++ b/ui/Dockerfile.prod @@ -0,0 +1,22 @@ +# Setup env +FROM node:10-alpine AS build +RUN mkdir -p /opt/lemmy/ui--prod +WORKDIR /opt/lemmy/ui--prod +# Install deps +COPY package.json . +COPY yarn.lock . +RUN npm install +# Add app +COPY . . +# Build app +RUN npm run build + +# Setup env +FROM node:10-alpine +RUN mkdir -p /opt/lemmy/ui--prod +WORKDIR /opt/lemmy/ui--prod +RUN npm install serve +# Add app +COPY --from=build /opt/lemmy/ui--prod/dist . +# Run app +CMD ["/opt/lemmy/ui--prod/node_modules/.bin/serve", "."] diff --git a/ui/stack.prod.yaml b/ui/stack.prod.yaml new file mode 100644 index 000000000..85ac6f6bf --- /dev/null +++ b/ui/stack.prod.yaml @@ -0,0 +1,54 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lemmy-ui--prod +spec: + selector: + matchLabels: + app: lemmy-ui--prod + template: + metadata: + labels: + app: lemmy-ui--prod + spec: + containers: + - name: lemmy-ui--prod + image: registry.gitlab.com/pojntfx/lemmy/ui.prod + resources: + limits: + memory: 1024Mi + cpu: 512m + ports: + - containerPort: 4444 +--- +apiVersion: v1 +kind: Service +metadata: + name: lemmy-ui--prod +spec: + selector: + app: lemmy-ui--prod + ports: + - port: 5000 + targetPort: 5000 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: lemmy-server--prod + annotations: + traefik.ingress.kubernetes.io/request-modifier: "ReplacePathRegex: ^/static/(.*) /$1" +spec: + rules: + - host: dev.lemmy.local + http: + paths: + - path: / + backend: + serviceName: lemmy-ui--prod + servicePort: 5000 + - path: /service/ws + backend: + serviceName: lemmy-server--prod + servicePort: 8536 From 16b618c214a85cf54d7493c8b2b4684212cbb68c Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 27 Apr 2019 15:55:12 +0200 Subject: [PATCH 6/8] chore: Formatting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b7999a54..e56e86804 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ A link aggregator / reddit clone for the fediverse. -[Lemmy Dev instance](https://dev.lemmy.ml) _for testing purposes only_ +[Lemmy Dev instance](https://dev.lemmy.ml) *for testing purposes only* This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation. -| Front Page | Post | -| ----------------------------------------------- | ----------------------------------------------- | -| ![main screen](https://i.imgur.com/y64BtXC.png) | ![chat screen](https://i.imgur.com/vsOr87q.png) | +|Front Page|Post| +|-|-| +|![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png)| ## Features From cf4a7e42e2a3bd32b9168a67a743cfb724d91b9e Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Sat, 4 May 2019 14:25:01 +0200 Subject: [PATCH 7/8] chore: Remove newlines from headings in README --- README.md | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/README.md b/README.md index 061621cef..a2219441e 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,7 @@ This is a **very early beta version**, and a lot of features are currently broke |Front Page|Post| |-|-| |![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png)| - ## Features - - Open source, [AGPL License](/LICENSE). - Self hostable, easy to deploy. - Comes with [Kubernetes](#kubernetes) @@ -36,9 +34,7 @@ This is a **very early beta version**, and a lot of features are currently broke - High performance. - Server is written in rust. - Front end is `~80kB` gzipped. - ## About - [Lemmy](https://github.com/dessalines/lemmy) is similar to sites like [Reddit](https://reddit.com), [Lobste.rs](https://lobste.rs), [Raddle](https://raddle.me), or [Hacker News](https://news.ycombinator.com/): you subscribe to forums you're interested in, post links and discussions, then vote, and comment on them. Behind the scenes, it is very different; anyone can easily run a server, and all these servers are federated (think email), and connected to the same universe, called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse). For a link aggregator, this means a user registered on one server can subscribe to forums on any other server, and can have discussions with users registered elsewhere. @@ -46,28 +42,20 @@ For a link aggregator, this means a user registered on one server can subscribe The overall goal is to create an easily self-hostable, decentralized alternative to reddit and other link aggregators, outside of their corporate control and meddling. Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing. - ## Why's it called Lemmy? - - Lead singer from [motorhead](https://invidio.us/watch?v=pWB5JZRGl0U). - The old school [video game](). - The [Koopa from Super Mario](https://www.mariowiki.com/Lemmy_Koopa). - The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/). Made with [Rust](https://www.rust-lang.org), [Actix](https://actix.rs/), [Inferno](https://www.infernojs.org), [Typescript](https://www.typescriptlang.org/) and [Diesel](http://diesel.rs/). - ## Usage - ### Kubernetes - #### Requirements - - Local or remote Kubernetes cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) - [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - [`skaffold`](https://skaffold.dev/) - #### Production - ```bash # Deploy the Traefik Ingress kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml @@ -81,17 +69,13 @@ skaffold run -p lemmy--prod ``` Now go to http://dev.lemmy.local. - #### Development - ```bash skaffold dev -p lemmy--dev ``` Now go to http://localhost:4444. It automatically proxies to localhost, both if the cluster is local or remote; it also hot-reloads the UI and automatically recompiles and restarts the server. - ### Docker - Make sure you have both docker and docker-compose installed. ``` @@ -101,24 +85,17 @@ cd lemmy ``` and goto http://localhost:8536 - ### Native - #### Requirements - - [Rust](https://www.rust-lang.org/) - [Yarn](https://yarnpkg.com/en/) - [Postgres](https://www.sqlite.org/index.html) - #### Set up Postgres DB - ``` psql -c "create user rrr with password 'rrr' superuser;" -U postgres psql -c 'create database rrr with owner rrr;' -U postgres ``` - #### Running - ``` git clone https://github.com/dessalines/lemmy cd lemmy @@ -129,22 +106,16 @@ cd lemmy ``` and goto http://localhost:8536 - ## Documentation - - [ActivityPub API.md](docs/API.md) - [Goals](docs/goals.md) - [Ranking Algorithm](docs/ranking.md) - ## Support - Lemmy is free, open-source software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. - [Support on Patreon](https://www.patreon.com/dessalines). - [Sponsor List](https://dev.lemmy.ml/#/sponsors). - bitcoin: `bc1queu73nwuheqtsp65nyh5hf4jr533r8rr5nsj75` - ethereum: `0x400c96c96acbC6E7B3B43B1dc1BB446540a88A01` - ## Credits - Icons made by [Freepik](https://www.freepik.com/) licensed by [CC 3.0](http://creativecommons.org/licenses/by/3.0/) From b6bad989991f8b155f7765860344d1658ad166f5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 4 May 2019 08:58:53 -0700 Subject: [PATCH 8/8] Fixes to readme. --- README.md | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a2219441e..5ebb969d6 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,13 @@ A link aggregator / reddit clone for the fediverse. This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation. -|Front Page|Post| -|-|-| -|![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png)| +Front Page|Post +---|--- +![main screen](https://i.imgur.com/y64BtXC.png)|![chat screen](https://i.imgur.com/vsOr87q.png) ## Features - Open source, [AGPL License](/LICENSE). - Self hostable, easy to deploy. - - Comes with [Kubernetes](#kubernetes) - - Comes with [Docker](#docker). + - Comes with [Docker](#docker), [Kubernetes](#kubernetes). - Live-updating Comment threads. - Full vote scores `(+/-)` like old reddit. - Moderation abilities. @@ -42,6 +41,7 @@ For a link aggregator, this means a user registered on one server can subscribe The overall goal is to create an easily self-hostable, decentralized alternative to reddit and other link aggregators, outside of their corporate control and meddling. Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing. + ## Why's it called Lemmy? - Lead singer from [motorhead](https://invidio.us/watch?v=pWB5JZRGl0U). - The old school [video game](). @@ -49,7 +49,17 @@ Each lemmy server can set its own moderation policy; appointing site-wide admins - The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/). Made with [Rust](https://www.rust-lang.org), [Actix](https://actix.rs/), [Inferno](https://www.infernojs.org), [Typescript](https://www.typescriptlang.org/) and [Diesel](http://diesel.rs/). -## Usage +## Install +### Docker +Make sure you have both docker and docker-compose installed. + +``` +git clone https://github.com/dessalines/lemmy +cd lemmy +./docker_update.sh # This pulls the newest version, builds and runs it +``` + +and goto http://localhost:8536 ### Kubernetes #### Requirements - Local or remote Kubernetes cluster, i.e. [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) @@ -75,17 +85,7 @@ skaffold dev -p lemmy--dev ``` Now go to http://localhost:4444. It automatically proxies to localhost, both if the cluster is local or remote; it also hot-reloads the UI and automatically recompiles and restarts the server. -### Docker -Make sure you have both docker and docker-compose installed. - -``` -git clone https://github.com/dessalines/lemmy -cd lemmy -./docker_update.sh # This pulls the newest version, builds and runs it -``` - -and goto http://localhost:8536 -### Native +### Local Development #### Requirements - [Rust](https://www.rust-lang.org/) - [Yarn](https://yarnpkg.com/en/) @@ -112,7 +112,6 @@ and goto http://localhost:8536 - [Ranking Algorithm](docs/ranking.md) ## Support Lemmy is free, open-source software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. - - [Support on Patreon](https://www.patreon.com/dessalines). - [Sponsor List](https://dev.lemmy.ml/#/sponsors). - bitcoin: `bc1queu73nwuheqtsp65nyh5hf4jr533r8rr5nsj75`