1
0
Fork 0
mirror of https://github.com/anyproto/any-sync-dockercompose.git synced 2025-06-08 05:47:03 +09:00

added versions to env, fixed variable names in script, fixes in Makefile

This commit is contained in:
Kirill Shklyaev 2023-11-14 19:10:03 +03:00
parent 91f4e95f65
commit 7e307b1bd3
6 changed files with 56 additions and 51 deletions

4
.env
View file

@ -7,6 +7,10 @@ ANY_SYNC_FILENODE_VERSION=latest
ANY_SYNC_COORDINATOR_VERSION=latest
ANY_SYNC_CONSENSUSNODE_VERSION=latest
MONGO_VERSION=7.0.2
REDIS_VERSION=7.2.0-v6
S3_EMULATOR_VERSION=0.0.1
ANY_SYNC_NODE_1_HOST=any-sync-node-1
ANY_SYNC_NODE_1_PORT=1001
ANY_SYNC_NODE_1_ADDRESSES=${ANY_SYNC_NODE_1_HOST}:${ANY_SYNC_NODE_1_PORT}

View file

@ -10,7 +10,7 @@ RUN ./generate_config.sh
FROM alpine:3.18.4
RUN apk add --no-cache bash perl
WORKDIR /opt/processing
COPY docker-generateconfig/etc/ etc/
COPY docker-generateconfig/etc/ tmp-etc/
COPY --chmod=777 docker-generateconfig/processing.sh .
COPY --from=generator /opt/generateconfig/ generateconfig/

View file

@ -3,7 +3,7 @@ include .env
generate_config:
docker build -t generateconfig -f Dockerfile-generateconfig .
docker run --rm -v ${CURDIR}/config:/opt/processing/config --name any-sync-generator generateconfig
docker run --rm -v ${CURDIR}/etc:/opt/processing/etc --name any-sync-generator generateconfig
start: generate_config
docker compose up -d
@ -28,5 +28,6 @@ restart: down start
update: down pull start
upgrade: down clean start
cleanTmp:
rm -rf config/
cleanEtcStorage:
rm -rf etc/
rm -rf storage/

View file

@ -7,7 +7,7 @@ Self-host for any-sync, designed for review and testing purposes.
* install docker and docker-compose https://docs.docker.com/compose/install/linux/
## Usage
* start stand:
* start stand - at the first run the directories `etc/` of configuration files and `storage/` for data storage will be generated:
```
make start
```
@ -27,9 +27,9 @@ Self-host for any-sync, designed for review and testing purposes.
```
make clean
```
* clean tmp files - deleting data for redis, mongo, s3, any-sync-*:
* clean config and storage files - deleting data for redis, mongo, s3, any-sync-*:
```
make cleanTmp
make cleanEtcStorage
```
* show logs:
```

View file

@ -2,56 +2,56 @@ version: "3.9"
services:
mongo-1:
image: mongo:7.0.2
image: "mongo:${MONGO_VERSION}"
command: --replSet rs0 --port ${MONGO_1_PORT}
ports:
- "${MONGO_1_PORT}:${MONGO_1_PORT}"
volumes:
- ./data/mongo-1/:/data/db
- ./storage/mongo-1/:/data/db
healthcheck:
test: test $$(echo "rs.initiate({_id:'rs0',members:[{_id:0,host:\"mongo-1:${MONGO_1_PORT}\"},{_id:1,host:\"mongo-2:${MONGO_2_PORT}\"},{_id:2,host:\"mongo-3:${MONGO_3_PORT}\"}]}).ok || rs.status().ok" | mongosh --port ${MONGO_1_PORT} --quiet) -eq 1
interval: 10s
start_period: 30s
mongo-2:
image: mongo:7.0.2
image: "mongo:${MONGO_VERSION}"
command: --replSet rs0 --port ${MONGO_2_PORT}
ports:
- "${MONGO_2_PORT}:${MONGO_2_PORT}"
volumes:
- ./data/mongo-2/:/data/db
- ./storage/mongo-2/:/data/db
mongo-3:
image: mongo:7.0.2
image: "mongo:${MONGO_VERSION}"
command: --replSet rs0 --port ${MONGO_3_PORT}
ports:
- "${MONGO_3_PORT}:${MONGO_3_PORT}"
volumes:
- ./data/mongo-3/:/data/db
- ./storage/mongo-3/:/data/db
redis:
container_name: redis
image: redis/redis-stack-server:7.2.0-v6
image: "redis/redis-stack-server:${REDIS_VERSION}"
restart: always
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy noeviction --protected-mode no --loadmodule /opt/redis-stack/lib/redisbloom.so
ports:
- "${REDIS_PORT}:${REDIS_PORT}"
volumes:
- ./data/redis/:/data/
- ./storage/redis/:/data/
s3-emulator:
image: stanislavt/s3-emulator:0.0.1
image: "stanislavt/s3-emulator:${S3_EMULATOR_VERSION}"
ports:
- "${AWS_PORT}:4569"
volumes:
- ./data/s3_root:/s3_root
- ./storage/s3_root:/s3_root
any-sync-coordinator_bootstrap:
image: "ghcr.io/anyproto/any-sync-coordinator:${ANY_SYNC_COORDINATOR_VERSION}"
depends_on:
- mongo-1
volumes:
- ./config/any-sync-coordinator/:/etc/any-sync-coordinator/
- ./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"
@ -64,8 +64,8 @@ services:
- "${ANY_SYNC_COORDINATOR_QUIC_PORT}:${ANY_SYNC_COORDINATOR_QUIC_PORT}"
- 8005:8000
volumes:
- ./config/any-sync-coordinator/:/etc/any-sync-coordinator/
- ./data/networkStore/any-sync-coordinator/:/networkStore/
- ./etc/any-sync-coordinator/:/etc/any-sync-coordinator/
- ./storage/networkStore/any-sync-coordinator/:/networkStore/
deploy:
resources:
limits:
@ -84,9 +84,9 @@ services:
- "${ANY_SYNC_FILENODE_QUIC_PORT}:${ANY_SYNC_FILENODE_QUIC_PORT}"
- 8004:8000
volumes:
- ./config/any-sync-filenode/:/etc/any-sync-filenode/
- ./etc/any-sync-filenode/:/etc/any-sync-filenode/
- ./.aws:/root/.aws:ro
- ./data/networkStore/any-sync-filenode/:/networkStore/
- ./storage/networkStore/any-sync-filenode/:/networkStore/
deploy:
resources:
limits:
@ -104,9 +104,9 @@ services:
- 8081:8080
- 8001:8000
volumes:
- ./config/any-sync-node-1/:/etc/any-sync-node/
- ./data/storage/any-sync-node-1/:/storage/
- ./data/networkStore/any-sync-node-1/:/networkStore/
- ./etc/any-sync-node-1/:/etc/any-sync-node/
- ./storage/any-sync-node-1/:/storage/
- ./storage/networkStore/any-sync-node-1/:/networkStore/
deploy:
resources:
limits:
@ -124,9 +124,9 @@ services:
- 8082:8080
- 8002:8000
volumes:
- ./config/any-sync-node-2/:/etc/any-sync-node/
- ./data/storage/any-sync-node-2/:/storage/
- ./data/networkStore/any-sync-node-2/:/networkStore/
- ./etc/any-sync-node-2/:/etc/any-sync-node/
- ./storage/any-sync-node-2/:/storage/
- ./storage/networkStore/any-sync-node-2/:/networkStore/
deploy:
resources:
limits:
@ -144,9 +144,9 @@ services:
- 8083:8080
- 8003:8000
volumes:
- ./config/any-sync-node-3/:/etc/any-sync-node/
- ./data/storage/any-sync-node-3/:/storage/
- ./data/networkStore/any-sync-node-3/:/networkStore/
- ./etc/any-sync-node-3/:/etc/any-sync-node/
- ./storage/any-sync-node-3/:/storage/
- ./storage/networkStore/any-sync-node-3/:/networkStore/
deploy:
resources:
limits:
@ -163,8 +163,8 @@ services:
- "${ANY_SYNC_CONSENSUSNODE_QUIC_PORT}:${ANY_SYNC_CONSENSUSNODE_QUIC_PORT}"
- 8006:8000
volumes:
- ./config/any-sync-consensusnode/:/etc/any-sync-consensusnode/
- ./data/networkStore/any-sync-consensusnode/:/networkStore/
- ./etc/any-sync-consensusnode/:/etc/any-sync-consensusnode/
- ./storage/networkStore/any-sync-consensusnode/:/networkStore/
deploy:
resources:
limits:

View file

@ -3,46 +3,46 @@
source generateconfig/.env
# Set file paths
DEST_PATH="config"
NETWORK_FILE="${DEST_PATH}/network.yml"
dest_path="etc"
network_file="${dest_path}/network.yml"
# Create directories for all node
for i in {1..3}; do
mkdir -p "${DEST_PATH}/any-sync-node-${i}"
mkdir -p "${dest_path}/any-sync-node-${i}"
done
# Create directories for other node types
for node_type in filenode coordinator consensusnode; do
mkdir -p "${DEST_PATH}/any-sync-${node_type}"
mkdir -p "${dest_path}/any-sync-${node_type}"
done
# Generate network file
sed 's|^| |; 1s|^|network:\n|' "generateconfig/nodes.yml" > "${NETWORK_FILE}"
sed 's|^| |; 1s|^|network:\n|' "generateconfig/nodes.yml" > "${network_file}"
# Generate config files for 3 nodes
for i in {0..2}; do
NODE_FILE="${DEST_PATH}/any-sync-node-$((i+1))/config.yml"
cat "${NETWORK_FILE}" etc/common.yml generateconfig/account${i}.yml etc/node-$((i+1)).yml > "${NODE_FILE}"
node_file="${dest_path}/any-sync-node-$((i+1))/config.yml"
cat "${network_file}" tmp-etc/common.yml generateconfig/account${i}.yml tmp-etc/node-$((i+1)).yml > "${node_file}"
done
# Generate config files for coordinator, filenode, consensusnode
cat "${NETWORK_FILE}" etc/common.yml generateconfig/account3.yml etc/coordinator.yml > ${DEST_PATH}/any-sync-coordinator/config.yml
cat "${NETWORK_FILE}" etc/common.yml generateconfig/account4.yml etc/filenode.yml > ${DEST_PATH}/any-sync-filenode/config.yml
cat "${NETWORK_FILE}" etc/common.yml generateconfig/account5.yml etc/consensusnode.yml > ${DEST_PATH}/any-sync-consensusnode/config.yml
cat "${network_file}" tmp-etc/common.yml generateconfig/account3.yml tmp-etc/coordinator.yml > ${dest_path}/any-sync-coordinator/config.yml
cat "${network_file}" tmp-etc/common.yml generateconfig/account4.yml tmp-etc/filenode.yml > ${dest_path}/any-sync-filenode/config.yml
cat "${network_file}" tmp-etc/common.yml generateconfig/account5.yml tmp-etc/consensusnode.yml > ${dest_path}/any-sync-consensusnode/config.yml
# Copy network file to coordinator directory
cp "generateconfig/nodes.yml" "${DEST_PATH}/any-sync-coordinator/network.yml"
cp "generateconfig/nodes.yml" "${dest_path}/any-sync-coordinator/network.yml"
# Replace placeholders in config files
for node_type in node_1 node_2 node_3 coordinator filenode consensusnode; do
ADDRESSES_VAR="ANY_SYNC_${node_type^^}_ADDRESSES"
QUIC_ADDRESSES_VAR="ANY_SYNC_${node_type^^}_QUIC_ADDRESSES"
perl -i -pe "s|%${ADDRESSES_VAR}%|${!ADDRESSES_VAR}|g" "${NETWORK_FILE}" "${DEST_PATH}/"/*/*.yml
perl -i -pe "s|%${QUIC_ADDRESSES_VAR}%|${!QUIC_ADDRESSES_VAR}|g" "${NETWORK_FILE}" "${DEST_PATH}/"/*/*.yml
addresses="ANY_SYNC_${node_type^^}_ADDRESSES"
quic_addresses="ANY_SYNC_${node_type^^}_QUIC_ADDRESSES"
perl -i -pe "s|%${addresses}%|${!addresses}|g" "${network_file}" "${dest_path}/"/*/*.yml
perl -i -pe "s|%${quic_addresses}%|${!quic_addresses}|g" "${network_file}" "${dest_path}/"/*/*.yml
done
# Replace other placeholders
PLACEHOLDERS=( "MONGO_CONNECT" "REDIS_URL" "AWS_PORT" )
for placeholder in "${PLACEHOLDERS[@]}"; do
perl -i -pe "s|%${placeholder}%|${!placeholder}|g" "${NETWORK_FILE}" "${DEST_PATH}/"/*/*.yml
placeholders=( "MONGO_CONNECT" "REDIS_URL" "AWS_PORT" )
for placeholder in "${placeholders[@]}"; do
perl -i -pe "s|%${placeholder}%|${!placeholder}|g" "${network_file}" "${dest_path}/"/*/*.yml
done