]> Untitled Git - lemmy.git/commitdiff
build: Add basic sync features and better architecture
authorFelix Pojtinger <felix@pojtinger.com>
Sat, 27 Apr 2019 00:56:33 +0000 (02:56 +0200)
committerFelix Pojtinger <felix@pojtinger.com>
Sat, 27 Apr 2019 00:56:33 +0000 (02:56 +0200)
Dockerfile.dev [deleted file]
README.md
server/Dockerfile.dev [new file with mode: 0644]
server/stack.dev.yaml [moved from stack.dev.yaml with 77% similarity]
skaffold.yaml
ui/Dockerfile.dev [new file with mode: 0644]
ui/stack.dev.yaml [new file with mode: 0644]

diff --git a/Dockerfile.dev b/Dockerfile.dev
deleted file mode 100644 (file)
index 7bf77ad..0000000
+++ /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
index 94238136f2caea60b5b42f73c97dd01eaffd5a91..33798d14a9cff5dd3da496c49cfa67eefd4a60bd 100644 (file)
--- a/README.md
+++ b/README.md
 
 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](<https://en.wikipedia.org/wiki/Lemmings_(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
+
+<!-- #### Kubernetes (WIP)
+
+> TODO: Add production version with proper proxy setup and Ingress for WebSockets
+
+```bash
+skaffold run -p lemmy--prod
+# Now go to http://${IP}:30002
+``` -->
+
+### 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 (file)
index 0000000..3a6f927
--- /dev/null
@@ -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
similarity index 77%
rename from stack.dev.yaml
rename to server/stack.dev.yaml
index e00b2fe4c1191b2e47f12455c5daccd1ab5fb41c..9e00e4fb0f488c51f9a5e8a2b1bde71a05f4f1fd 100644 (file)
@@ -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
index 4bb4ef5d6fc4a5dca1ba358b00aab73cce507be7..d8ab281ba97453345de6be2677ac84c7e1fbb902 100644 (file)
@@ -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 (file)
index 0000000..84ebbca
--- /dev/null
@@ -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 (file)
index 0000000..bb7c62e
--- /dev/null
@@ -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