Skip to content

Commit

Permalink
Merge pull request #324 from EYBlockchain/lydia/optimiseStartup
Browse files Browse the repository at this point in the history
 Optimise the startup scripts and dockerfiles for speed
  • Loading branch information
lydiagarms authored Aug 16, 2024
2 parents 6b1a74e + 58ae206 commit 7c6eea8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 56 deletions.
47 changes: 42 additions & 5 deletions src/boilerplate/common/bin/startup
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,59 @@ set -e

docker compose -f docker-compose.zapp.yml down -v

sleep 5
# Wait for all containers from the docker-compose.zapp.yml configuration to be removed
while docker compose -f docker-compose.zapp.yml ps | grep -q 'Up'; do
sleep 1
done

docker compose -f docker-compose.zapp.yml up -d ganache
docker compose -f docker-compose.zapp.yml up -d zokrates

sleep 5
# Wait for the ganache service to be ready
while ! nc -z localhost 8545; do
sleep 1
done

# Get the ID of the zokrates container
container_id_zokrates=$(docker compose -f docker-compose.zapp.yml ps -q zokrates)

# Wait for the zokrates service to be ready
while ! nc -z localhost 8080; do
sleep 1
done


CONSTRUCTOR_CALL

docker compose -f docker-compose.zapp.yml up -d deployer
docker compose -f docker-compose.zapp.yml up -d deployer

# Get the ID of the deployer container
container_id=$(docker compose -f docker-compose.zapp.yml ps -q deployer)

# Wait for the deployer container to stop and get its exit code
exit_code=$(docker wait "$container_id")

# Exit the script if the exit code is 1
if [ "$exit_code" -eq 1 ]; then
echo "Deployer container failed with exit code 1, exiting."
exit 1
fi

# Wait for the deployer container to be ready
while ! docker logs "$container_id" 2>&1 | grep -q "Saving migration to chain."; do
sleep 1
done

sleep 25

docker compose -f docker-compose.zapp.yml up -d timber

sleep 10
# Get the ID of the timber container
container_id=$(docker compose -f docker-compose.zapp.yml ps -q timber)

# Wait for the timber container to be ready
while ! docker logs "$container_id" 2>&1 | grep -q "Blockchain Connected"; do
sleep 1
done

docker compose -f docker-compose.zapp.yml up -d zapp

Expand Down
3 changes: 0 additions & 3 deletions src/boilerplate/common/boilerplate-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ WORKDIR /app

COPY ./package.json ./package-lock.json ./
RUN npm i
COPY circuits ./circuits
COPY config ./config
COPY orchestration ./orchestration
COPY proving-files ./proving-files

EXPOSE 3000

Expand Down
3 changes: 1 addition & 2 deletions src/boilerplate/common/boilerplate-Dockerfile.deployer
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ RUN apt-get update -y
RUN apt-get install -y netcat-openbsd

COPY ./package.json ./package-lock.json ./
RUN npm ci
COPY entrypoint.sh entrypoint.sh
COPY contracts contracts
COPY migrations migrations
COPY truffle-config.js truffle-config.js
RUN chmod +x entrypoint.sh
RUN npm ci
ENTRYPOINT ["./entrypoint.sh"]
18 changes: 0 additions & 18 deletions src/boilerplate/common/boilerplate-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ services:
depends_on:
- zokrates
volumes:
- ./circuits/:/app/circuits:delegated
- ./proving-files/:/app/output:delegated
- ./orchestration/common/write-vk.mjs:/app/write-vk.mjs # "
- ./orchestration/:/app/orchestration:delegated
- ./config/:/app/config:delegated
networks:
- zapp_network
zapp:
Expand All @@ -24,19 +22,11 @@ services:
context: .
dockerfile: Dockerfile
depends_on:
- zokrates
- timber
- ganache
- zapp-mongo
volumes:
- ./build:/app/build
- ./contracts/:/app/contracts/
- ./migrations/:/app/migrations/
- ./truffle-config.js:/app/truffle-config.js
- ./circuits/:/app/circuits:delegated
- ./orchestration/:/app/orchestration:delegated
- ./test/:/app/test:delegated
- ./config/:/app/config:delegated
environment:
BLOCKCHAIN_HOST: ws://ganache
BLOCKCHAIN_PORT: 8545
Expand All @@ -60,8 +50,6 @@ services:
volumes:
- ./circuits/:/app/circuits:delegated
- ./proving-files/:/app/output:delegated
- ./orchestration/common/write-vk.mjs:/app/write-vk.mjs
- ./orchestration/common/db/:/app/orchestration/common/db:delegated
environment:
PROVING_SCHEME: 'g16'
ports:
Expand All @@ -76,10 +64,8 @@ services:
restart: on-failure
depends_on:
- timber-mongo
- ganache
volumes:
- ./config/:/app/config
- ./contracts/:/app/contracts:consistent
- ./build/:/app/build:consistent
ports:
- '9000:80'
Expand Down Expand Up @@ -142,13 +128,9 @@ services:
build:
context: .
dockerfile: Dockerfile.deployer
depends_on:
- ganache
volumes:
- ./build:/app/build
- ./contracts/:/app/contracts/
- ./migrations/:/app/migrations/
- ./truffle-config.js:/app/truffle-config.js
- ./orchestration/:/app/orchestration:delegated
environment:
BLOCKCHAIN_HOST: ws://ganache
Expand Down
28 changes: 0 additions & 28 deletions src/boilerplate/common/boilerplate-docker-compose.zapp-double.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@ services:
context: .
dockerfile: Dockerfile
depends_on:
- zokrates
- timber
- ganache
- zapp-mongo
volumes:
- ./build:/app/build
- ./contracts/:/app/contracts/
- ./migrations/:/app/migrations/
- ./truffle-config.js:/app/truffle-config.js
- ./circuits/:/app/circuits:delegated
- ./orchestration/:/app/orchestration:delegated
- ./test/:/app/test:delegated
- ./config/:/app/config:delegated
environment:
BLOCKCHAIN_HOST: ws://ganache
BLOCKCHAIN_PORT: 8545
Expand All @@ -43,19 +35,11 @@ services:
context: .
dockerfile: Dockerfile
depends_on:
- zokrates
- timber
- ganache
- zapp-mongo
volumes:
- ./build:/app/build
- ./contracts/:/app/contracts/
- ./migrations/:/app/migrations/
- ./truffle-config.js:/app/truffle-config.js
- ./circuits/:/app/circuits:delegated
- ./orchestration/:/app/orchestration:delegated
- ./test/:/app/test:delegated
- ./config/:/app/config:delegated
environment:
BLOCKCHAIN_HOST: ws://ganache
BLOCKCHAIN_PORT: 8545
Expand All @@ -79,8 +63,6 @@ services:
volumes:
- ./circuits/:/app/circuits:delegated
- ./proving-files/:/app/output:delegated
- ./orchestration/common/write-vk.mjs:/app/write-vk.mjs
- ./orchestration/common/db/:/app/orchestration/common/db:delegated
environment:
PROVING_SCHEME: 'g16'
ports:
Expand All @@ -96,8 +78,6 @@ services:
volumes:
- ./circuits/:/app/circuits:delegated
- ./proving-files/:/app/output:delegated
- ./orchestration/common/write-vk.mjs:/app/write-vk.mjs
- ./orchestration/common/db/:/app/orchestration/common/db:delegated
environment:
PROVING_SCHEME: 'g16'
ports:
Expand All @@ -112,10 +92,8 @@ services:
restart: on-failure
depends_on:
- timber-mongo
- ganache
volumes:
- ./config/:/app/config
- ./contracts/:/app/contracts:consistent
- ./build/:/app/build:consistent
ports:
- '9000:80'
Expand Down Expand Up @@ -144,10 +122,8 @@ services:
restart: on-failure
depends_on:
- timber-mongo
- ganache
volumes:
- ./config/:/app/config
- ./contracts/:/app/contracts:consistent
- ./build/:/app/build:consistent
ports:
- '9001:80'
Expand Down Expand Up @@ -245,13 +221,9 @@ services:
build:
context: .
dockerfile: Dockerfile.deployer
depends_on:
- ganache
volumes:
- ./build:/app/build
- ./contracts/:/app/contracts/
- ./migrations/:/app/migrations/
- ./truffle-config.js:/app/truffle-config.js
- ./orchestration/:/app/orchestration:delegated
environment:
BLOCKCHAIN_HOST: ws://ganache
Expand Down

0 comments on commit 7c6eea8

Please sign in to comment.