From a74e69aeb3c64294f054687d847ce06225eb154b Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 5 Jun 2021 17:06:13 +0200 Subject: [PATCH] Introduce dev dockerfile for contract migration enabling faster iteration in dev --- apps/cic-eth/cic_eth/version.py | 2 +- apps/cic-eth/requirements.txt | 6 +- apps/contract-migration/docker/Dockerfile | 15 ++- apps/contract-migration/docker/Dockerfile.dev | 93 +++++++++++++++++++ .../override_requirements.txt | 3 + apps/contract-migration/requirements.txt | 9 +- apps/contract-migration/reset.sh | 29 ++++-- docker-compose.yml | 13 ++- 8 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 apps/contract-migration/docker/Dockerfile.dev create mode 100644 apps/contract-migration/override_requirements.txt diff --git a/apps/cic-eth/cic_eth/version.py b/apps/cic-eth/cic_eth/version.py index 0edda257..fd65bab3 100644 --- a/apps/cic-eth/cic_eth/version.py +++ b/apps/cic-eth/cic_eth/version.py @@ -10,7 +10,7 @@ version = ( 0, 11, 0, - 'beta.16', + 'beta.17', ) version_object = semver.VersionInfo( diff --git a/apps/cic-eth/requirements.txt b/apps/cic-eth/requirements.txt index 3f56ce0c..ac143555 100644 --- a/apps/cic-eth/requirements.txt +++ b/apps/cic-eth/requirements.txt @@ -1,4 +1,4 @@ -cic-base~=0.1.2b15 +cic-base~=0.1.2b17 celery==4.4.7 crypto-dev-signer~=0.4.14b3 confini~=0.3.6rc3 @@ -18,8 +18,8 @@ chainlib~=0.0.3rc2 hexathon~=0.0.1a7 chainsyncer[sql]~=0.0.2a5 chainqueue~=0.0.2b3 -sarafu-faucet==0.0.3a3 -erc20-faucet==0.2.1a4 +sarafu-faucet~=0.0.3a4 +erc20-faucet~=0.2.1a4 coincurve==15.0.0 potaahto~=0.0.1a2 pycryptodome==3.10.1 diff --git a/apps/contract-migration/docker/Dockerfile b/apps/contract-migration/docker/Dockerfile index a15ac1c8..6aa16479 100644 --- a/apps/contract-migration/docker/Dockerfile +++ b/apps/contract-migration/docker/Dockerfile @@ -22,7 +22,7 @@ COPY contract-migration/nvm.sh . ENV CONFINI_DIR /usr/local/etc/cic/ RUN mkdir -vp $CONFINI_DIR -ARG cic_config_commit=35c69ba75f00c8147150acf325565d5391cf25bf +ARG cic_config_commit=0abe0867f18077907c7023bf0ef5e466a3984dd8 ARG cic_config_url=https://gitlab.com/grassrootseconomics/cic-config.git/ RUN echo Install confini schema files && \ git clone --depth 1 $cic_config_url cic-config && \ @@ -56,7 +56,9 @@ COPY contract-migration/requirements.txt . ARG pip_extra_args="" ARG pip_index_url=https://pypi.org/simple ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433 -RUN pip install --index-url https://pypi.org/simple \ +ARG pip_trusted_host=pypi.org +RUN pip install --index-url $pip_index_url \ + --trusted-host $pip_trusted_host \ --extra-index-url $pip_extra_index_url -r requirements.txt # -------------- begin runtime container ---------------- @@ -97,4 +99,13 @@ RUN chmod gu+x *.sh # USER grassroots +ARG pip_index_url=https://pypi.org/simple +ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433 +ARG pip_trusted_host=pypi.org +COPY contract-migration/override_requirements.txt . +RUN pip install --index-url $pip_index_url \ + --force-reinstall \ + --trusted-host $pip_trusted_host \ + --extra-index-url $pip_extra_index_url -r override_requirements.txt + ENTRYPOINT [ ] diff --git a/apps/contract-migration/docker/Dockerfile.dev b/apps/contract-migration/docker/Dockerfile.dev new file mode 100644 index 00000000..2d8a76fa --- /dev/null +++ b/apps/contract-migration/docker/Dockerfile.dev @@ -0,0 +1,93 @@ +# syntax = docker/dockerfile:1.2 +FROM python:3.8.6-slim-buster as compile-image + +RUN apt-get update +RUN apt-get install -y --no-install-recommends git gcc g++ libpq-dev gawk jq telnet wget openssl iputils-ping gnupg socat bash procps make python2 cargo + +RUN touch /etc/apt/sources.list.d/ethereum.list +RUN echo 'deb http://ppa.launchpad.net/ethereum/ethereum/ubuntu bionic main' > /etc/apt/sources.list.d/ethereum.list +RUN echo 'deb-src http://ppa.launchpad.net/ethereum/ethereum/ubuntu bionic main' >> /etc/apt/sources.list.d/ethereum.list + +RUN cat etc/apt/sources.list.d/ethereum.list +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2A518C819BE37D2C2031944D1C52189C923F6CA9 + +RUN apt-get update +RUN apt-get install solc +RUN pip install --upgrade pip + +WORKDIR /root +RUN mkdir -vp /usr/local/etc/cic + +COPY contract-migration/nvm.sh . +ENV CONFINI_DIR /usr/local/etc/cic/ +RUN mkdir -vp $CONFINI_DIR + +ARG cic_config_commit=0abe0867f18077907c7023bf0ef5e466a3984dd8 +ARG cic_config_url=https://gitlab.com/grassrootseconomics/cic-config.git/ +RUN echo Install confini schema files && \ + git clone --depth 1 $cic_config_url cic-config && \ + cd cic-config && \ + git fetch --depth 1 origin $cic_config_commit && \ + git checkout $cic_config_commit && \ + cp -v *.ini $CONFINI_DIR + +# Install nvm with node and npm +# https://stackoverflow.com/questions/25899912/how-to-install-nvm-in-docker +ENV NVM_DIR /root/.nvm +ENV NODE_VERSION 15.3.0 +ENV BANCOR_NODE_VERSION 10.16.0 + +RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash \ + && . $NVM_DIR/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm alias default $NODE_VERSION \ + && nvm use $NODE_VERSION +# && chown -R root:root "$NVM_DIR/versions/node/v$NODE_VERSION" + +ENV NODE_PATH $NVM_DIR/versions/node//v$NODE_VERSION/lib/node_modules +ENV PATH $NVM_DIR/versions/node//v$NODE_VERSION/bin:$PATH + +#RUN useradd --create-home grassroots +# WORKDIR /home/grassroots +# USER grassroots + +COPY contract-migration/requirements.txt . + +ARG pip_extra_args="" +ARG pip_index_url=https://pypi.org/simple +ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433 +ARG pip_trusted_host=pypi.org +RUN pip install --index-url $pip_index_url \ + --trusted-host $pip_trusted_host \ + --extra-index-url $pip_extra_index_url -r requirements.txt + +COPY contract-migration/testdata/pgp testdata/pgp +COPY contract-migration/sarafu_declaration.json sarafu_declaration.json +COPY contract-migration/keystore keystore +COPY contract-migration/envlist . + +# A shared output dir for environment configs +RUN mkdir -p /tmp/cic/config +# RUN chown grassroots:grassroots /tmp/cic/config +RUN chmod a+rwx /tmp/cic/config + +COPY contract-migration/*.sh ./ +# RUN chown grassroots:grassroots -R . +RUN chmod gu+x *.sh + +# we copied these from the root build container. +# this is dumb though...I guess the compile image should have the same user +# RUN chown grassroots:grassroots -R /usr/local/lib/python3.8/site-packages/ + +# USER grassroots + +ARG pip_index_url=https://pypi.org/simple +ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433 +ARG pip_trusted_host=pypi.org +COPY contract-migration/override_requirements.txt . +RUN pip install --index-url $pip_index_url \ + --force-reinstall \ + --trusted-host $pip_trusted_host \ + --extra-index-url $pip_extra_index_url -r override_requirements.txt + +ENTRYPOINT [ ] diff --git a/apps/contract-migration/override_requirements.txt b/apps/contract-migration/override_requirements.txt new file mode 100644 index 00000000..62ba7a71 --- /dev/null +++ b/apps/contract-migration/override_requirements.txt @@ -0,0 +1,3 @@ +erc20-demurrage-token==0.0.1b1 + + diff --git a/apps/contract-migration/requirements.txt b/apps/contract-migration/requirements.txt index 291ced7a..64ae898f 100644 --- a/apps/contract-migration/requirements.txt +++ b/apps/contract-migration/requirements.txt @@ -1,4 +1,5 @@ - cic-base[full_graph]==0.1.2b15 - sarafu-faucet==0.0.3a3 - sarafu-token==0.0.1a8 - cic-eth==0.11.0b16 +cic-base[full_graph]==0.1.2b17 +sarafu-faucet~=0.0.3a4 +erc20-demurrage-token==0.0.1b1 +cic-eth~=0.11.0b16 + diff --git a/apps/contract-migration/reset.sh b/apps/contract-migration/reset.sh index 4ecf2fba..ac8c8b65 100755 --- a/apps/contract-migration/reset.sh +++ b/apps/contract-migration/reset.sh @@ -2,14 +2,26 @@ set -a +cat <&2 echo using static gas price $DEV_ETH_GAS_PRICE fi -if [[ $CIC_DEFAULT_TOKEN_SYMBOL != 'GFT' && $CIC_DEFAULT_TOKEN_SYMBOL != 'SRF' ]]; then - >&2 echo CIC_DEFAULT_TOKEN_SYMBOL must be one of [GFT,SRF], but was $CIC_DEFAULT_TOKEN_SYMBOL +if [[ $TOKEN_SYMBOL != 'GFT' && $TOKEN_SYMBOL != 'SRF' ]]; then + >&2 echo TOKEN_SYMBOL must be one of [GFT,SRF], but was $TOKEN_SYMBOL exit 1 fi @@ -60,17 +72,16 @@ if [[ -n "${ETH_PROVIDER}" ]]; then ./wait-for-it.sh "${ETH_PROVIDER_HOST}:${ETH_PROVIDER_PORT}" fi - if [ $CIC_DEFAULT_TOKEN_SYMBOL == 'GFT' ]; then + if [ $TOKEN_SYMBOL == 'GFT' ]; then >&2 echo "deploying 'giftable token'" - DEV_RESERVE_ADDRESS=`giftable-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -w --name "Giftable Token" --symbol "GFT" --decimals 6 -vv` + DEV_RESERVE_ADDRESS=`giftable-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww --name "Giftable Token" --symbol "GFT" --decimals 6 -vv` else - >&2 echo "deploying 'sarafu' token'" - DEV_RESERVE_ADDRESS=`sarafu-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -w --name "Sarafu" --decimals 6 -vv SRF $DEV_SARAFU_DEMURRAGE_LEVEL` + >&2 echo "deploying 'redistributed demurrage token'" + DEV_RESERVE_ADDRESS=`erc20-demurrage-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww` fi + exit 0 giftable-token-gift $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -w -a $DEV_RESERVE_ADDRESS $DEV_RESERVE_AMOUNT - #BANCOR_REGISTRY_ADDRESS=`cic-bancor-deploy $gas_price_arg --bancor-dir /usr/local/share/cic/bancor -z $DEV_ETH_RESERVE_ADDRESS -p $ETH_PROVIDER -o $DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER` - >&2 echo "deploy account index contract" DEV_ACCOUNT_INDEX_ADDRESS=`eth-accounts-index-deploy $gas_price_arg -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -vv -w` >&2 echo "add deployer address as account index writer" diff --git a/docker-compose.yml b/docker-compose.yml index a6a4ba89..50b64013 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -72,11 +72,11 @@ services: contract-migration: build: + dockerfile: contract-migration/docker/Dockerfile.dev args: pip_index_url: ${PIP_DEFAULT_INDEX_URL:-https://pypi.org/simple} pip_extra_args: $PIP_EXTRA_ARGS context: apps/ - dockerfile: contract-migration/docker/Dockerfile # image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/contract-migration:latest environment: # ETH_PROVIDER should be broken out into host/port but cic-eth expects this @@ -101,9 +101,16 @@ services: DEV_PIP_EXTRA_INDEX_URL: ${DEV_PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net:8433} RUN_MASK: ${RUN_MASK:-0} # bit flags; 1: contract migrations 2: seed data DEV_FAUCET_AMOUNT: ${DEV_FAUCET_AMOUNT:-0} - CIC_DEFAULT_TOKEN_SYMBOL: ${CIC_DEFAULT_TOKEN_SYMBOL:-GFT} - DEV_SARAFU_DEMURRAGE_LEVEL: ${DEV_SARAFU_DEMURRAGE_LEVEL:-196454828847045000000000000000000} + #CIC_DEFAULT_TOKEN_SYMBOL: ${CIC_DEFAULT_TOKEN_SYMBOL:-GFT} + #DEV_SARAFU_DEMURRAGE_LEVEL: ${DEV_SARAFU_DEMURRAGE_LEVEL:-196454828847045000000000000000000} DEV_ETH_GAS_PRICE: ${DEV_ETH_GAS_PRICE:-1} + TOKEN_NAME: $TOKEN_NAME + TOKEN_SYMBOL: $TOKEN_SYMBOL + TOKEN_DECIMALS: $TOKEN_DECIMALS + TOKEN_REDISTRIBUTION_PERIOD: $TOKEN_REDISTRIBUTION_PERIOD + TOKEN_SUPPLY_LIMIT: $TOKEN_SUPPLY_LIMIT + TOKEN_DEMURRAGE_LEVEL: ${TOKEN_DEMURRAGE_LEVEL:-196454828847045000000000000000000} + CONFINI_DIR: $CONFINI_DIR command: ["./run_job.sh"] #command: ["./reset.sh"] depends_on: