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 11 commits into
base: main
Choose a base branch
from
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
9 changes: 6 additions & 3 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
"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",
"docker:bash": "docker exec agd bash",
"docker:make": "docker exec agd make -C /ws-agoric-basics/contract",
Comment on lines -10 to +11
Copy link
Member

Choose a reason for hiding this comment

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

interesting approach!

Copy link
Member

@dckc dckc Sep 5, 2024

Choose a reason for hiding this comment

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

idea: to manage namespace collisions, use an env variable with a default ${AG_CONTAINER:-agd}

and maybe for ws-agoric-basics

"make:help": "make list",
"start": "make clean start-contract",
"docker:copy-Makefile": "docker exec agd mkdir -p /ws-agoric-basics/contract; docker cp Makefile agd:/ws-agoric-basics/contract/",
"docker:copy-scripts": "docker cp scripts agd:/ws-agoric-basics/contract/",
"docker:copy-tools": "docker cp tools agd:/ws-agoric-basics/contract/",
"start": "yarn docker:copy-Makefile; yarn docker:copy-scripts; yarn docker:copy-tools; make clean start-contract",
"build": "yarn build:deployer",
"build:deployer": "rollup -c rollup.config.mjs",
"test": "ava --verbose",
Expand Down
6 changes: 3 additions & 3 deletions contract/scripts/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const options = {
install: { type: 'string' },
eval: { type: 'string', multiple: true },
service: { type: 'string', default: 'agd' },
workdir: { type: 'string', default: '/workspace/contract' },
workdir: { type: 'string', default: '/ws-agoric-basics/contract' },
};
/**
* @typedef {{
Expand Down Expand Up @@ -74,9 +74,9 @@ const main = async (bundleDir = 'bundles') => {

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

Expand Down
6 changes: 3 additions & 3 deletions contract/scripts/run-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ waitForBlock() (

approveProposals() {
while true; do
proposals=$(make -s -C /workspace/contract gov-voting-q 2>/dev/null)
proposals=$(make -s -C /ws-agoric-basics/contract gov-voting-q 2>/dev/null)
exit_status=$?
if [ $exit_status -eq 0 ]; then
echo "Approving proposals: $proposals"
printf $proposals | xargs -I {} make -s -C /workspace/contract vote PROPOSAL={}
printf $proposals | xargs -I {} make -s -C /ws-agoric-basics/contract vote PROPOSAL={}
else
echo "No proposals to approve, continuing..."
fi
Expand All @@ -63,7 +63,7 @@ waitForBlock 2
# Approve any proposals forever in the background.
approveProposals &

make -C /workspace/contract mint100
# make -C /ws-agoric-basics/contract mint100

# bring back chain process to foreground
wait
6 changes: 3 additions & 3 deletions contract/test/test-postalSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const makeTestContext = async t => {

/** @type {import('../tools/agd-lib.js').ExecSync} */
const dockerExec = (file, args, opts = { encoding: 'utf-8' }) => {
const workdir = '/workspace/contract';
const execArgs = ['compose', 'exec', '--workdir', workdir, 'agd'];
const workdir = '/ws-agoric-basics/contract';
const execArgs = ['exec', '--workdir', workdir, 'agd'];
opts.verbose &&
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
16 changes: 16 additions & 0 deletions contract/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
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';
import { getBundleId } from './bundle-tools.js';
import { makeVStorage } from './ui-kit-goals/batchQuery.js';


const BLD = '000000ubld';

const makeRunner = execFile => {
Expand Down Expand Up @@ -103,6 +105,8 @@ const installBundle = async (fullPath, opts) => {
const { chainId = 'agoriclocal', installer = 'user1' } = opts;
const from = await agd.lookup(installer);



const explainDelay = (ms, info) => {
progress('follow', { ...info, delay: ms / 1000 }, '...');
return delay(ms);
Expand Down Expand Up @@ -472,6 +476,7 @@ export const makeE2ETools = (
await null;
/** @type {Record<string, import('../test/boot-tools.js').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 @@ -496,6 +501,11 @@ export const makeE2ETools = (

const bundleSizeMb = (bundleJSON.length / 1_000_000).toFixed(3);
progress('installing', name, shortId, bundleSizeMb, 'Mb');
const containerId = 'agd'; // container is named agd
const localPath = './bundles';
const containerPath = '/ws-agoric-basics/contract/';
const command = `docker cp ${localPath} ${containerId}:${containerPath}`;
exec(command);
const { tx, confirm } = await installBundle(fullPath, {
id: shortId,
agd,
Expand Down Expand Up @@ -568,7 +578,13 @@ export const makeE2ETools = (
// 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
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
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '3.5'

services:
agd:
# cf. https://github.com/Agoric/agoric-3-proposals
image: ghcr.io/agoric/agoric-3-proposals:latest
container_name: agd
platform: linux/amd64
ports:
- 26656:26656
Expand All @@ -12,6 +12,6 @@ services:
environment:
DEST: 1
DEBUG: "SwingSet:ls,SwingSet:vat"
volumes:
- .:/workspace
entrypoint: /workspace/contract/scripts/run-chain.sh
volumes:
- ./contract/scripts/run-chain.sh:/scripts/run-chain.sh
entrypoint: /scripts/run-chain.sh
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"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",
"docker:bash": "cd contract; docker exec agd bash",
"docker:make": "cd contract; docker exec agd make -C /ws-agoric-basics/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