Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'shellcheck'
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Oct 19, 2020
2 parents 8212b83 + e4eec08 commit 49352a6
Show file tree
Hide file tree
Showing 47 changed files with 624 additions and 595 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ config-prod.json
**/.test-store
**/.tmp
**/cache/**
**/*.backup

# Data Storage
**/.bot-store/
Expand Down
1 change: 1 addition & 0 deletions modules/auth/ops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ENV HOME /root
RUN apk add --update --no-cache bash curl g++ gcc git jq make python
RUN npm config set unsafe-perm true && npm install -g [email protected]
RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/ed77b63706ea721766a62ff22d3a251d8b4a6a30/wait-for-it.sh > /bin/wait-for && chmod +x /bin/wait-for
ENV PATH="/root/node_modules/.bin:./node_modules/.bin:${PATH}"
COPY ops ops
COPY dist dist
ENTRYPOINT ["bash", "ops/entry.sh"]
47 changes: 28 additions & 19 deletions modules/auth/ops/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@
set -e

if [[ -d "modules/auth" ]]
then cd modules/auth
then cd modules/auth || exit 1
fi

########################################
# Convert secrets to env vars

if [[ -n "$VECTOR_JWT_SIGNER_PUBLIC_KEY" ]]
then echo "Using public key provided by env var"
elif [[ -n "$VECTOR_JWT_SIGNER_PUBLIC_KEY_FILE" ]]
then export VECTOR_JWT_SIGNER_PUBLIC_KEY="`cat $VECTOR_JWT_SIGNER_PUBLIC_KEY_FILE`"
then VECTOR_JWT_SIGNER_PUBLIC_KEY="$(cat "$VECTOR_JWT_SIGNER_PUBLIC_KEY_FILE")"
else echo "public key must be provided via either a secret or an env var." && exit 1
fi

if [[ -n "$VECTOR_JWT_SIGNER_PRIVATE_KEY" ]]
then echo "Using private key provided by env var"
elif [[ -n "$VECTOR_JWT_SIGNER_PRIVATE_KEY_FILE" ]]
then export VECTOR_JWT_SIGNER_PRIVATE_KEY="`cat $VECTOR_JWT_SIGNER_PRIVATE_KEY_FILE`"
then VECTOR_JWT_SIGNER_PRIVATE_KEY="$(cat "$VECTOR_JWT_SIGNER_PRIVATE_KEY_FILE")"
else echo "private key must be provided via either a secret or an env var." && exit 1
fi

# Ensure keys have proper newlines inserted (bc newlines are stripped from env vars)
export VECTOR_JWT_SIGNER_PRIVATE_KEY=`
echo $VECTOR_JWT_SIGNER_PRIVATE_KEY | tr -d '\n\r' |\
sed 's/-----BEGIN RSA PRIVATE KEY-----/\n-----BEGIN RSA PRIVATE KEY-----\n/' |\
sed 's/-----END RSA PRIVATE KEY-----/\n-----END RSA PRIVATE KEY-----\n/'`
VECTOR_JWT_SIGNER_PRIVATE_KEY=$(
echo "$VECTOR_JWT_SIGNER_PRIVATE_KEY" |\
tr -d '\n\r' |\
sed 's/-----BEGIN RSA PRIVATE KEY-----/\n-----BEGIN RSA PRIVATE KEY-----\n/' |\
sed 's/-----END RSA PRIVATE KEY-----/\n-----END RSA PRIVATE KEY-----\n/'
)

VECTOR_JWT_SIGNER_PUBLIC_KEY=$(
echo "$VECTOR_JWT_SIGNER_PUBLIC_KEY" |\
tr -d '\n\r' |\
sed 's/-----BEGIN PUBLIC KEY-----/\n-----BEGIN PUBLIC KEY-----\n/' | \
sed 's/-----END PUBLIC KEY-----/\n-----END PUBLIC KEY-----\n/'
)

export VECTOR_JWT_SIGNER_PUBLIC_KEY=`
echo $VECTOR_JWT_SIGNER_PUBLIC_KEY | tr -d '\n\r' |\
sed 's/-----BEGIN PUBLIC KEY-----/\n-----BEGIN PUBLIC KEY-----\n/' | \
sed 's/-----END PUBLIC KEY-----/\n-----END PUBLIC KEY-----\n/'`
export VECTOR_JWT_SIGNER_PRIVATE_KEY
export VECTOR_JWT_SIGNER_PUBLIC_KEY

node_bin="`pwd`/node_modules/.bin"
nodemon="$node_bin/nodemon"
pino="$node_bin/pino-pretty"
########################################
# Launch it

if [[ "$VECTOR_PROD" == "true" ]]
then
Expand All @@ -42,15 +51,15 @@ then

else
echo "Starting node in dev-mode"
exec $nodemon \
exec nodemon \
--delay 1 \
--exitcrash \
--ignore *.test.ts \
--ignore *.spec.ts \
--ignore *.swp \
--ignore ./**/*.test.ts \
--ignore ./**/*.spec.ts \
--ignore ./**/*.swp \
--legacy-watch \
--polling-interval 1000 \
--watch src \
--exec ts-node \
./src/index.ts | $pino
./src/index.ts | pino-pretty
fi
3 changes: 2 additions & 1 deletion modules/browser-node-test-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Wallet, constants } from "ethers";
import { Col, Divider, Row, Spin, Statistic, Input, Typography, Table, Button } from "antd";

import "./App.css";
import { config } from "./config";
import { FullChannelState } from "@connext/vector-types";

import { config } from "./config";

const logger = pino();
const wallet = Wallet.fromMnemonic(config.mnemonic!);
const signer = new ChannelSigner(wallet.privateKey);
Expand Down
1 change: 1 addition & 0 deletions modules/browser-node-test-ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";

import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
Expand Down
38 changes: 19 additions & 19 deletions modules/browser-node-test-ui/src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// opt-in, read https://bit.ly/CRA-PWA

const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
);

type Config = {
Expand All @@ -26,11 +26,11 @@ type Config = {
};

export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
process.env.PUBLIC_URL,
window.location.href
window.location.href,
);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
Expand All @@ -39,7 +39,7 @@ export function register(config?: Config) {
return;
}

window.addEventListener('load', () => {
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

if (isLocalhost) {
Expand All @@ -50,8 +50,8 @@ export function register(config?: Config) {
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://bit.ly/CRA-PWA",
);
});
} else {
Expand All @@ -72,14 +72,14 @@ function registerValidSW(swUrl: string, config?: Config) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
"New content is available and will be used when all " +
"tabs for this page are closed. See https://bit.ly/CRA-PWA.",
);

// Execute callback
Expand All @@ -90,7 +90,7 @@ function registerValidSW(swUrl: string, config?: Config) {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log("Content is cached for offline use.");

// Execute callback
if (config && config.onSuccess) {
Expand All @@ -102,21 +102,21 @@ function registerValidSW(swUrl: string, config?: Config) {
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
console.error("Error during service worker registration:", error);
});
}

function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' }
headers: { "Service-Worker": "script" },
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
const contentType = response.headers.get("content-type");
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
(contentType != null && contentType.indexOf("javascript") === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
Expand All @@ -131,13 +131,13 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
"No internet connection found. App is running in offline mode.",
);
});
}

export function unregister() {
if ('serviceWorker' in navigator) {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
Expand Down
2 changes: 1 addition & 1 deletion modules/browser-node-test-ui/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import "@testing-library/jest-dom/extend-expect";
1 change: 0 additions & 1 deletion modules/browser-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"copy-webpack-plugin": "6.2.1",
"fake-indexeddb": "3.1.2",
"mocha": "8.1.3",
"nodemon": "2.0.4",
"pino-pretty": "4.3.0",
"ts-loader": "8.0.4",
"ts-mocha": "7.0.0",
Expand Down
1 change: 1 addition & 0 deletions modules/contracts/ops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ENV HOME /root
RUN apk add --update --no-cache bash curl g++ gcc git jq make python
RUN npm config set unsafe-perm true && npm install -g [email protected]
RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/ed77b63706ea721766a62ff22d3a251d8b4a6a30/wait-for-it.sh > /bin/wait-for && chmod +x /bin/wait-for
ENV PATH="/root/node_modules/.bin:./node_modules/.bin:${PATH}"
COPY ops/package.json package.json
RUN npm install
COPY ops/entry.sh entry.sh
Expand Down
39 changes: 20 additions & 19 deletions modules/contracts/ops/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ address_book="${ADDRESS_BOOK:-/data/address-book.json}"
data_dir="${DATA_DIR:-/tmp}"
chain_id="${CHAIN_ID:-1337}"
mnemonic="${MNEMONIC:-candy maple cake sugar pudding cream honey rich smooth crumble sweet treat}"
evm="${EVM:-`if [[ "$chain_id" == "1337" ]]; then echo "ganache"; else echo "buidler"; fi`}"
evm="${EVM:-$(if [[ "$chain_id" == "1337" ]]; then echo "ganache"; else echo "buidler"; fi)}"

chain_addresses="`dirname $address_book`/chain-addresses.json"
chain_addresses="$(dirname "$address_book")/chain-addresses.json"

cwd="`pwd`"
mkdir -p $data_dir /data /tmp
touch $address_book
rm -f $chain_addresses
cwd="$(pwd)"
mkdir -p "$data_dir" /data /tmp
touch "$address_book"
rm -f "$chain_addresses"

if [[ "$evm" == "buidler" ]]
then
Expand All @@ -27,7 +27,7 @@ then
defaultNetwork: "buidlerevm",
networks: {
buidlerevm: {
chainId: '$chain_id',
chainId: '"$chain_id"',
loggingEnabled: false,
accounts: [{
privateKey: "0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
Expand All @@ -37,39 +37,40 @@ then
},
},
}' > /tmp/buidler.config.js
launch="$cwd/node_modules/.bin/buidler node --config /tmp/buidler.config.js --hostname 0.0.0.0 --port 8545 "
launch="buidler node --config /tmp/buidler.config.js --hostname 0.0.0.0 --port 8545"
cd /tmp # bc we need to run buidler node in same dir as buidler.config.js

elif [[ "$evm" == "ganache" ]]
then
echo "Using ganache EVM"
launch=$cwd'/node_modules/.bin/ganache-cli \
--db='$data_dir' \
launch="ganache-cli \
--db=$data_dir \
--defaultBalanceEther=2000000000 \
--gasPrice=100000000000 \
--mnemonic="'"$mnemonic"'" \
--networkId='$chain_id' \
--mnemonic=\"$mnemonic\" \
--networkId=$chain_id \
--host 0.0.0.0 \
--port=8545 '
expose=""
--port=8545"

else
echo 'Expected $EVM to be either "ganache" or "buidler"'
echo 'Expected EVM to be either "ganache" or "buidler"'
exit 1
fi

echo "Starting isolated testnet to migrate contracts.."
echo "Starting testnet to migrate contracts.."
eval "$launch > /tmp/evm.log &"
pid=$!

echo "Waiting for local testnet to wake up.."
wait-for -q -t 60 localhost:8545 2>&1 | sed '/nc: bad address/d'

# Because stupid ganache hardcoded it's chainId, prefer this env var over ethProvider.getNetwork()
export REAL_CHAIN_ID=$chain_id

echo "Deploying contracts.."
node $cwd/dist/cli.js migrate --address-book "$address_book" --mnemonic "$mnemonic"
node "$cwd/dist/cli.js" migrate --address-book "$address_book" --mnemonic "$mnemonic"

node $cwd/dist/cli.js new-token --address-book "$address_book" --mnemonic "$mnemonic"
node "$cwd/dist/cli.js" new-token --address-book "$address_book" --mnemonic "$mnemonic"

# jq docs: https://stedolan.github.io/jq/manual/v1.5/#Builtinoperatorsandfunctions
function fromAddressBook {
Expand All @@ -84,6 +85,6 @@ function fromAddressBook {
';
}

cat $address_book | fromAddressBook > $chain_addresses
fromAddressBook < "$address_book" > "$chain_addresses"

wait $pid
16 changes: 9 additions & 7 deletions modules/router/ops/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
set -e

if [[ -d "modules/router" ]]
then cd modules/router
then cd modules/router || exit 1
fi

########################################
# Convert secrets to env vars

if [[ -z "$VECTOR_PG_PASSWORD" && -n "$VECTOR_PG_PASSWORD_FILE" ]]
then export VECTOR_PG_PASSWORD="`cat $VECTOR_PG_PASSWORD_FILE`"
then
VECTOR_PG_PASSWORD="$(cat "$VECTOR_PG_PASSWORD_FILE")"
export VECTOR_PG_PASSWORD
fi

export VECTOR_DATABASE_URL="postgresql://$VECTOR_PG_USERNAME:$VECTOR_PG_PASSWORD@${VECTOR_PG_HOST}:$VECTOR_PG_PORT/$VECTOR_PG_DATABASE"
Expand All @@ -19,10 +21,10 @@ export VECTOR_DATABASE_URL="postgresql://$VECTOR_PG_USERNAME:$VECTOR_PG_PASSWORD

db="$VECTOR_PG_HOST:$VECTOR_PG_PORT"
echo "Waiting for database at $db"
wait-for -q -t 60 $db 2>&1 | sed '/nc: bad address/d'
wait-for -q -t 60 "$db" 2>&1 | sed '/nc: bad address/d'

echo "Pinging node at $VECTOR_NODE_URL"
while [[ -z "`curl -k -m 5 -s $VECTOR_NODE_URL/ping || true`" ]]
while [[ -z "$(curl -k -m 5 -s "$VECTOR_NODE_URL/ping" || true)" ]]
do sleep 1
done

Expand All @@ -40,9 +42,9 @@ else
exec nodemon \
--delay 1 \
--exitcrash \
--ignore *.test.ts \
--ignore *.spec.ts \
--ignore *.swp \
--ignore ./**/*.test.ts \
--ignore ./**/*.spec.ts \
--ignore ./**/*.swp \
--legacy-watch \
--polling-interval 1000 \
--watch src \
Expand Down
Loading

0 comments on commit 49352a6

Please sign in to comment.