Skip to content

Commit

Permalink
Isomorphic docker (#1124)
Browse files Browse the repository at this point in the history
* Adding a way to GetComments for a community given its name only.

* Adding getcomments to api docs.

* A first pass at locally working isomorphic integration.

* Testing out cargo-husky.

* Testing a fail hook.

* Revert "Testing a fail hook."

This reverts commit 0941cf1.

* Moving server to top level, now that UI is gone.

* Running cargo fmt using old way.

* Adding nginx, fixing up docker-compose files, fixing docs.

* Trying to re-add API tests.

* Fixing prod dockerfile.

* Redoing nightly fmt

* Trying to fix private message api test.

* Adding CommunityJoin, PostJoin instead of joins from GetComments, etc.

- Fixes #1122

* Fixing fmt.

* Fixing up docs.

* Removing translations.

* Adding apps / clients to readme.

* Fixing main image.

* Using new lemmy-isomorphic-ui with better javascript disabled.

* Try to fix image uploads in federation test

* Revert "Try to fix image uploads in federation test"

This reverts commit a2ddf2a.

* Fix post url federation

* Adding some more tests, some still broken.

* Don't need gitattributes anymore.

* Update local federation test setup

* Fixing tests.

* Fixing travis build.

* Fixing travis build, again.

* Changing lemmy-isomorphic-ui to lemmy-ui

* Error in travis build again.

Co-authored-by: Felix Ableitner <me@nutomic.com>
  • Loading branch information
dessalines and Nutomic authored Sep 15, 2020
1 parent b69524b commit 5c62583
Show file tree
Hide file tree
Showing 372 changed files with 4,369 additions and 34,787 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

19 changes: 10 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ ansible/passwords/
# docker build files
docker/lemmy_mine.hjson
docker/dev/env_deploy.sh
docker/federation/volumes
docker/federation-test/volumes
docker/dev/volumes

# local build files
build/
ui/src/translations
volumes

# ide config
.idea/
.vscode/
.idea
.vscode

# local build files
target
env_setup.sh
query_testing/*.json
query_testing/*.json.old

# API tests
api_tests/node_modules
File renamed without changes.
7 changes: 7 additions & 0 deletions server/Cargo.lock → Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions server/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ anyhow = "1.0.32"
thiserror = "1.0.20"
background-jobs = " 0.8.0-alpha.2"
reqwest = { version = "0.10", features = ["json"] }

[dev-dependencies.cargo-husky]
version = "1"
default-features = false # Disable features which are enabled by default
features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<p align="center">
<a href="https://dev.lemmy.ml/" rel="noopener">
<img width=200px height=200px src="ui/assets/favicon.svg"></a>
<img width=200px height=200px src="https://raw.githubusercontent.com/LemmyNet/lemmy-ui/main/src/assets/icons/favicon.svg"></a>

<h3 align="center"><a href="https://dev.lemmy.ml">Lemmy</a></h3>
<p align="center">
Expand Down Expand Up @@ -108,12 +108,15 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins

### Apps

- [lemmy-ui - The official web app for lemmy](https://github.com/LemmyNet/lemmy-ui)
- [Lemmur - A flutter lemmy app ( under development )](https://github.com/krawieck/lemmur)
- [Lemmy-mobile (Android / IOS) - React native ( under development )](https://github.com/koredefashokun/lemmy-mobile)

### Libraries

- [lemmy-js-client](https://github.com/LemmyNet/lemmy-js-client)
- [Kotlin API ( under development )](https://github.com/eiknat/lemmy-client)
- [Dart API client ( under development )](https://github.com/krawieck/lemmy_api_client)

## Support / Donate

Expand Down
2 changes: 0 additions & 2 deletions ansible/templates/config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
hostname: "{{ domain }}"
# json web token for authorization between server and client
jwt_secret: "{{ jwt_password }}"
# The location of the frontend
front_end_dir: "/app/dist"
# email sending configuration
email: {
# hostname of the smtp server
Expand Down
50 changes: 34 additions & 16 deletions ansible/templates/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,41 @@ server {
# Upload limit for pictrs
client_max_body_size 20M;

# lemmy api
location /api/v1 {
proxy_pass http://0.0.0.0:8536/api/v1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Cuts off the trailing slash on URLs to make them valid
rewrite ^(.+)/+$ $1 permanent;

# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# Rate limit
limit_req zone=lemmy_ratelimit burst=30 nodelay;
}

# Docs
location /docs {
proxy_pass http://0.0.0.0:8536/docs;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# lemmy-ui
location / {
proxy_pass http://0.0.0.0:8536;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Cuts off the trailing slash on URLs to make them valid
rewrite ^(.+)/+$ $1 permanent;

# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# Rate limit
limit_req zone=lemmy_ratelimit burst=30 nodelay;
}
proxy_pass http://0.0.0.0:1235;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}


# Redirect pictshare images to pictrs
location ~ /pictshare/(.*)$ {
Expand Down
4 changes: 4 additions & 0 deletions api_tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
20 changes: 20 additions & 0 deletions api_tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "api_tests",
"version": "0.0.1",
"description": "API tests for lemmy backend",
"main": "index.js",
"repository": "https://github.com/LemmyNet/lemmy",
"author": "Dessalines",
"license": "AGPL-3.0",
"scripts": {
"api-test": "jest src/ -i --verbose"
},
"devDependencies": {
"@types/jest": "^26.0.13",
"jest": "^26.4.2",
"lemmy-js-client": "^1.0.11",
"node-fetch": "^2.6.1",
"ts-jest": "^26.3.0",
"typescript": "^4.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ test('Reply to a comment', async () => {

test('Mention beta', async () => {
// Create a mention on alpha
let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8551';
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let mentionRes = await createComment(
Expand Down Expand Up @@ -275,7 +275,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
let gammaPost = search.posts[0];

let commentContent =
'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8550';
'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551';
let commentRes = await createComment(
gamma,
gammaPost.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
jest.setTimeout(120000);
import {
alpha,
beta,
setupLogins,
searchForBetaCommunity,
searchForCommunity,
createCommunity,
deleteCommunity,
removeCommunity,
Expand All @@ -21,6 +23,17 @@ test('Create community', async () => {
let prevName = communityRes.community.name;
let communityRes2 = await createCommunity(alpha, prevName);
expect(communityRes2['error']).toBe('community_already_exists');
await delay();

// Cache the community on beta, make sure it has the other fields
let searchShort = `!${prevName}@lemmy-alpha:8541`;
let search = await searchForCommunity(beta, searchShort);
let communityOnBeta = search.communities[0];
expect(communityOnBeta.name).toBe(communityRes.community.name);
expect(communityOnBeta.title).toBe(communityRes.community.title);
expect(communityOnBeta.description).toBe(communityRes.community.description);
expect(communityOnBeta.icon).toBe(communityRes.community.icon);
expect(communityOnBeta.banner).toBe(communityRes.community.banner);
});

test('Delete community', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.setTimeout(120000);
import {
alpha,
setupLogins,
Expand Down
4 changes: 4 additions & 0 deletions ui/src/api_tests/post.spec.ts → api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ test('Create a post', async () => {
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(1);
expect(betaPost.name).toBe(postRes.post.name);
expect(betaPost.body).toBe(postRes.post.body);
expect(betaPost.url).toBe(postRes.post.url);
expect(betaPost.nsfw).toBe(postRes.post.nsfw);

// Delta only follows beta, so it should not see an alpha ap_id
let searchDelta = await searchPost(delta, postRes.post);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.setTimeout(120000);
import {
alpha,
beta,
Expand Down
35 changes: 29 additions & 6 deletions ui/src/api_tests/shared.ts → api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ export interface API {
}

export let alpha: API = {
client: new LemmyHttp('http://localhost:8540/api/v1'),
client: new LemmyHttp('http://localhost:8541/api/v1'),
};

export let beta: API = {
client: new LemmyHttp('http://localhost:8550/api/v1'),
client: new LemmyHttp('http://localhost:8551/api/v1'),
};

export let gamma: API = {
client: new LemmyHttp('http://localhost:8560/api/v1'),
client: new LemmyHttp('http://localhost:8561/api/v1'),
};

export let delta: API = {
client: new LemmyHttp('http://localhost:8570/api/v1'),
client: new LemmyHttp('http://localhost:8571/api/v1'),
};

export let epsilon: API = {
client: new LemmyHttp('http://localhost:8580/api/v1'),
client: new LemmyHttp('http://localhost:8581/api/v1'),
};

export async function setupLogins() {
Expand Down Expand Up @@ -120,8 +120,12 @@ export async function createPost(
community_id: number
): Promise<PostResponse> {
let name = 'A jest test post';
let body = 'Some body';
let url = 'https://google.com/';
let form: PostForm = {
name,
url,
body,
auth: api.auth,
community_id,
nsfw: false,
Expand Down Expand Up @@ -232,7 +236,20 @@ export async function searchForBetaCommunity(
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
let form: SearchForm = {
q: '!main@lemmy-beta:8550',
q: '!main@lemmy-beta:8551',
type_: SearchType.Communities,
sort: SortType.TopAll,
};
return api.client.search(form);
}

export async function searchForCommunity(
api: API,
q: string,
): Promise<SearchResponse> {
// Use short-hand search url
let form: SearchForm = {
q,
type_: SearchType.Communities,
sort: SortType.TopAll,
};
Expand Down Expand Up @@ -369,9 +386,15 @@ export async function createCommunity(
api: API,
name_: string = randomString(5)
): Promise<CommunityResponse> {
let description = 'a sample description';
let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let form: CommunityForm = {
name: name_,
title: name_,
description,
icon,
banner,
category_id: 1,
nsfw: false,
auth: api.auth,
Expand Down
3 changes: 2 additions & 1 deletion ui/src/api_tests/user.spec.ts → api_tests/src/user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.setTimeout(120000);
import {
alpha,
beta,
Expand All @@ -17,7 +18,7 @@ test('Create user', async () => {

let site = await getSite(alpha, auth);
expect(site.my_user).toBeDefined();
apShortname = `@${site.my_user.name}@lemmy-alpha:8540`;
apShortname = `@${site.my_user.name}@lemmy-alpha:8541`;
});

test('Save user settings, check changed bio from beta', async () => {
Expand Down
Loading

0 comments on commit 5c62583

Please sign in to comment.