Skip to content

Commit

Permalink
Merge pull request #40 from anyproto/ghcr.io-image-versions
Browse files Browse the repository at this point in the history
added support prod,stage1 versions for ghcr docker images
  • Loading branch information
fb929 committed Apr 23, 2024
2 parents 1303549 + a9b8cfc commit 98d528f
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 129 deletions.
10 changes: 5 additions & 5 deletions .env → .env.common
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ MINIO_BUCKET=minio-bucket
MINIO_PORT=9000
MINIO_WEB_PORT=9001

ANY_SYNC_NODE_VERSION=v0.3.25
ANY_SYNC_FILENODE_VERSION=v0.6.1
ANY_SYNC_COORDINATOR_VERSION=v0.3.17
ANY_SYNC_CONSENSUSNODE_VERSION=v0.1.5
ANY_SYNC_NODE_VERSION=prod
ANY_SYNC_FILENODE_VERSION=prod
ANY_SYNC_COORDINATOR_VERSION=prod
ANY_SYNC_CONSENSUSNODE_VERSION=prod
ANY_SYNC_ADMIN_VERSION=latest

MONGO_VERSION=7.0.2
REDIS_VERSION=7.2.0-v6
MINIO_VERSION=RELEASE.2024-01-16T16-07-38Z

EXTERNAL_LISTEN_HOST="127.0.0.1"
EXTERNAL_LISTEN_HOSTS="127.0.0.1"

ANY_SYNC_NODE_1_HOST=any-sync-node-1
ANY_SYNC_NODE_1_PORT=1001
Expand Down
4 changes: 4 additions & 0 deletions .env.override.latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ANY_SYNC_NODE_VERSION=latest
ANY_SYNC_FILENODE_VERSION=latest
ANY_SYNC_COORDINATOR_VERSION=latest
ANY_SYNC_CONSENSUSNODE_VERSION=latest
4 changes: 4 additions & 0 deletions .env.override.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ANY_SYNC_NODE_VERSION=prod
ANY_SYNC_FILENODE_VERSION=prod
ANY_SYNC_COORDINATOR_VERSION=prod
ANY_SYNC_CONSENSUSNODE_VERSION=prod
4 changes: 4 additions & 0 deletions .env.override.stage1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ANY_SYNC_NODE_VERSION=stage1
ANY_SYNC_FILENODE_VERSION=stage1
ANY_SYNC_COORDINATOR_VERSION=stage1
ANY_SYNC_CONSENSUSNODE_VERSION=stage1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.DS_Store
/etc/
/storage/
/docker-compose.override.yml
/repos/
/.env
/.env.override
17 changes: 0 additions & 17 deletions Dockerfile-generateconfig

This file was deleted.

12 changes: 12 additions & 0 deletions Dockerfile-generateconfig-anyconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1
FROM golang:1.21.6-alpine3.19
RUN apk add --no-cache bash yq
RUN go install github.com/anyproto/any-sync-tools/anyconf@latest
WORKDIR /code
HEALTHCHECK \
--start-period=3s \
--retries=20 \
--interval=10s \
--timeout=3s \
CMD echo 'HEALTHCHECK' | nc 127.0.0.1 8000 | grep -q HEALTHCHECK
ENTRYPOINT ./docker-generateconfig/anyconf.sh
6 changes: 6 additions & 0 deletions Dockerfile-generateconfig-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# syntax=docker/dockerfile:1
FROM python:3.11-alpine
WORKDIR /code
COPY docker-generateconfig/env-requirements.txt requirements.txt
RUN pip install -r requirements.txt
ENTRYPOINT ./docker-generateconfig/env.py
11 changes: 11 additions & 0 deletions Dockerfile-generateconfig-processing
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1
FROM alpine:3.18.4
RUN apk add --no-cache bash yq perl python3 py3-yaml
WORKDIR /code
HEALTHCHECK \
--start-period=3s \
--retries=10 \
--interval=5s \
--timeout=3s \
CMD echo 'HEALTHCHECK' | nc 127.0.0.1 8000 | grep -q HEALTHCHECK
ENTRYPOINT ./docker-generateconfig/processing.sh
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
.DEFAULT_GOAL := start
include .env

generate_config:
mkdir -p ./storage/docker-generateconfig/
docker build -t generateconfig -f Dockerfile-generateconfig .
generate_env:
docker buildx build --tag generateconfig-env --file Dockerfile-generateconfig-env .
docker run --rm \
--volume ${CURDIR}/etc:/opt/processing/etc \
--volume ${CURDIR}/storage/docker-generateconfig:/opt/processing/docker-generateconfig \
--name any-sync-generator generateconfig
--volume ${CURDIR}/:/code/ \
generateconfig-env

start: generate_config
start: generate_env
docker compose up -d
@echo "Done! Upload your self-hosted network configuration file ${CURDIR}/etc/client.yml into the client app"
@echo "See: https://doc.anytype.io/anytype-docs/data-and-security/self-hosting#switching-between-networks"
Expand Down
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Self-host for any-sync, designed for personal usage or for review and testing pu
- [Prepare](#prepare)
- [Usage](#usage)
- [Configuration](#configuration)
- [Troubleshooting](#troubleshooting)
- [Compatible versions](#compatible-versions)
- [Local build](#local-build)
- [Limits web admin](#limits-web-admin)
Expand All @@ -36,8 +37,8 @@ Self-host for any-sync, designed for personal usage or for review and testing pu
git config --global core.autocrlf false
# Generate config
docker build -t generateconfig -f Dockerfile-generateconfig .
docker run --rm -v ${PWD}/etc:/opt/processing/etc --name any-sync-generator generateconfig
docker buildx build --tag generateconfig-env --file Dockerfile-generateconfig-env .
docker run --rm --volume ${PWD}/:/code/ generateconfig-env
# Run containers
docker compose up -d
```
Expand Down Expand Up @@ -96,10 +97,38 @@ Self-host for any-sync, designed for personal usage or for review and testing pu
ANYTYPE_LOG_LEVEL="*=DEBUG" ANYPROF=:6060 ANY_SYNC_NETWORK=$(pwd)/etc/client.yml /Applications/Anytype.app/Contents/MacOS/Anytype
```

## configuration
Use file .env
* Set specific versions: find and edit variables with suffix "_VERSION"
* Set external listen host: default 127.0.0.1, for change you need edit variable "EXTERNAL_LISTEN_HOST"
## Configuration
> [!WARNING]
> The .env file is generated automatically.
It is based on the .env.common file, which is overridden or extended by variables from the .env.override file.
### Version control
By default, we use "prod" image version for any-sync-* daemons.
Also you can use "stage1" or "latest" verions:
```
# for use stage1 version
ln -F -s .env.override.stage1 .env.override
# for use latest version
ln -F -s .env.override.latest .env.override
```
### external listen host
By default, we use only the listen address 127.0.0.1, which is sufficient for running tests and a local client.
If you need to connect external clients, please add "EXTERNAL_LISTEN_HOSTS" in .env.override file.
Use spaces separation, multiline is not supported. For example:
```
EXTERNAL_LISTEN_HOSTS=<yourExternalIp1> <yourExternalIp2 ...
```

## Troubleshooting & FAQ
### mongo replica set error
if you have mongo replica set error like this:
```
test> rs.status()
MongoServerError: Our replica set config is invalid or we are not a member of it
```
please run command:
```
docker compose exec mongo-1 mongosh --port 27001 --eval 'rs.reconfig({_id: rs.conf()._id, members: [{ _id: 0, host: "mongo-1:27001" }]}, {force: true});'
```

## Compatible versions
You can find compatible versions on these pages:
Expand All @@ -122,6 +151,8 @@ If you need to create local build binaries for any-sync-*, you can do so by usin
make restart
```

ln -F -s .env.override.stage1 .env.override

## Limits web admin
open link in browser: http://127.0.0.1:80

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ After Upgrade please run:
```
docker compose exec mongo-1 mongosh --port 27001 --eval 'rs.reconfig({_id: rs.conf()._id, members: [{ _id: 0, host: "mongo-1:27001" }]}, {force: true});'
```

## Upgrading from v3.x.x to v4.x.x
1. You need to transfer your modifications from the .env file to the .env.override file.
2. The variable EXTERNAL_LISTEN_HOST is deprecated.
Please, use the variable EXTERNAL_LISTEN_HOSTS instead.
70 changes: 53 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
version: "3.9"

services:
# generate configs using the anyconf utility
generateconfig-anyconf:
image: generateconfig-anyconf
build:
context: .
dockerfile: Dockerfile-generateconfig-anyconf
volumes:
- ./:/code

# processing any-sync-* configs
generateconfig-processing:
depends_on:
generateconfig-anyconf:
condition: service_healthy
image: generateconfig-processing
build:
context: .
dockerfile: Dockerfile-generateconfig-processing
volumes:
- ./:/code

mongo-1:
depends_on:
generateconfig-processing:
condition: service_healthy
image: "mongo:${MONGO_VERSION}"
command: --replSet ${MONGO_REPLICA_SET} --port ${MONGO_1_PORT}
ports:
- "${MONGO_1_PORT}:${MONGO_1_PORT}"
volumes:
- ./storage/mongo-1/:/data/db
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate() }" | mongosh --port ${MONGO_1_PORT} --quiet
test: test $$(mongosh --port ${MONGO_1_PORT} --quiet --eval "try {rs.initiate({_id:'${MONGO_REPLICA_SET}',members:[{_id:0,host:\"mongo-1:${MONGO_1_PORT}\"}]})} catch(e) {rs.status().ok}") -eq 1
interval: 10s
start_period: 30s

redis:
depends_on:
generateconfig-processing:
condition: service_healthy
image: "redis/redis-stack-server:${REDIS_VERSION}"
restart: always
command: redis-server --dir /data/ --appendonly yes --maxmemory 256mb --maxmemory-policy noeviction --protected-mode no --loadmodule /opt/redis-stack/lib/redisbloom.so
Expand Down Expand Up @@ -64,16 +91,24 @@ services:
any-sync-coordinator_bootstrap:
image: "ghcr.io/anyproto/any-sync-coordinator:${ANY_SYNC_COORDINATOR_VERSION}"
depends_on:
- mongo-1
generateconfig-processing:
condition: service_healthy
mongo-1:
condition: service_healthy
volumes:
- ./etc/any-sync-coordinator/:/etc/any-sync-coordinator/
restart: no
command: bash -c "sleep 10; /bin/any-sync-confapply -c /etc/any-sync-coordinator/config.yml -n /etc/any-sync-coordinator/network.yml -e"
command: bash -c "/bin/any-sync-confapply -c /etc/any-sync-coordinator/config.yml -n /etc/any-sync-coordinator/network.yml -e"

any-sync-coordinator:
image: "ghcr.io/anyproto/any-sync-coordinator:${ANY_SYNC_COORDINATOR_VERSION}"
depends_on:
- any-sync-coordinator_bootstrap
generateconfig-processing:
condition: service_healthy
mongo-1:
condition: service_healthy
any-sync-coordinator_bootstrap:
condition: service_completed_successfully
ports:
- "${ANY_SYNC_COORDINATOR_PORT}:${ANY_SYNC_COORDINATOR_PORT}"
- "${ANY_SYNC_COORDINATOR_QUIC_PORT}:${ANY_SYNC_COORDINATOR_QUIC_PORT}"
Expand All @@ -86,14 +121,16 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 10; /bin/any-sync-coordinator -c /etc/any-sync-coordinator/config.yml"

any-sync-filenode:
image: "ghcr.io/anyproto/any-sync-filenode:${ANY_SYNC_FILENODE_VERSION}"
depends_on:
- redis
- minio
- any-sync-coordinator
redis:
condition: service_healthy
minio:
condition: service_healthy
any-sync-coordinator:
condition: service_started
ports:
- "${ANY_SYNC_FILENODE_PORT}:${ANY_SYNC_FILENODE_PORT}"
- "${ANY_SYNC_FILENODE_QUIC_PORT}:${ANY_SYNC_FILENODE_QUIC_PORT}"
Expand All @@ -107,12 +144,12 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 15; /bin/any-sync-filenode -c /etc/any-sync-filenode/config.yml"

any-sync-node-1:
image: "ghcr.io/anyproto/any-sync-node:${ANY_SYNC_NODE_VERSION}"
depends_on:
- any-sync-coordinator
any-sync-coordinator:
condition: service_started
ports:
- "${ANY_SYNC_NODE_1_PORT}:${ANY_SYNC_NODE_1_PORT}"
- "${ANY_SYNC_NODE_1_QUIC_PORT}:${ANY_SYNC_NODE_1_QUIC_PORT}"
Expand All @@ -127,12 +164,12 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 15; /bin/any-sync-node -c /etc/any-sync-node/config.yml"

any-sync-node-2:
image: "ghcr.io/anyproto/any-sync-node:${ANY_SYNC_NODE_VERSION}"
depends_on:
- any-sync-coordinator
any-sync-coordinator:
condition: service_started
ports:
- "${ANY_SYNC_NODE_2_PORT}:${ANY_SYNC_NODE_2_PORT}"
- "${ANY_SYNC_NODE_2_QUIC_PORT}:${ANY_SYNC_NODE_2_QUIC_PORT}"
Expand All @@ -147,12 +184,12 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 15; /bin/any-sync-node -c /etc/any-sync-node/config.yml"

any-sync-node-3:
image: "ghcr.io/anyproto/any-sync-node:${ANY_SYNC_NODE_VERSION}"
depends_on:
- any-sync-coordinator
any-sync-coordinator:
condition: service_started
ports:
- "${ANY_SYNC_NODE_3_PORT}:${ANY_SYNC_NODE_3_PORT}"
- "${ANY_SYNC_NODE_3_QUIC_PORT}:${ANY_SYNC_NODE_3_QUIC_PORT}"
Expand All @@ -167,12 +204,12 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 15; /bin/any-sync-node -c /etc/any-sync-node/config.yml"

any-sync-consensusnode:
image: "ghcr.io/anyproto/any-sync-consensusnode:${ANY_SYNC_CONSENSUSNODE_VERSION}"
depends_on:
- any-sync-coordinator
any-sync-coordinator:
condition: service_started
ports:
- "${ANY_SYNC_CONSENSUSNODE_PORT}:${ANY_SYNC_CONSENSUSNODE_PORT}"
- "${ANY_SYNC_CONSENSUSNODE_QUIC_PORT}:${ANY_SYNC_CONSENSUSNODE_QUIC_PORT}"
Expand All @@ -185,7 +222,6 @@ services:
limits:
memory: 500M
restart: on-failure
command: bash -c "sleep 15; /bin/any-sync-consensusnode -c /etc/any-sync-consensusnode/config.yml"

any-sync-admin:
image: "ghcr.io/anyproto/any-sync-admin:${ANY_SYNC_ADMIN_VERSION}"
Expand Down
Loading

0 comments on commit 98d528f

Please sign in to comment.