Simplify docker federation setup

This commit is contained in:
Felix Ableitner 2020-08-31 17:26:32 +02:00
parent b15c406924
commit 147972273a
8 changed files with 33 additions and 103 deletions

View file

@ -1,20 +0,0 @@
#!/bin/bash
set -e
sudo docker-compose --file ../federation/docker-compose.yml --project-directory . down
sudo rm -rf volumes
pushd ../../server/
cargo build
popd
pushd ../../ui
yarn
popd
mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
sudo docker build ../../ --file ../federation/Dockerfile --tag lemmy-federation:latest
sudo docker-compose --file ../federation/docker-compose.yml --project-directory . up

View file

@ -1,12 +0,0 @@
#!/bin/bash
set -xe
pushd ../../ui
echo "Waiting for Lemmy to start..."
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done
yarn api-test || true
popd

View file

@ -1,17 +0,0 @@
FROM ekidd/rust-musl-builder:1.42.0-openssl11
USER root
RUN mkdir /app/dist/documentation/ -p \
&& addgroup --gid 1001 lemmy \
&& adduser --gecos "" --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
# Copy resources
COPY server/config/defaults.hjson /app/config/defaults.hjson
COPY ui/dist /app/dist
COPY server/target/debug/lemmy_server /app/lemmy
RUN chown lemmy:lemmy /app/ -R
USER lemmy
EXPOSE 8536
WORKDIR /app
CMD ["/app/lemmy"]

View file

@ -10,8 +10,7 @@ services:
- "8570:8570" - "8570:8570"
- "8580:8580" - "8580:8580"
volumes: volumes:
# Hack to make this work from both docker/federation/ and docker/federation-test/ - ./nginx.conf:/etc/nginx/nginx.conf
- ../federation/nginx.conf:/etc/nginx/nginx.conf
restart: on-failure restart: on-failure
depends_on: depends_on:
- pictrs - pictrs

View file

@ -1,28 +0,0 @@
#!/bin/bash
set -e
# already start rust build in the background
pushd ../../server/ || exit
cargo build &
popd || exit
if [ "$1" != "--no-yarn-build" ]; then
pushd ../../ui/ || exit
yarn
yarn build
popd || exit
fi
# wait for rust build to finish
pushd ../../server/ || exit
cargo build
popd || exit
sudo docker build ../../ --file Dockerfile -t lemmy-federation:latest
for Item in alpha beta gamma delta epsilon ; do
sudo mkdir -p volumes/pictrs_$Item
sudo chown -R 991:991 volumes/pictrs_$Item
done
sudo docker-compose up

View file

@ -2,26 +2,18 @@
set -e set -e
# make sure there are no old containers or old data around # make sure there are no old containers or old data around
sudo docker-compose --file ../federation/docker-compose.yml --project-directory . down sudo docker-compose down
sudo rm -rf volumes sudo rm -rf volumes
pushd ../../server/
cargo build
popd
pushd ../../ui
yarn
popd
mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon} mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon} sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
sudo docker build ../../ --file ../federation/Dockerfile --tag lemmy-federation:latest sudo docker build ../../ --file ../dev/Dockerfile --tag lemmy-federation:latest
sudo mkdir -p volumes/pictrs_alpha sudo mkdir -p volumes/pictrs_alpha
sudo chown -R 991:991 volumes/pictrs_alpha sudo chown -R 991:991 volumes/pictrs_alpha
sudo docker-compose --file ../federation/docker-compose.yml --project-directory . up -d sudo docker-compose up -d
pushd ../../ui pushd ../../ui
echo "Waiting for Lemmy to start..." echo "Waiting for Lemmy to start..."
@ -33,6 +25,6 @@ while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')
yarn api-test || true yarn api-test || true
popd popd
sudo docker-compose --file ../federation/docker-compose.yml --project-directory . down sudo docker-compose down
sudo rm -r volumes/ sudo rm -r volumes

11
docker/federation/start-local-instances.bash vendored Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
sudo docker build ../../ --file ../dev/Dockerfile -t lemmy-federation:latest
for Item in alpha beta gamma delta epsilon ; do
sudo mkdir -p volumes/pictrs_$Item
sudo chown -R 991:991 volumes/pictrs_$Item
done
sudo docker-compose up

View file

@ -14,25 +14,30 @@ You need to have the following packages installed, the Docker service needs to b
- docker - docker
- docker-compose - docker-compose
- cargo
- yarn
Then run the following Then run the following
```bash ```bash
cd docker/federation cd docker/federation
./run-federation-test.bash -yarn ./start-local-instances.bash
``` ```
The federation test sets up 3 instances: The federation test sets up 5 instances:
Instance / Username | Location Instance | Username | Location | Notes
--- | --- --- | --- | --- | ---
lemmy_alpha | [127.0.0.1:8540](http://127.0.0.1:8540) lemmy-alpha | lemmy_alpha | [127.0.0.1:8540](http://127.0.0.1:8540) | federated with all other instances
lemmy_beta | [127.0.0.1:8550](http://127.0.0.1:8550) lemmy-beta | lemmy_beta | [127.0.0.1:8550](http://127.0.0.1:8550) | federated with all other instances
lemmy_gamma | [127.0.0.1:8560](http://127.0.0.1:8560) lemmy-gamma | lemmy_gamma | [127.0.0.1:8560](http://127.0.0.1:8560) | federated with all other instances
lemmy-delta | lemmy_delta | [127.0.0.1:8570](http://127.0.0.1:8570) | only allows federation with lemmy-beta
lemmy-epsilon | lemmy_epsilon | [127.0.0.1:8580](http://127.0.0.1:8580) | uses blocklist, has lemmy-alpha blocked
You can log into each using the instance name, and `lemmy` as the password, IE (`lemmy_alpha`, `lemmy`). You can log into each using the instance name, and `lemmy` as the password, IE (`lemmy_alpha`, `lemmy`).
To start federation between instances, visit one of them and search for a user, community or post, like this:
- `!main@lemmy-alpha:8540`
- `http://lemmy-beta:8550/post/3`
- `@lemmy-gamma@lemmy-gamma:8560`
Firefox containers are a good way to test them interacting. Firefox containers are a good way to test them interacting.
## Integration tests ## Integration tests
@ -40,8 +45,8 @@ Firefox containers are a good way to test them interacting.
To run a suite of suite of federation integration tests: To run a suite of suite of federation integration tests:
```bash ```bash
cd docker/federation-test cd docker/federation
./run-tests.sh ./run-tests.bash
``` ```
## Running on a server ## Running on a server