Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making start-docker Contract-Agnostic #93

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
14170dc
feat: only mount scripts in docker-compose.yml
amessbee Aug 19, 2024
46b09a7
rebase main
amessbee Aug 19, 2024
a076ceb
feat: clean run-chain.sh
amessbee Aug 19, 2024
76842a8
feat: add copy-bundle.sh script
amessbee Aug 23, 2024
146a4db
chore: docker compose file update
amessbee Aug 23, 2024
5ac6637
chore: makefile
amessbee Aug 23, 2024
9e4f849
chore: fix package.json to do bundle on host machine
amessbee Aug 23, 2024
7971c2f
chore: fix package.json to do bundle on host machine
amessbee Aug 24, 2024
5ce8ab7
chore: fix package.json to do bundle on host machine
amessbee Aug 24, 2024
07588e2
chore: dedicated workspace dir in a3p container
amessbee Aug 29, 2024
38d1a55
chore: scripts are now copied after chain starts
amessbee Aug 29, 2024
5896060
chore: use container name instead of service in docker commands
amessbee Aug 29, 2024
8093abc
chore: simplify start:contract
amessbee Oct 22, 2024
e2e3f5f
fixup! no need for copy-bundle.sh atm
amessbee Oct 22, 2024
8c09770
chore: separate script to start chain
amessbee Jan 17, 2025
63bec30
fixup! add back `-C /ws-offerup/contract`
amessbee Jan 20, 2025
d02bd4f
chore: clean up with ENV variables
amessbee Jan 20, 2025
722a4a4
fixup! accidental container removal and refatoring
amessbee Feb 3, 2025
64a76ca
chore: container name as env var
amessbee Feb 3, 2025
206d346
fixup! error handling for CI
amessbee Feb 3, 2025
30ffba1
fixup! error in setting volumes
amessbee Feb 3, 2025
2c2e526
fixup! Update devcontainer.json
amessbee Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ instance-q:
SCRIPT=start-offer-up.js
PERMIT=start-offer-up-permit.json
start-contract: $(SCRIPT) $(PERMIT) install-bundles
scripts/propose-start-contract.sh
./scripts/propose-start-contract.sh

install-bundles: bundles/bundle-list
./scripts/install-bundles.sh
Expand Down
10 changes: 5 additions & 5 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"description": "Offer Up Contract",
"type": "module",
"scripts": {
"start:docker": "docker compose up -d",
"docker:logs": "docker compose logs --tail 200 -f",
"docker:bash": "docker compose exec agd bash",
"docker:make": "docker compose exec agd make -C /workspace/contract",
"start:docker": ". ./scripts/run-chain.sh",
"docker:logs": "docker logs --tail 200 -f ${AGDC_NAME:-agdc}",
"docker:bash": "docker exec -it ${AGDC_NAME:-agdc} bash",
"docker:make": "docker exec ${AGDC_NAME:-agdc} make -C ${WS_OFFER_UP:-/ws-offerup}/contract",
"make:help": "make list",
"start": "./scripts/wait-for-chain.sh && yarn docker:make clean start-contract",
"start": "./scripts/wait-for-chain.sh && yarn docker:make clean mint100 start-contract",
"build": "agoric run scripts/build-contract-deployer.js",
"test": "ava --verbose",
"lint": "tsc && eslint '**/*.js'",
Expand Down
2 changes: 1 addition & 1 deletion contract/scripts/build-proposal.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# NOTE: intended to run _inside_ the agd container

cd /workspace/contract
cd ${WS_OFFER_UP:-/ws-offerup}/contract

mkdir -p bundles
(agoric run ./scripts/build-contract-deployer.js )>/tmp/,run.log
Expand Down
2 changes: 1 addition & 1 deletion contract/scripts/install-bundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -ueo pipefail

. /usr/src/upgrade-test-scripts/env_setup.sh

cd /workspace/contract
cd ${WS_OFFER_UP:-/ws-offerup}/contract

# wait for blocks to start being produced
# avoid collision with run-chain.sh who is also migrating keys
Expand Down
2 changes: 1 addition & 1 deletion contract/scripts/propose-start-contract.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -xueo pipefail

cd /workspace/contract
cd ${WS_OFFER_UP:-/ws-offerup}/contract

SCRIPT=start-offer-up.js
PERMIT=start-offer-up-permit.json
Expand Down
64 changes: 56 additions & 8 deletions contract/scripts/run-chain.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
#!/bin/bash
set -e # Exit on error

. /usr/src/upgrade-test-scripts/env_setup.sh
# Set default container name if not provided
: ${AGDC_NAME:="agdc"}

# Start the chain in the background
/usr/src/upgrade-test-scripts/start_agd.sh &
# Check if container already exists and is running
if [ "$(docker ps -q -f name=$AGDC_NAME)" ]; then
echo "Container '$AGDC_NAME' is already running. Please stop it first using 'docker stop $AGDC_NAME' if you want to start a new instance."
exit 1
fi

# wait for blocks to start being produced
waitForBlock 1
# Check if container exists but is stopped
if [ "$(docker ps -aq -f status=exited -f name=$AGDC_NAME)" ]; then
echo "Found stopped container '$AGDC_NAME'. Do you want to remove it before starting a new one? (y/N)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
echo "Removing stopped container '$AGDC_NAME'..."
docker rm $AGDC_NAME
else
echo "Aborting to preserve existing container. You can set/update AGDC_NAME environment variable to avoid any potential conflicts."
exit 1
fi
fi

make -C /workspace/contract mint100
# Set paths only if environment variables are not already set
: ${DAPP_ED_CERT_PATH:="$(pwd)/../dapp-ed-cert"}
: ${DAPP_CHAIN_TIMER_PATH:="$(pwd)/../dapp-chain-timer"}
: ${SECOND_INVITE_PATH:="$(pwd)/../dapp-second-invite"}
: ${DAPP_OFFER_UP_PATH:="$(pwd)/../dapp-offer-up"}
: ${DAPP_AGORIC_BASICS_PATH:="$(pwd)/../dapp-agoric-basics"}
Comment on lines +27 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should dapp-offer-up know about these other dapps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work if somebody clones dapp-offer-up but uses something like demo as the directory name?

Does yarn create @agoric/dapp demo (from getting started) work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, any script executed by yarn start:docker is not officially dapp-offer-up. That we keep it in the same repo is a privacy-priced convenience. We can ask dev to either only load dapp-offer-up or all the dapps in the parent directory or keep a flag up top with default to only dapp-offer-up. I need a suggestion here.

As long as DAPP_OFFER_UP_PATH is set correctly this should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to understand what you're saying about yarn create @agoric/dapp demo.


# bring back chain process to foreground
wait
# Set workspace names with default values
: ${WS_EDCERT:="/ws-edcert"}
: ${WS_CHAIN_TIMER:="/ws-chainTimer"}
: ${WS_SECOND_INVITE:="/ws-secondInvite"}
: ${WS_OFFER_UP:="/ws-offerup"}
: ${WS_AGORIC_BASICS:="/ws-agoricBasics"}

# Start new container with the chain startup commands
# Define docker parameters
agd_image="ghcr.io/agoric/agoric-3-proposals:latest"
linux_only="--platform linux/amd64"
ports="-p 26656:26656 -p 26657:26657 -p 1317:1317"
env="-e DEST=1 -e DEBUG=\"SwingSet:ls,SwingSet:vat\""
volumes=""
[ -d "$DAPP_ED_CERT_PATH" ] && volumes+=" -v $DAPP_ED_CERT_PATH:$WS_EDCERT"
[ -d "$DAPP_CHAIN_TIMER_PATH" ] && volumes+=" -v $DAPP_CHAIN_TIMER_PATH:$WS_CHAIN_TIMER"
[ -d "$SECOND_INVITE_PATH" ] && volumes+=" -v $SECOND_INVITE_PATH:$WS_SECOND_INVITE"
[ -d "$DAPP_OFFER_UP_PATH" ] && volumes+=" -v $DAPP_OFFER_UP_PATH:$WS_OFFER_UP"
[ -d "$DAPP_AGORIC_BASICS_PATH" ] && volumes+=" -v $DAPP_AGORIC_BASICS_PATH:$WS_AGORIC_BASICS"
start_agd="bash -c '. /usr/src/upgrade-test-scripts/env_setup.sh && \
/usr/src/upgrade-test-scripts/start_agd.sh & \
waitForBlock 1 && \
wait'"

docker run -d --name $AGDC_NAME $linux_only $ports $env $volumes $agd_image $start_agd || {
echo "Failed to start docker container. Please check if Docker is running and you have necessary permissions."
exit 1
}

echo "Container '$AGDC_NAME' started successfully."
15 changes: 0 additions & 15 deletions docker-compose.yml

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
"@babel/highlight": "7.22.5"
},
"scripts": {
"start:docker": "cd contract && docker compose up -d",
"docker:logs": "cd contract; docker compose logs --tail 200 -f",
"docker:bash": "cd contract; docker compose exec agd bash",
"docker:make": "cd contract; docker compose exec agd make -C /workspace/contract",
"start:docker": "./contract/scripts/run-chain.sh",
"stop:docker": "cd contract && docker stop ${AGDC_NAME:-agdc} && docker rm ${AGDC_NAME:-agdc}",
"docker:logs": "cd contract && docker logs -f --tail 200 ${AGDC_NAME:-agdc}",
"docker:bash": "cd contract && docker exec -it ${AGDC_NAME:-agdc} bash",
"docker:make": "cd contract && docker exec ${AGDC_NAME:-agdc} make -C ${WS_OFFER_UP:-/ws-offerup}/contract",
"make:help": "make -C contract list",
"start:contract": "cd contract && yarn start",
"start:ui": "cd ui && yarn dev",
Expand Down