swindon 0.7.8

An HTTP edge (frontend) server with smart websockets support
containers:
  xenial:
    setup:
    - !Ubuntu xenial
    - !UbuntuUniverse
    - &pkgs !Install
      - make
      - gcc
      - libc6-dev
      - zlib1g-dev
      - libssl-dev
      - libcurl4-openssl-dev
      - ca-certificates
      - libcurl3
      - pkg-config
      - git  # to build package
      - lsb-release  # to build package
      - vim  # to edit release notes
    - &rust !TarInstall
      url: https://static.rust-lang.org/dist/rust-1.23.0-x86_64-unknown-linux-gnu.tar.gz
      script: "./install.sh --prefix=/usr \
               --components=rustc,rust-std-x86_64-unknown-linux-gnu,cargo"
    - !TarInstall
      url: "https://static.rust-lang.org/dist/rust-std-1.23.0-x86_64-unknown-linux-musl.tar.gz"
      script: "./install.sh --prefix=/musl \
               --components=rust-std-x86_64-unknown-linux-musl"
    - !Sh 'ln -s /musl/lib/rustlib/x86_64-unknown-linux-musl /usr/lib/rustlib/x86_64-unknown-linux-musl'
    - !Install [musl-tools]
    - &bulk !Tar
      url: "https://github.com/tailhook/bulk/releases/download/v0.4.9/bulk-v0.4.9.tar.gz"
      sha256: 23471a9986274bb4b7098c03e2eb7e1204171869b72c45385fcee1c64db2d111
      path: /
    - !EnsureDir /cargo
    environ: &environ
      CARGO_HOME: /cargo
    volumes: &volumes
      /cargo: !Persistent { name: cargo }


  trusty:
    setup:
    - !Ubuntu trusty
    - *pkgs
    - *rust
    - *bulk
    - !EnsureDir /cargo
    environ: *environ
    volumes: *volumes

  precise:
    setup:
    - !Ubuntu precise
    - *pkgs
    - *rust
    - *bulk
    - !EnsureDir /cargo
    environ: *environ
    volumes: *volumes

  sphinx:
    setup:
    - !Alpine v3.5
    - !Install [make]
    - !PipConfig { dependencies: true }
    - !Py2Install [sphinx]
    - !Py2Requirements "docs/requirements.txt"
    auto-clean: true

  httpbin:
    setup:
    - !Alpine v3.4
    - !PipConfig {dependencies: true}
    - !Py3Install
      - httpbin
      - gunicorn
      - gevent
    auto-clean: true

  wrk:
    setup:
    - !Container xenial
    - !UbuntuUniverse
    - !Install
      - wrk

  message-board:  # example
    setup:
    - !Alpine v3.4
    - !Install [ca-certificates]
    - !PipConfig { dependencies: true }
    - !Py3Requirements "examples/message-board/requirements.txt"

  message-board2:  # example
    setup:
    - !Alpine v3.6
    - !Install [ca-certificates]
    - !Install [nodejs, nodejs-npm]
    - !PipConfig { dependencies: true }
    - !Py3Requirements "examples/message-board2/requirements.txt"
    - !NpmDependencies
      file: "examples/message-board2/package.json"
    environ:
      NODE_PATH: /usr/lib/node_modules

  presence:  # example
    setup:
    - !Alpine v3.6
    - !Install [ca-certificates]
    - !Install [nodejs, nodejs-npm]
    - !PipConfig { dependencies: true }
    - !Py3Requirements "examples/presence/requirements.txt"
    - !NpmDependencies
      file: "examples/presence/package.json"

    # temporary for git install
    - !Sh |
        cd /usr/lib/node_modules/swindon
        npm install
        npm run build
    environ:
      NODE_PATH: /usr/lib/node_modules

  multi-user-chat:  # example
    setup:
    - !Alpine v3.4
    - !Install [ca-certificates]
    - !PipConfig { dependencies: true }
    - !Py3Requirements "examples/multi-user-chat/requirements.txt"
    - !NpmDependencies
      file: "examples/multi-user-chat/package.json"
    environ:
      NODE_PATH: /usr/lib/node_modules

  multi-user-chat2:  # example
    setup:
    - !Alpine v3.6
    - !Install [ca-certificates]
    - !PipConfig { dependencies: true }
    - !Py3Requirements "examples/multi-user-chat2/requirements.txt"
    - !NpmDependencies
      file: "examples/multi-user-chat2/package.json"
    environ:
      NODE_PATH: /usr/lib/node_modules

  pytest:
    setup:
    - !Ubuntu xenial
    - !AptTrust
      keys: [4AB0F789CBA31744CC7DA76A8CF63AD3F06FC659]
    - !UbuntuPPA jonathonf/python-3.6
    - !Install [libcurl3, libdw1, python3.6, python3.6-dev, ca-certificates]
    - !BuildDeps
      - wget
      - make
      - cmake
      - gcc
      - g++
      - pkg-config
      - libdw-dev
      - libiberty-dev
      - zlib1g-dev
      - libcurl4-openssl-dev
      - binutils-dev
      - python
    - !TarInstall
      url: https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
      script: |
        mkdir build
        cd build
        cmake .. -DCMAKE_INSTALL_PREFIX=/usr
        make
        make install
    - !PipConfig
      dependencies: true
      install-python: false
      python-exe: /usr/bin/python3.6
    - !Py3Requirements "tests/requirements.txt"

commands:

  rustc: !Command
    container: xenial
    description: Run rustc command
    run: [rustc]

  cargo: !Command
    container: xenial
    symlink-name: cargo
    description: Run Cargo command
    run: [cargo]

  make: !Command
    container: xenial
    description: Build project
    run: [cargo, build]

  cargo-test: !Command
    container: xenial
    description: Run CI tests (with crates in container)
    environ:
      RUST_BACKTRACE: 1
    run: [cargo, test]

  func-test: &functest !Command
    container: pytest
    work-dir: /work/tests
    prerequisites: [make]
    user-id: 1
    environ:
      AIOHTTP_NO_EXTENSIONS: 1
    run: [pytest]

  test: !Command
    prerequisites: [make, cargo-test]
    <<: *functest

  run: &run !Command
    container: xenial
    description: Run
    environ:
      RUST_BACKTRACE: 1
    run:
    - cargo
    - run
    - --bin=swindon
    - "--"
    - --verbose
    - --config=example.yaml

  bench-run: &bench-run !Command
    container: xenial
    description: Run swindon for benchmarks (--release and specific config)
    environ:
      RUST_BACKTRACE: 1
    run:
    - cargo
    - run
    - --release
    - --bin=swindon
    - "--"
    - --verbose
    - --config=example.yaml

  devd: !Command
    container: xenial
    description: Run swindon-dev (useless without parameters)
    run:
    - cargo
    - run
    - --bin=swindon-dev
    - "--"

  debug-run: !Command
    container: xenial
    description: Run with debugging enabled
    run: |
      cargo build
      echo Starting...
      RUST_LOG=debug exec ./target/debug/swindon --config=example.yaml

  httpbin: &httpbin !Command
    container: httpbin
    description: Run httpbin instance
    run:
    - gunicorn
    - httpbin:app
    - -b
    - example.com:5000
    - --log-level
    - debug
    - -k
    - gevent

  run-with-proxy: !Supervise
    description: Run swindon & httpbin
    children:
      httpbin: *httpbin
      swindon: *run

  run-two: !Supervise
    description: Run two instances of swindon with replication
    children:
      inst1: !Command
        <<: *run
        run:
        - cargo
        - run
        - --bin=swindon
        - "--"
        - --verbose
        - --config=example-peer-A.yaml
      inst2: !Command
        <<: *run
        run:
        - cargo
        - run
        - --bin=swindon
        - "--"
        - --verbose
        - --config=example-peer-B.yaml

  _cargo-doc: !Command
    container: xenial
    description: build rust docs
    environ:
      CARGO_HOME: /cargo
    run: |
      cargo doc --no-deps
  _copy-doc: !Command
    container: xenial
    description: copy rust docs into sphinx build dir
    prerequisites: [_cargo-doc]
    run: |
      mkdir -p docs/_build/html
      [ -d docs/_build/html/rust_api ] && rm -r docs/_build/html/rust_api
      cp -rT target/doc docs/_build/html/rust_api
  _cargo-new: !Command
    container: xenial
    description: Create New Crate lib
    work-dir: /work/deps
    run: [cargo, new, --vcs, git]

  doc: !Command
    container: sphinx
    description: Build documentation
    prerequisites: [_copy-doc]
    epilog: |
      ---------------------------------------------------
      Run this to open docs in browser:
      xdg-open $(pwd)/docs/_build/html/index.html
    work-dir: docs
    run: [make, html]

  wrk: !Command
    container: wrk
    description: Run wrk tool
    run: [wrk]

  example-message-board: !Supervise
    description: Run swindon and message board example
    prerequisites: [make]
    children:
      swindon: !Command
        container: xenial
        work-dir: examples/message-board
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon.yaml
      board: !Command
        container: message-board
        work-dir: examples/message-board
        environ:
          LISTEN_FDS: 1
        pass-tcp-socket: 127.0.0.1:8082
        run:
        - python3
        - -m
        - messageboard

  example-message-board2: !Supervise
    description: Run swindon and message board 2 example
    prerequisites: [make]
    children:
      swindon: !Command
        container: xenial
        work-dir: examples/message-board2
        environ: { RUST_BACKTRACE: 1, RUST_LOG: "debug,tokio_core=warn" }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon.yaml
      webpack: !Command
        container: message-board2
        work-dir: examples/message-board2
        run:
        - webpack
        - --watch
      board: !Command
        container: message-board2
        work-dir: examples/message-board2
        environ:
          LISTEN_FDS: 1
        pass-tcp-socket: 127.0.0.1:8082
        run:
        - python3
        - -m
        - messageboard

  example-message-board2-two-nodes: !Supervise
    description:
      Run swindon and message board 2 example
      employing two nodes of swindon with replication
    prerequisites: [make]
    children:
      swindon1: !Command
        container: xenial
        work-dir: examples/message-board2
        environ: { RUST_BACKTRACE: 1, RUST_LOG: "debug,tokio_core=warn" }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon1.yaml
      swindon2: !Command
        container: xenial
        work-dir: examples/message-board2
        environ: { RUST_BACKTRACE: 1, RUST_LOG: "debug,tokio_core=warn" }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon2.yaml
      webpack: !Command
        container: message-board2
        work-dir: examples/message-board2
        run:
        - webpack
        - --watch
      board: !Command
        container: message-board2
        work-dir: examples/message-board2
        environ:
          LISTEN_FDS: 1
        pass-tcp-socket: 127.0.0.1:8082
        run:
        - python3
        - -m
        - messageboard

  example-presence: !Supervise
    description: Run swindon and presence example
    prerequisites: [make]
    children:
      swindon: !Command
        container: xenial
        work-dir: examples/presence
        environ: { RUST_BACKTRACE: 1, RUST_LOG: "debug,tokio_core=warn" }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon.yaml
      webpack: !Command
        container: presence
        work-dir: examples/presence
        run:
        - webpack
        - --watch
      board: !Command
        container: presence
        work-dir: examples/presence
        environ:
          LISTEN_FDS: 1
        pass-tcp-socket: 127.0.0.1:8082
        run:
        - python3
        - -m
        - presence

  example-presence-two-nodes: !Supervise
    description:
      Run swindon and presence example
      employing two nodes of swindon with replication
    prerequisites: [make]
    children:
      swindon1: !Command
        container: xenial
        work-dir: examples/presence
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon1.yaml
      swindon2: !Command
        container: xenial
        work-dir: examples/presence
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon2.yaml
      webpack: !Command
        container: presence
        work-dir: examples/presence
        run:
        - webpack
        - --watch
      board: !Command
        container: presence
        work-dir: examples/presence
        environ:
          LISTEN_FDS: 1
        pass-tcp-socket: 127.0.0.1:8082
        run:
        - python3
        - -m
        - presence

  example-multi-user-chat: !Supervise
    description: Run swindon and multi-user-chat example
    prerequisites: [make]
    children:
      swindon: !Command
        container: xenial
        work-dir: examples/multi-user-chat
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon.yaml
      chat: !Command
        container: multi-user-chat
        work-dir: examples/multi-user-chat
        run:
        - python3
        - -m
        - muc
      react-app: !Command
        container: multi-user-chat
        work-dir: examples/multi-user-chat
        run:
        - npm
        - start

  example-multi-user-chat2: !Supervise
    description: Run swindon and multi-user-chat 2 example
    prerequisites: [make]
    children:
      swindon: !Command
        container: xenial
        work-dir: examples/multi-user-chat2
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon.yaml
      chat: !Command
        container: multi-user-chat2
        work-dir: examples/multi-user-chat2
        run:
        - python3
        - -m
        - muc
      react-app: !Command
        container: multi-user-chat2
        work-dir: examples/multi-user-chat2
        run:
        - npm
        - start

  example-multi-user-chat2-two-nodes: !Supervise
    description:
      Run swindon and multi-user-chat 2 example
      employing two nodes of swindon with replication
    prerequisites: [make]
    children:
      swindon1: !Command
        container: xenial
        work-dir: examples/multi-user-chat2
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon1.yaml
      swindon2: !Command
        container: xenial
        work-dir: examples/multi-user-chat2
        environ: { RUST_BACKTRACE: 1 }
        run:
        - ../../target/debug/swindon
        - --verbose
        - --config=swindon2.yaml
      chat: !Command
        container: multi-user-chat2
        work-dir: examples/multi-user-chat2
        run:
        - python3
        - -m
        - muc
      react-app: !Command
        container: multi-user-chat2
        work-dir: examples/multi-user-chat2
        run:
        - npm
        - start

  bulk: !Command
    description: Run any bulk command
    container: xenial
    run: [bulk]


  _package-trusty: !Command
    container: trusty
    run: &package |
      set -e
      version=$(git describe --dirty)
      codename=$(lsb_release --codename --short)
      rm -rf pkg
      rm -rf target/release/swindon*
      bulk with-version "${version}" cargo install --root=/work/pkg/usr --path=.
      rm pkg/usr/.crates.toml
      bulk pack --package-version="${version}+${codename}1"

  _package-precise: !Command
    container: precise
    run: *package

  _package-xenial: !Command
    container: xenial
    run: *package

  packages: !Command
    container: xenial
    description: Build packages and repostories (mostly for CI)
    prerequisites: [_package-trusty, _package-precise, _package-xenial]
    accepts_arguments: true
    run: |
      bulk repo-add --config bulk.yaml --repository-base dist/repos \
        dist/swindon-[0-9]*.deb "$@"