Skip to content

Commit

Permalink
Implemented the rest of the support for dynamic versions from config.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed Apr 16, 2019
1 parent 2e30cb7 commit 1c77316
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,31 @@ import { EOSManager } from '../eosManager';
import { sleep } from '../utils';
import { generateTypes } from '../contracts';
import { ConfigManager } from '../configManager';
import { GitIgnoreManager } from '../gitignoreManager';

const EOS_VERSION = '1.7.0';
const CDT_VERSION = '1.6.1';
// const CONTRACTS_VERSION = '1.6.0';
// const DOCKER_IMAGE_NAME = `lamington:eos${EOS_VERSION}-cdt${CDT_VERSION}-contracts${CONTRACTS_VERSION}`;
const DOCKER_IMAGE_NAME = `lamington:eos${EOS_VERSION}-cdt${CDT_VERSION}`;
const TEMP_DOCKER_DIRECTORY = path.join(__dirname, '.temp-docker');

const versionFromUrl = (url: string) => {
// Looks for strings in this format:
// '/v1.4.6/'
// Allows us to pull just the version part out with the group.
const pattern = /\/(v\d+\.\d+\.\d+)\//g;
const result = url.match(pattern);

if (!result) throw new Error(`Could not extract version number from url: '${url}'`);

return result[1];
};

const dockerImageName = async () => {
await ConfigManager.initWithDefaults();

return `lamington:eos.${versionFromUrl(ConfigManager.eos)}-cdt.${versionFromUrl(
ConfigManager.cdt
)}`;
};

export const imageExists = async () => {
const result = await docker.command(`images ${DOCKER_IMAGE_NAME}`);
const result = await docker.command(`images ${await dockerImageName()}`);

return result.images.length > 0;
};
Expand All @@ -56,15 +70,15 @@ RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
`
);

await docker.command(`build -t ${DOCKER_IMAGE_NAME} "${TEMP_DOCKER_DIRECTORY}"`);
await docker.command(`build -t ${await dockerImageName()} "${TEMP_DOCKER_DIRECTORY}"`);

// Clean up after ourselves.
await rimraf(TEMP_DOCKER_DIRECTORY);
};

export const startContainer = async () => {
await docker.command(
`run --rm --name lamington -d -p 8888:8888 -p 9876:9876 --mount type=bind,src="${workingDirectory}",dst=/opt/eosio/bin/project --mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts -w "/opt/eosio/bin/" ${DOCKER_IMAGE_NAME} /bin/bash -c "./scripts/init_blockchain.sh"`
`run --rm --name lamington -d -p 8888:8888 -p 9876:9876 --mount type=bind,src="${workingDirectory}",dst=/opt/eosio/bin/project --mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts -w "/opt/eosio/bin/" ${await dockerImageName()} /bin/bash -c "./scripts/init_blockchain.sh"`
);
};

Expand Down

0 comments on commit 1c77316

Please sign in to comment.