Skip to content

Commit

Permalink
Init system contracts when creating docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
jnordberg committed Sep 27, 2019
1 parent 24e9d97 commit f9fe443
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ const versionFromUrl = (url: string) => {
/**
* Constructs the name of the current Lamington Docker image
* @author Kevin Brown <github.com/thekevinbrown>
* @author Johan Nordberg <github.com/jnordberg>
* @returns Docker image name
*/
const dockerImageName = async () => {
await ConfigManager.loadConfigFromDisk();

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

/**
Expand All @@ -84,6 +85,7 @@ export const imageExists = async () => {
* Configures and builds the docker image
* @author Kevin Brown <github.com/thekevinbrown>
* @author Mitch Pierias <github.com/MitchPierias>
* @author Johan Nordberg <github.com/jnordberg>
*/
export const buildImage = async () => {
// Log notification
Expand All @@ -92,14 +94,25 @@ export const buildImage = async () => {
await rimraf(TEMP_DOCKER_DIRECTORY);
await mkdirp(TEMP_DOCKER_DIRECTORY);
// Write a Dockerfile so Docker knows what to build.
const systemDeps = [
'build-essential',
'ca-certificates',
'cmake',
'curl',
'git',
'wget',
]
await writeFile(
path.join(TEMP_DOCKER_DIRECTORY, 'Dockerfile'),
`
FROM ubuntu:18.04
RUN apt-get update --fix-missing && apt-get install -y --no-install-recommends wget curl ca-certificates
RUN apt-get update --fix-missing && apt-get install -y --no-install-recommends ${systemDeps.join(' ')}
RUN wget ${ConfigManager.cdt} && apt-get install -y ./*.deb && rm -f *.deb
RUN wget ${ConfigManager.eos} && apt-get install -y ./*.deb && rm -f *.deb
RUN eos_ver=$(ls /usr/opt/eosio | head -n 1); \
git clone --depth 1 --branch ${ConfigManager.contracts} https://github.com/EOSIO/eosio.contracts.git /usr/opt/eosio.contracts &&\
cd /usr/opt/eosio.contracts && ./build.sh -e "/usr/opt/eosio/$eos_ver" -c /usr/opt/eosio.cdt
RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
`.replace(/\t/gm, '')
);
Expand Down
10 changes: 10 additions & 0 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CONFIGURATION_FILE_NAME = '.lamingtonrc';
export interface LamingtonConfig {
cdt: string;
eos: string;
contracts: string;
keepAlive?: boolean;
outDir?: string;
exclude?: Array<string>;
Expand All @@ -46,6 +47,7 @@ export enum LamingtonDebugLevel {
const DEFAULT_CONFIG = {
eos:'',
cdt:'',
contracts:'v1.8.0-rc1',
debug:LamingtonDebugLevel.NONE,
debugTransactions: false,
keepAlive: false,
Expand Down Expand Up @@ -181,6 +183,14 @@ export class ConfigManager {
return (ConfigManager.config && ConfigManager.config.cdt) || '';
}

/**
* Returns the current eosio.contracts configuration
* @author Johan Nordberg <github.com/jnordberg>
*/
static get contracts() {
return (ConfigManager.config && ConfigManager.config.contracts) || 'master';
}

/**
* Returns the container keep alive setting or false
* @author Mitch Pierias <github.com/MitchPierias>
Expand Down
18 changes: 17 additions & 1 deletion src/scripts/init_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ nodeos -e -p eosio -d /mnt/dev/data \
--max-transaction-time=1000 \
--http-validate-host=false \
--plugin eosio::producer_plugin \
--plugin eosio::producer_api_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::http_plugin \
--http-server-address=0.0.0.0:8888 \
Expand All @@ -34,10 +35,25 @@ do
sleep 1s
done

syskey_pub=EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
syskey_priv=5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

echo "=== lamington: setup wallet: lamington ==="
# First key import is for eosio system account
cleos wallet create -n eosiomain --to-console | tail -1 | sed -e 's/^"//' -e 's/"$//' > eosiomain_wallet_password.txt
cleos wallet import -n eosiomain --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos wallet import -n eosiomain --private-key $syskey_priv

echo "=== lamington: activate protocol features ==="
curl --silent --output /dev/null -X POST localhost:8888/v1/producer/schedule_protocol_feature_activations \
-d '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}'
sleep 2s

echo "=== lamington: install bios ==="
contracts_dir=/usr/opt/eosio.contracts/build/contracts
cleos set contract eosio "$contracts_dir/eosio.bios" -p eosio@active
cleos create account eosio eosio.token $syskey_pub
cleos set contract eosio.token "$contracts_dir/eosio.token" -p eosio.token@active
cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS"]' -p eosio.token@active

# put the background nodeos job to foreground for docker run
fg %1

0 comments on commit f9fe443

Please sign in to comment.