From c979ae2054ff58a3d282abffc0800693b59405fd Mon Sep 17 00:00:00 2001 From: "Justin D. Harris" Date: Mon, 13 Sep 2021 13:55:37 -0400 Subject: [PATCH] Correct Docker pushes (#129) prod: Add version number Remove trailing whitespace in many files. Co-authored-by: Justin D. Harris <> --- .github/workflows/demo-prod.yml | 11 ++++++++--- .github/workflows/demo-test.yml | 2 +- .github/workflows/docker.yml | 8 ++++---- .github/workflows/simulation-test.yml | 4 ++-- README.md | 2 +- demo/client/src/components/model.js | 5 ++--- demo/client/src/ml-models/deploy-model.ts | 3 +-- demo/client/src/ml-models/model-interfaces.ts | 6 +++--- demo/server.js | 4 ++-- simulation/README.md | 4 ++-- .../contract/incentive/prediction_market.py | 6 +++--- simulation/setup.py | 2 +- 12 files changed, 30 insertions(+), 27 deletions(-) diff --git a/.github/workflows/demo-prod.yml b/.github/workflows/demo-prod.yml index 4fb8b7c..3d094c9 100644 --- a/.github/workflows/demo-prod.yml +++ b/.github/workflows/demo-prod.yml @@ -15,6 +15,11 @@ jobs: run: | cd demo docker login --username 0xDeCA10Bcontainerreg 0xdeca10bcontainerreg.azurecr.io --password ${{ secrets._0XDECA10B_AZURECR_PASSWORD }} - docker build --file service.Dockerfile -t 0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca10b-demo-prod . - docker push 0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca10b-demo-prod:latest - + + name="0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca10b-demo-prod" + version=`grep version package.json | head -n1 | awk -F: '{ print $2 }' | sed 's/[",[:space:]]\+//g'` + + docker build --file service.Dockerfile -t ${name} -t ${name}:${version} . + docker push ${name}:latest + docker push ${name}:${version} + diff --git a/.github/workflows/demo-test.yml b/.github/workflows/demo-test.yml index 6dfcca3..cf4720a 100644 --- a/.github/workflows/demo-test.yml +++ b/.github/workflows/demo-test.yml @@ -32,7 +32,7 @@ jobs: -t mcr.microsoft.com/samples/blockchain-ai/0xdeca10b-demo:latest \ . - name: Test - run: | + run: | docker run --rm --name decai-demo \ -v /${PWD}/demo:/root/workspace/demo \ -v /root/workspace/demo/node_modules \ diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index da71665..333f8cc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -21,11 +21,11 @@ jobs: run: | cd demo docker login --username 0xDeCA10Bcontainerreg 0xdeca10bcontainerreg.azurecr.io --password ${{ secrets._0XDECA10B_AZURECR_PASSWORD }} - + name="0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca10b-demo" version=`grep version package.json | head -n1 | awk -F: '{ print $2 }' | sed 's/[",[:space:]]\+//g'` - docker build --file Dockerfile -t ${name} -t ${name}:${version} . + docker build --file Dockerfile -t ${name} -t ${name}:${version} . docker push ${name}:latest docker push ${name}:${version} @@ -33,10 +33,10 @@ jobs: run: | cd simulation docker login --username 0xDeCA10Bcontainerreg 0xdeca10bcontainerreg.azurecr.io --password ${{ secrets._0XDECA10B_AZURECR_PASSWORD }} - + name="0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca10b-simulation" version=`grep 'version=' setup.py | head -n1 | awk '{ split($0,a,"="); print a[2] }' | sed "s/[\',[:space:]]//g"` - docker build --file Dockerfile -t ${name} -t ${name}:${version} . + docker build --file Dockerfile -t ${name} -t ${name}:${version} . docker push ${name}:latest docker push ${name}:${version} \ No newline at end of file diff --git a/.github/workflows/simulation-test.yml b/.github/workflows/simulation-test.yml index 005a6d7..2e1d90a 100644 --- a/.github/workflows/simulation-test.yml +++ b/.github/workflows/simulation-test.yml @@ -1,4 +1,4 @@ -name: "Simulation: Test" +name: "Simulation: Test" on: push: @@ -33,7 +33,7 @@ jobs: conda create --quiet --channel conda-forge --name decai-simulation --yes python=${{ matrix.python-version }} bokeh mkl mkl-service numpy phantomjs scikit-learn scipy tensorflow conda run --name decai-simulation python -m pip install --upgrade pip conda run --name decai-simulation pip install -e .[test] - + # pip install flake8 - name: Lint with flake8 run: | diff --git a/README.md b/README.md index eb6ecfa..b4096d4 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This repository contains: # FAQ/Concerns -## Aren't smart contracts just for simple code? +## Aren't smart contracts just for simple code? There are many options. We can restrict the framework to simple models: Perceptron, Naive Bayes, Nearest Centroid, etc. We can also combine off-chain computation with on-chain computation in a few ways such as: diff --git a/demo/client/src/components/model.js b/demo/client/src/components/model.js index a04a2c6..43e7441 100644 --- a/demo/client/src/components/model.js +++ b/demo/client/src/components/model.js @@ -341,7 +341,7 @@ class Model extends React.Component { } /** - * @param {Array[Number]} data + * @param {Array[Number]} data * @returns Normalized `data` using the result of the norm from the classifier contract. * The result is in the mapped space (multiplied by `this.state.toFloat`. */ @@ -513,7 +513,7 @@ class Model extends React.Component { if (isForTaking) { // Prediction must be wrong. canAttemptRefund = prediction !== data.classification - // Take the floor since that is what Solidity will do. + // Take the floor since that is what Solidity will do. const amountShouldGet = Math.floor(data.initialDeposit * this.state.numGood / this.state.totalGoodDataCount) if (amountShouldGet !== 0) { claimableAmount = amountShouldGet @@ -585,7 +585,6 @@ class Model extends React.Component { } /** - * * @param {string} transactionHash The transaction hash for the transacation that added the data. * @returns A representation of the original data. If the storage type is 'none' or the data cannot be found then `undefined` is returned. */ diff --git a/demo/client/src/ml-models/deploy-model.ts b/demo/client/src/ml-models/deploy-model.ts index 9a01859..11a2bd3 100644 --- a/demo/client/src/ml-models/deploy-model.ts +++ b/demo/client/src/ml-models/deploy-model.ts @@ -264,8 +264,7 @@ export class ModelDeployer { throw new Error(`Unrecognized model type: "${model.type}"`) } // Subtract 1 from the count because the first chunk has already been uploaded. - const notification = notify(`Please accept the prompt to upload classifier - weights [${i},${Math.min(i + chunkSize, weightsArray.length)}) (${i / chunkSize}/${Math.ceil(weightsArray.length / chunkSize) - 1})`) + const notification = notify(`Please accept the prompt to upload classifier weights [${i},${Math.min(i + chunkSize, weightsArray.length)}) (${i / chunkSize}/${Math.ceil(weightsArray.length / chunkSize) - 1})`) await transaction.send({ from: account, gas: this.gasLimit, diff --git a/demo/client/src/ml-models/model-interfaces.ts b/demo/client/src/ml-models/model-interfaces.ts index 17ccb25..6c7cda9 100644 --- a/demo/client/src/ml-models/model-interfaces.ts +++ b/demo/client/src/ml-models/model-interfaces.ts @@ -61,7 +61,7 @@ export class NearestCentroidModel extends Model { export class CentroidInfo { /** * @param centroid The average of all data points in the class. - * @param dataCount The number of samples in the class. + * @param dataCount The number of samples in the class. */ constructor( public centroid: number[], @@ -89,8 +89,8 @@ export class SparseNearestCentroidModel extends Model { export class SparseCentroidInfo { /** * @param centroid The average of all data points in the class. - * The feature indices should be integers but they are strings for convenience when loading from JSON. - * @param dataCount The number of samples in the class. + * The feature indices should be integers but they are strings for convenience when loading from JSON. + * @param dataCount The number of samples in the class. */ constructor( public centroid: { [featureIndex: string]: number }, diff --git a/demo/server.js b/demo/server.js index 9120dcc..3cb75be 100644 --- a/demo/server.js +++ b/demo/server.js @@ -163,7 +163,7 @@ initSqlJs().then(SQL => { // eslint-disable-next-line @typescript-eslint/no-empty-function fs.writeFile(dbPath, Buffer.from(db.export()), () => {}) } - + // Add a new accuracy record for a model app.post('/api/accuracy', jsonParser, (req, res) => { const body = req.body @@ -171,7 +171,7 @@ initSqlJs().then(SQL => { return res.sendStatus(200) }) - // Get the accuracy history + // Get the accuracy history app.get('/api/accuracy/model', (req, res) => { const { modelId } = req.query if (modelId != null) { diff --git a/simulation/README.md b/simulation/README.md index eabb637..73eea64 100644 --- a/simulation/README.md +++ b/simulation/README.md @@ -64,7 +64,7 @@ docker push 0xdeca10bcontainerreg.azurecr.io/public/samples/blockchain-ai/0xdeca Run: ```bash bokeh serve decai/simulation/simulate_imdb_perceptron.py -``` +``` Then open the browser to the address the above command tells you. It should be something like: [http://localhost:5006/simulate_imdb_perceptron](http://localhost:5006/simulate_imdb_perceptron). @@ -92,7 +92,7 @@ So instead of `PerceptronModule` put `NeuralNetworkModule`. Run `bokeh serve decai/simulation/simulate_imdb_neural_network.py` and open your browse to the displayed URL to try it out. # Testing -Setup the testing environment: +Setup the testing environment: ```bash pip install -e .[test] ``` diff --git a/simulation/decai/simulation/contract/incentive/prediction_market.py b/simulation/decai/simulation/contract/incentive/prediction_market.py index ae5bcba..78522cd 100644 --- a/simulation/decai/simulation/contract/incentive/prediction_market.py +++ b/simulation/decai/simulation/contract/incentive/prediction_market.py @@ -35,7 +35,7 @@ class MarketPhase(Enum): REWARD_RESTART = 4 """ - Same as `REWARD` but contributions have just been filtered out + Same as `REWARD` but contributions have just been filtered out and the iteration needs to restart with the remaining contributions. """ @@ -63,7 +63,7 @@ class _Contribution: """ Initially this is the amount deposited with this contribution. If contributions are not grouped by contributor, then while calculating rewards this gets updated to be the balance - for this particular contribution, to know if it should get kicked out of the reward phase. + for this particular contribution, to know if it should get kicked out of the reward phase. """ score: Optional[int] = field(default=None, init=False) @@ -121,7 +121,7 @@ class PredictionMarket(IncentiveMechanism): self.min_stake = 1 """ The minimum required amount to deposit. - Should be at least 1 to handle the worst case where the contribution takes the accuracy from 1 to 0. + Should be at least 1 to handle the worst case where the contribution takes the accuracy from 1 to 0. """ self.state = None diff --git a/simulation/setup.py b/simulation/setup.py index 490d47b..b7e6fe8 100644 --- a/simulation/setup.py +++ b/simulation/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup from setuptools import find_packages -# When publishing the Docker image, a script checks for the first line with "version=" to get the version. +# When publishing the Docker image, a script checks for the first line with "version" and an equals sign to get the version. version='1.0.0' install_requires = [