# Introduction * OpenRelay was designed to run in containers * Docker drastically simplifes our: * Development process * Builds * Deployments * Service Management * Autoscaling * ...
# What is Docker? Note: This is a very quick, rough overview. Much more information available on Docker.
# Image * A snapshot of the necessary files to run a service * Must include **ALL** user-space dependencies * Defined by a "Dockerfile"
# Image Registry * Images can be uploaded to a shared registry * Public Registry: **hub.docker.com** * Host your own private registry * Easily pull images from a registry
# Container * "Live" version of an image running on the host kernel * Containers do not touch the host userspace * Generally only one process per container * Started fresh from image with each execution Note: * When a container starts, it will pull the image from a registry if necessary * When running a container, you can set lifecycle rules like restarting on failure.
# Stack * A collection of containers networked together * May run on the same host, or networked cluster * Containers communicate over network protocols
# Questions about Docker? * Images * Registries * Containers * Stacks
# OpenRelay Images * OpenRelay is written in Go * Go has some neat properties when it comes to Docker

Typical Docker File


							FROM ubuntu:12.04

							MAINTAINER Kimbro Staken version: 0.1

							RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*

							ENV APACHE_RUN_USER www-data
							ENV APACHE_RUN_GROUP www-data
							ENV APACHE_LOG_DIR /var/log/apache2

							EXPOSE 80

							CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
						

OpenRelay Dockerfile


							FROM scratch

							COPY bin/delayrelay /delayrelay

							CMD ["/delayrelay"]

						

Multistage Builds


							FROM golang:1.8 as corebuild
							RUN mkdir -p /go/src/github.com/notegio/openrelay
							WORKDIR /go/src/github.com/notegio/openrelay
							COPY . .
							RUN make clean bin

							FROM scratch
							COPY --from=corebuild /go/src/github.com/notegio/openrelay/bin/delayrelay /delayrelay
							CMD ["/delayrelay"]
						
## Questions about OpenRelay's Images? * Typical Images * Go Images * Multistage Builds
# OpenRelay Development Stack * Let's run OpenRelay's development stack

Development Environment


							$ git clone https://github.com/notegio/openrelay.git
							$ cd openrelay/

							$ git checkout 0xv2-support

							$ docker-compose -f docker-compose-testrpc.yml build
							$ docker-compose -f docker-compose-testrpc.yml up
							^C
							$ docker-compose -f docker-compose-testrpc.yml rm
						

Compose File


version: "3"
services:
  redis:
    image: redis:alpine
    ports:
      - "6379"
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
  postgres:
    image: postgres
    ports:
      - "5432"
    environment:
      POSTGRES_PASSWORD: secret
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
  ethnode:
    build:
      context: ./
      dockerfile: Dockerfile.testrpc
    ports:
      - "18545:8545"
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
  ingest:
    build:
      context: ./
      dockerfile: Dockerfile.ingest
    image: "openrelay/ingest:${TAG:-latest}"
    ports:
      - "8081:8080"
    command: ["/ingest", "${REDIS_HOST:-redis:6379}", "C22d5b2951DB72B44CFb8089bb8CD374A3c354eA", "queue://ingest"]
    depends_on:
      - redis
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
  exchangesplitter:
    build:
      context: ./
      dockerfile: Dockerfile.exchangesplitter
    image: "openrelay/exchangesplitter:${TAG:-latest}"
    command: ["/exchangesplitter", "${REDIS_HOST:-redis:6379}", "queue://ingest", "queue://canceluptocheck", "0x1dad4783cf3fe3085c1426157ab175a6119a04ba=queue://canceluptocheck-othernet"]
    depends_on:
      - redis
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
...

						
# Notes * Uses Ganache to simulate Ethereum network * Standard set of test accounts * Pre-deployed contracts * Pre-distributed ETH / token balances * Exposed Services: * Ingest: `localhost:8081` * Search: `localhost:8082` * Ethereum RPC: `localhost:18545`

Upload Order


							massive 0x expiration --input v2_unformatted_transaction.json --duration 864000 | \
							massive 0x setExchange --testrpc | \
							massive 0x getFees --maker-share .5 --target=http://localhost:8081 | \
							massive 0x setSalt | \
							massive 0x sign --replace-on-mismatch test-privkey | \
							massive 0x setAllowance --unlimited http://localhost:18545 test-privkey | \
							massive 0x upload --target=http://localhost:8081
						

Mine Some Blocks


							curl -X POST --data '{"jsonrpc":"2.0","method":"evm_mine","params":[],"id":1}' \
							     -H "Content-Type: application/json" http://localhost:18545
						

Search for Orders


							curl -L http://localhost:8082/v1/orders
						
## Questions about the development environment? * Running the dev environment * The docker-compose-testrpc.yml * Interacting with the development OpenRelay * Ganache test network
# Production * Push images to **Docker Hub** * Deployed on AWS with **Elastic Container Service** * **CloudFormation** stack to manage hosts & containers * Logging to **Cloudwatch** * Add Spot Instances for extra capacity
# Next Week * Options * Contract Code * Web3 Examples * Microservice Code