Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: schedule a Docker deployment test #4133

Merged
merged 12 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/actions/restore-golang/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Agoric SDK restore Golang build
description: 'Set up Golang environment and restore cached built files'

inputs:
go-version:
description: 'The version of Go to use'
required: true

runs:
using: composite
steps:
- name: set default environment variables
run: echo GOPATH="$HOME/go" >> $GITHUB_ENV
shell: bash
- uses: actions/checkout@v2
with:
clean: 'false'
submodules: 'true'
- uses: actions/setup-go@v2
with:
go-version: ${{ inputs.go-version }}
- name: cache Go modules
uses: actions/cache@v1
with:
path: ${{ env.GOPATH }}/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('packages/cosmic-swingset/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: go mod download
run: go mod download
shell: bash
if: steps.built.outputs.cache-hit != 'true'
4 changes: 2 additions & 2 deletions .github/actions/restore-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ runs:
with:
path: .
key: ${{ runner.os }}-${{ inputs.node-version }}-built-${{ github.sha }}
- name: yarn install
run: yarn install
- name: yarn install --frozen-lockfile
run: yarn install --frozen-lockfile
shell: bash
if: steps.built.outputs.cache-hit != 'true'
- name: yarn build
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/deployment-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Chain deployment test

on:
schedule:
- cron: "0 0 * * *"

jobs:
deployment-test:
runs-on: ubuntu-18.04 # trusty
steps:
- uses: actions/checkout@v2
with:
clean: 'false'
- uses: ./.github/actions/restore-golang
with:
go-version: 1.15
- uses: ./.github/actions/restore-node
with:
node-version: 14.x
- name: Build cosmic-swingset dependencies
run: |
# Some of our build relies on /usr/src/agoric-sdk
set -e
sudo mv "$GITHUB_WORKSPACE" /usr/src/agoric-sdk
ln -s /usr/src/agoric-sdk "$GITHUB_WORKSPACE"
cd /usr/src/agoric-sdk/packages/cosmic-swingset
make install
working-directory: /
- run: sudo ./packages/deployment/scripts/install-deps.sh
working-directory: /usr/src/agoric-sdk
- run: /usr/src/agoric-sdk/packages/deployment/scripts/integration-test.sh
working-directory: ~
env:
NETWORK_NAME: chaintest
2 changes: 1 addition & 1 deletion .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# 'yarn install' must be done at the top level, to build all the
# cross-package symlinks
- name: yarn install
run: yarn install
run: yarn install --frozen-lockfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- name: check dependencies
run: yarn check-dependencies
# 'yarn build' loops over all workspaces
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/test-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Set up Go 1.15
uses: actions/setup-go@v1
- uses: ./.github/actions/restore-golang
with:
go-version: 1.15
- name: cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('packages/cosmic-swingset/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: go test
run: cd golang && go test ./...
14 changes: 2 additions & 12 deletions packages/deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@ ARG REPO=agoric/agoric-sdk

FROM $REPO:$TAG

# Install Terraform.
ARG TERRAFORM_VERSION=0.11.14
RUN curl https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip > terraform.zip && \
unzip -d /usr/local/bin/ terraform.zip && rm -f terraform.zip

# Install Ansible.
RUN echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && \
apt-get update --allow-releaseinfo-change -y && \
apt-get install -y ansible rsync curl sudo gnupg2 jq python-jmespath && \
apt-get clean -y
RUN /usr/src/agoric-sdk/packages/deployment/scripts/install-deps.sh

# # Copy journalbeat for logging support
# COPY --from=go-build /go/bin/journalbeat /usr/local/bin/

WORKDIR /usr/src/agoric-sdk/packages/deployment
RUN ln -sf $PWD/src/entrypoint.js /usr/local/bin/ag-setup-cosmos
RUN ln -sf $PWD/bin/ag-setup-cosmos /usr/local/bin/ag-setup-cosmos

WORKDIR /data/chains

Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/ansible/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
strategy: free
vars:
- service: ag-chain-cosmos
- HELPER_BINARY: "{{lookup('env', 'GOPATH') or '/usr/local'}}/bin/agd"
- APPDIR: "{{lookup('pipe', 'pwd')}}/../.."
- HELPER_BINARY: "{{lookup('env', 'GOBIN') or ((lookup('env', 'GOPATH') or '/usr/local') + '/bin')}}/agd"
roles:
- stop
- copy
Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/ansible/copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
vars:
- service: ag-chain-cosmos
- APPDIR: "{{lookup('pipe', 'pwd')}}/../.."
- HELPER_BINARY: "{{lookup('env', 'GOPATH') or '/usr/local'}}/bin/agd"
- HELPER_BINARY: "{{lookup('env', 'GOBIN') or ((lookup('env', 'GOPATH') or '/usr/local') + '/bin')}}/agd"
roles:
- copy

2 changes: 1 addition & 1 deletion packages/deployment/ansible/prepare-cosmos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
vars:
- service: ag-chain-cosmos
- CHAIN_NAME: "{{ lookup('file', SETUP_HOME + '/' + service + '/chain-name.txt') }}"
- HELPER_BINARY: "{{lookup('env', 'GOPATH') or '/usr/local'}}/bin/agd"
- HELPER_BINARY: "{{lookup('env', 'GOBIN') or ((lookup('env', 'GOPATH') or '/usr/local') + '/bin')}}/agd"
- APPDIR: "{{lookup('pipe', 'pwd')}}/../.."
roles:
- copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ OP=$1
shift

ACH="agd --home=$FAUCET_HOME --log_level=info"
FAUCET_ADDR=$($ACH keys show -a faucet)
FAUCET_ADDR=$($ACH keys show --keyring-backend=test -a faucet)

case $OP in
show-faucet-address)
echo "$FAUCET_ADDR"
exit 0
;;
esac

chainName=$(cat "$thisdir/ag-chain-cosmos/chain-name.txt")
IFS=, read -r -a origRpcAddrs <<<"$(AG_SETUP_COSMOS_HOME=$thisdir ag-setup-cosmos show-rpcaddrs)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
register: staker_balance
until: staker_balance.stdout.find(staking_denom) != -1
delay: 10
retries: 60
retries: 20 # 200 seconds === 3m20s

- name: "Create validators for {{ STAKER }}-*"
become_user: "{{ service }}"
Expand Down
1 change: 1 addition & 0 deletions packages/deployment/bin/ag-setup-cosmos
70 changes: 70 additions & 0 deletions packages/deployment/scripts/docker-deployment.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#! /usr/bin/env node
/* global process */
// Get a deployment.json for a 2-node docker setup.

const DEFAULT_NUM_VALIDATORS = 2;
const DEFAULT_NETWORK_NAME = 'localtest';

const NUM_VALIDATORS = process.argv[2] || DEFAULT_NUM_VALIDATORS;

const NETWORK_NAME = process.env.NETWORK_NAME || DEFAULT_NETWORK_NAME;

// Add in DOCKER_VOLUMES=host_path:container_path,host_path2:container_path2,...
const ADD_VOLUMES = (process.env.DOCKER_VOLUMES || '')
.split(',')
.flatMap(volumeSpec => {
const splitVolumeSpec = volumeSpec.split(':');
if (splitVolumeSpec.length < 2) {
// No specification found.
return [];
}

const [hostPath, ...rest] = splitVolumeSpec;
return [
{
host_path: hostPath,
container_path: rest.join(':'),
},
];
});

const deployment = {
PLACEMENTS: [
[
'docker1',
{
default: 2,
},
],
],
PLACEMENT_PROVIDER: {
docker1: 'docker',
},
SSH_PRIVATE_KEY_FILE: 'id_ecdsa',
DETAILS: {
VOLUMES: {
docker1: [
{
host_path: '/sys/fs/cgroup',
container_path: '/sys/fs/cgroup',
},
...ADD_VOLUMES,
],
},
},
OFFSETS: {
docker1: 0,
},
ROLES: {
docker1: 'validator',
},
DATACENTERS: {
docker1: new Array(NUM_VALIDATORS).fill('default'),
},
PROVIDER_NEXT_INDEX: {
docker: 1,
},
NETWORK_NAME,
};

process.stdout.write(`${JSON.stringify(deployment, null, 2)}\n`);
46 changes: 46 additions & 0 deletions packages/deployment/scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /bin/bash
set -ueo pipefail

# Install Terraform.
TERRAFORM_VERSION=0.11.14

uname_s=$(uname -s | tr '[:upper:]' '[:lower:]')

case $uname_s in
*) TERRAFORM_OS=$uname_s ;;
esac

uname_m=$(uname -m)
case $uname_m in
x86_64) TERRAFORM_ARCH=amd64 ;;
*) TERRAFORM_ARCH=$uname_m ;;
esac

TERRAFORM_RELEASE=terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS}_${TERRAFORM_ARCH}
TERRAFORM_URL=https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/${TERRAFORM_RELEASE}.zip

# Extract, then delete temporary file.
(
terraform_zip=$(mktemp -t terraform)
trap "rm -f \"\$terraform_zip\"" EXIT
echo "$terraform_zip"
exit 1
curl "$TERRAFORM_URL" > "$terraform_zip"
unzip -od /usr/local/bin/ "$terraform_zip"
)

# Install Ansible.
if test -d /etc/apt; then
echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt-get update --allow-releaseinfo-change -y
apt-get install -y ansible rsync curl sudo gnupg2 jq
apt-get clean -y
elif test "$uname_s" == darwin; then
brew update
brew install ansible rsync curl gnupg2 jq
brew cleanup
else
echo "Don't know how to install Ansible, so I'm skipping..."
exit 1
fi
20 changes: 20 additions & 0 deletions packages/deployment/scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash
set -ueo pipefail

real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
mhofman marked this conversation as resolved.
Show resolved Hide resolved
thisdir=$(cd "$(dirname -- "$real0")" > /dev/null && pwd -P)

export NETWORK_NAME=${NETWORK_NAME-localtest}

mkdir -p "$NETWORK_NAME/setup"
cd "$NETWORK_NAME/setup"

# Speed up the docker deployment by pre-mounting /usr/src/agoric-sdk.
DOCKER_VOLUMES="$(cd "$thisdir/../../.." > /dev/null && pwd -P):/usr/src/agoric-sdk" \
"$thisdir/docker-deployment.cjs" > deployment.json

# Set up the network from our above deployment.json.
"$thisdir/setup.sh" init --noninteractive

# Go ahead and bootstrap.
exec "$thisdir/setup.sh" bootstrap ${1+"$@"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to exec here?

Should the test be nice and cleanly stop the bootstrapped chain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are reasonable improvements, but not necessary for the Github Actions test, so I didn't do them.

18 changes: 18 additions & 0 deletions packages/deployment/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /bin/bash
# setup.sh - Run the local ag-setup-cosmos with arguments
set -ueo pipefail

real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
thisdir=$(cd "$(dirname -- "$real0")" > /dev/null && pwd -P)

NETWORK_NAME=${NETWORK_NAME-localtest}
export NETWORK_NAME

export AG_SETUP_COSMOS_NAME=$NETWORK_NAME
export AG_SETUP_COSMOS_HOME="$PWD"

# Put our bindir into the PATH so that children can find ag-setup-cosmos.
export PATH="$thisdir/../bin:$PATH"

# Run our setup command.
exec ag-setup-cosmos ${1+"$@"}
12 changes: 7 additions & 5 deletions packages/deployment/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,12 @@ const doInit = ({
}) => async (progname, args) => {
const { needDoRun, cwd, chdir } = running;
const PROVIDERS = makeProviders({ env, inquirer, wr, setup, fetch });
let {
_: [dir, overrideNetworkName],
} = parseArgs(args.slice(1));

const { _: parsedArgs, noninteractive } = parseArgs(args.slice(1), {
boolean: ['noninteractive'],
});
let [dir, overrideNetworkName] = parsedArgs;

if (!dir) {
dir = setup.SETUP_HOME;
}
Expand Down Expand Up @@ -323,8 +326,7 @@ const doInit = ({
});
config.NETWORK_NAME = overrideNetworkName;

// eslint-disable-next-line no-constant-condition
while (true) {
while (!noninteractive) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this halts!

// eslint-disable-next-line no-await-in-loop
const { ROLE, ...rest } = await askPlacement({ inquirer })(
config.PLACEMENTS,
Expand Down
Loading