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

creating-contract-agnostic-docker --WIP-- #58

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ SIGN_BROADCAST_OPTS=--keyring-backend=test --chain-id=$(CHAINID) \
--yes -b block

mint100:
make FUNDS=1000$(ATOM) fund-acct
cd /usr/src/agoric-sdk && \
yarn --silent agops vaults open --wantMinted 100 --giveCollateral 100 >/tmp/want-ist.json && \
yarn --silent agops perf satisfaction --executeOffer /tmp/want-ist.json --from user1 --keyring-backend=test
# make FUNDS=1000$(ATOM) fund-acct
# cd /usr/src/agoric-sdk && \
# yarn --silent agops vaults open --wantMinted 100 --giveCollateral 100 >/tmp/want-ist.json && \
# yarn --silent agops perf satisfaction --executeOffer /tmp/want-ist.json --from user1 --keyring-backend=test

# Keep mint4k around a while for compatibility
mint4k:
Expand Down
8 changes: 4 additions & 4 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"description": "Agoric Basics 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/start_chain.sh",
"docker:logs": "docker logs --tail 200 -f agdc",
"docker:bash": "docker exec -it agdc bash",
"docker:make": "docker exec agdc make -C /ws-agoricBasics/contract",
"make:help": "make list",
"start": "make clean start-contract",
"build": "yarn build:deployer",
Expand Down
23 changes: 11 additions & 12 deletions contract/scripts/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const options = {
help: { type: 'boolean' },
install: { type: 'string' },
eval: { type: 'string', multiple: true },
service: { type: 'string', default: 'agd' },
workdir: { type: 'string', default: '/workspace/contract' },
container: { type: 'string', default: 'agdc' },
workdir: { type: 'string', default: '/ws-agoricBasics/contract' },
};
/**
* @typedef {{
* help: boolean,
* install?: string,
* eval?: string[],
* service: string,
* container: string,
* workdir: string,
* }} DeployOptions
*/
Expand All @@ -35,9 +35,9 @@ Options:
--install entry module of contract to install
--eval entry module of core evals to run
(cf rollup.config.mjs)
--service SVC docker compose service to run agd (default: ${options.service.default}).
--container NAME docker container name to run agd (default: ${options.container.default})
Use . to run agd outside docker.
--workdir DIR workdir for docker service (default: ${options.workdir.default})
--workdir DIR workdir for docker container (default: ${options.workdir.default})
`;

const mockExecutionContext = () => {
Expand Down Expand Up @@ -68,21 +68,21 @@ const main = async (bundleDir = 'bundles') => {
progress(Usage);
return;
}
/** @type {{ workdir: string, service: string }} */
const { workdir, service } = flags;
/** @type {{ workdir: string, container: string }} */
const { workdir, container } = flags;

/** @type {import('../tools/agd-lib.js').ExecSync} */
const dockerExec = (file, dargs, opts = { encoding: 'utf-8' }) => {
const execArgs = ['compose', 'exec', '--workdir', workdir, service];
opts.verbose &&
console.log('docker compose exec', JSON.stringify([file, ...dargs]));
const execArgs = ['exec', '--workdir', workdir, container];
const fullCommand = ['docker', ...execArgs, file, ...dargs];
console.log('Executing Docker command:', fullCommand.join(' '));
return execFileSync('docker', [...execArgs, file, ...dargs], opts);
};

const t = mockExecutionContext();
const tools = makeE2ETools(t, bundleCache, {
execFile,
execFileSync: service === '.' ? execFileSync : dockerExec,
execFileSync: container === '.' ? execFileSync : dockerExec,
fetch,
setTimeout,
writeFile,
Expand All @@ -93,7 +93,6 @@ const main = async (bundleDir = 'bundles') => {

if (flags.install) {
const name = stem(flags.install);

await tools.installBundles({ [name]: flags.install }, progress);
}

Expand Down
2 changes: 1 addition & 1 deletion contract/scripts/run-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# wait for blocks to start being produced
waitForBlock 1

make -C /workspace/contract mint100
make -C /ws-agoricBasics/contract mint100

# bring back chain process to foreground
wait
49 changes: 49 additions & 0 deletions contract/scripts/start_chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -e # Exit on error

# Check if script has execute permissions
if [ ! -x "$(pwd)/contract/scripts/run-chain.sh" ]; then
echo "Adding execute permissions to run-chain.sh..."
chmod +x "$(pwd)/contract/scripts/run-chain.sh"
fi

# Check if container already exists and is running
if [ "$(docker ps -q -f name=agdc)" ]; then
echo "Container 'agdc' is already running. Please stop it first using 'docker stop agdc' if you want to start a new instance."
exit 1
fi

# Check if container exists but is stopped
if [ "$(docker ps -aq -f status=exited -f name=agdc)" ]; then
echo "Found stopped container 'agdc'. Removing it before starting a new one..."
docker rm agdc
fi

# 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"}

# Start new container
docker run -d \
--name agdc \
--platform linux/amd64 \
-p 26656:26656 \
-p 26657:26657 \
-p 1317:1317 \
-e DEST=1 \
-e DEBUG="SwingSet:ls,SwingSet:vat" \
$([ -d "$DAPP_ED_CERT_PATH" ] && echo "-v $DAPP_ED_CERT_PATH:/ws-edcert") \
$([ -d "$DAPP_CHAIN_TIMER_PATH" ] && echo "-v $DAPP_CHAIN_TIMER_PATH:/ws-chainTimer") \
$([ -d "$SECOND_INVITE_PATH" ] && echo "-v $SECOND_INVITE_PATH:/ws-secondInvite") \
$([ -d "$DAPP_OFFER_UP_PATH" ] && echo "-v $DAPP_OFFER_UP_PATH:/ws-offerup") \
$([ -d "$DAPP_AGORIC_BASICS_PATH" ] && echo "-v $DAPP_AGORIC_BASICS_PATH:/ws-agoricBasics") \
ghcr.io/agoric/agoric-3-proposals:latest \
/ws-edcert/contract/scripts/run-chain.sh || {
echo "Failed to start docker container. Please check if Docker is running and you have necessary permissions."
exit 1
}

echo "Container 'agdc' started successfully."
4 changes: 2 additions & 2 deletions contract/test/test-postalSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@

/** @type {ExecSync} */
const dockerExec = (file, args, opts = { encoding: 'utf-8' }) => {
const workdir = '/workspace/contract';
const workdir = '/ws-agoricBasics/contract';
const execArgs = ['compose', 'exec', '--workdir', workdir, 'agd'];
opts.verbose &&

Check warning on line 63 in contract/test/test-postalSvc.js

View workflow job for this annotation

GitHub Actions / unit

Delete `⏎·····`
console.log('docker compose exec', JSON.stringify([file, ...args]));
console.log('docker exec', JSON.stringify([file, ...args]));
return execFileSync('docker', [...execArgs, file, ...args], opts);
};

Expand Down
15 changes: 15 additions & 0 deletions contract/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { E, Far } from '@endo/far';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Nat } from '@endo/nat';
import { exec } from 'child_process';
import { flags, makeAgd } from './agd-lib.js';
import { makeHttpClient, makeAPI } from './ui-kit-goals/makeHttpClient.js';
import { dedup, makeQueryKit, poll } from './ui-kit-goals/queryKit.js';
Expand Down Expand Up @@ -117,6 +118,8 @@
const { chainId = 'agoriclocal', installer = 'user1' } = opts;
const from = await agd.lookup(installer);


Check warning on line 121 in contract/tools/e2e-tools.js

View workflow job for this annotation

GitHub Actions / unit

Delete `⏎⏎`

const explainDelay = (ms, info) => {
progress('follow', { ...info, delay: ms / 1000 }, '...');
return delay(ms);
Expand Down Expand Up @@ -485,6 +488,7 @@
await null;
/** @type {Record<string, CachedBundle>} */
const bundles = {};
// Below we are creating bundles for each contract
for (const [name, rootModPath] of Object.entries(bundleRoots)) {
const bundle = await bundleCache.load(rootModPath, name);
bundles[name] = bundle;
Expand All @@ -509,6 +513,11 @@

const bundleSizeMb = (bundleJSON.length / 1_000_000).toFixed(3);
progress('installing', name, shortId, bundleSizeMb, 'Mb');
const containerId = 'agdc'; // container is named agd

Check warning on line 516 in contract/tools/e2e-tools.js

View workflow job for this annotation

GitHub Actions / unit

Delete `·`
const localPath = './bundles';
const containerPath = '/ws-agoricBasics/contract/';
const command = `docker cp ${localPath} ${containerId}:${containerPath}`;
exec(command);
const { tx, confirm } = await installBundle(fullPath, {
id: shortId,
agd,
Expand Down Expand Up @@ -581,7 +590,13 @@
// not yet bundled
}
const detail = { evals: [eval0], title, description };
// The following creates bundle scripts and jsons in bundles/ directory
await runPackageScript('build:deployer', entryFile);
const containerId = 'agd'; // container is named agd

Check warning on line 595 in contract/tools/e2e-tools.js

View workflow job for this annotation

GitHub Actions / unit

Delete `·`
const localPath = './bundles';
const containerPath = '/ws-agoric-basics/contract/';
const command = `docker cp ${localPath} ${containerId}:${containerPath}`;
exec(command);
const proposal = await runCoreEval(t, detail, { agd, blockTool });
await writeFile(
`${eval0.code}.done`,
Expand Down
17 changes: 0 additions & 17 deletions docker-compose.yml

This file was deleted.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
},
"scripts": {
"postinstall": "patch-package",
"start:docker": "cd contract && docker compose up -d",
"stop:docker": "cd contract && docker compose down",
"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/start_chain.sh",
"stop:docker": "cd contract && docker stop agdc && docker rm agdc",
"docker:logs": "cd contract && docker logs -f --tail 200 agdc",
"docker:bash": "cd contract && docker exec -it agdc bash",
"docker:make": "cd contract && docker exec agdc make -C /ws-agoricBasics/contract",
"make:help": "make -C contract list",
"start:contract": "cd contract && yarn start",
"start:ui": "export VITE_HOSTNAME=$CODESPACE_NAME && export VITE_GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN && cd ui && yarn dev",
Expand Down
Loading