From e3a101e8bdeb100c852f9a4600b4553a6fe59de7 Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Fri, 12 Mar 2021 16:33:37 +0100 Subject: [PATCH] Support for "One-click" releases (#205) * Refactored start docs * Changed source of go-bindata #197 * Updated go dep trackers * Updated yarn dependencies * Added update step to Makefile * New auto-generated bindata tests * Added doc note about make update * yarn upgrade * Doc: rename Infura key as "project ID" for clarity * Set resource class to medium for CircleCI builds * Use Debian 'stable' release in Docker * Added bootstrap * Added stackscript * Default branch * Added variables * Root folder * Stackscript updated * StackScript README * Revert to master yarn.lock * Stackscript and Readme * Added virtual host to StackScript * Switch to official bootstrap source --- README.md | 22 ++++-- bootstrap.sh | 120 ++++++++++++++++++++++++++++++++ deploy/linode/README.md | 26 +++++++ deploy/linode/stackscript.sh | 130 +++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+), 6 deletions(-) create mode 100644 bootstrap.sh create mode 100644 deploy/linode/README.md create mode 100644 deploy/linode/stackscript.sh diff --git a/README.md b/README.md index b8ecb41be..93b2bb818 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,33 @@ # Proxeus ---------------- -Main repository of the proxeus platform. +Main repository of the Proxeus platform core. Proxeus combines a powerful document automation tool with the wide-ranging blockchain functionalities, enabling users to digitize and monetize their IP. -## Source Code +You can access the source code of this application and various extensions +on [GitHub](https://github.com/ProxeusApp). -You can access the source code of this application on the [Proxeus GitHub repository](https://github.com/ProxeusApp). +# Quick Starts -## Quick Start with docker -The quickest way to try Proxeus is to use `docker-compose`. +## One-click builds + +We are making facilitated build configurations available for select cloud platforms: + +- [Linode StackScript](deploy/linode/README.md) + +## Using Docker + +The quickest way to set up Proxeus for development is to use Docker, and the `docker-compose` tool. ### Install docker and docker-compose + 1. [Install Docker Engine](https://docs.docker.com/install/) 2. [Install docker-compose](https://docs.docker.com/compose/install/) ### Get API Keys for Infura and SparkPost + The Proxeus platform depends on [Infura](https://infura.io/) and [SparkPost](https://www.sparkpost.com/) for Ethereum and email integration respectively. @@ -41,7 +51,7 @@ Proxeus platform. ## User manual -The user manual is available here: [User Manual](https://docs.google.com/document/d/1SP0ZimG7uemfZ2cF2JkY5enUZnBJLDyfcJGZnyWOejQ) +Get help to make the most of the platform in the [User Handbook](https://docs.google.com/document/d/e/2PACX-1vTchv7PotoQeH2cBA2VIHcqV0I0N_IQpFnbESR-8C19cgBikek3HAMVdPtfJJcYkANzPWbfy_S3bf8X/pub). ## Contributing diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 000000000..fa1b37751 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $TRACE ]] && set -x + +# A script to bootstrap proxeus-core. + +# Based on https://github.com/dokku/dokku/blob/master/bootstrap.sh +# We encourage you to also add Dokku for managing your instance, +# however this is not done by this script. + +# It expects to be run on Debian, Ubuntu, or CentOS 7 via 'sudo' + +# It checks out the proxeus source code from Github into ~/proxeus and then runs 'make install'. + + +log-fail() { + declare desc="log fail formatter" + echo "$@" 1>&2 + exit 1 +} + +ensure-environment() { + local FREE_MEMORY + if [[ -z "$GIT_TAG" ]]; then + echo "Preparing to install $GIT_REPO..." + else + echo "Preparing to install $GIT_TAG from $GIT_REPO..." + fi + + hostname -f >/dev/null 2>&1 || { + log-fail "This installation script requires that you have a hostname set for the instance. Please set a hostname for 127.0.0.1 in your /etc/hosts" + } + + if ! command -v apt-get &>/dev/null; then + log-fail "This installation script supports Debian-based systems and expects apt-get." + fi + + if ! command -v docker &> /dev/null; then + log-fail "Docker needs to be installed." + fi + + if ! command -v docker-compose &> /dev/null; then + log-fail "Docker Compose needs to be installed." + fi + + FREE_MEMORY=$(grep MemTotal /proc/meminfo | awk '{print $2}') + if [[ "$FREE_MEMORY" -lt 1003600 ]]; then + echo "To build containers, it is strongly suggested that you have 1024 megabytes or more of free memory" + fi +} + +install-requirements() { + echo "--> Ensuring we have the proper dependencies" + + case "$SRV_DISTRO" in + debian) + if ! dpkg -l | grep -q software-properties-common; then + apt-get update -qq >/dev/null + apt-get -qq -y --no-install-recommends install software-properties-common + fi + ;; + ubuntu) + if ! dpkg -l | grep -q software-properties-common; then + apt-get update -qq >/dev/null + apt-get -qq -y --no-install-recommends install software-properties-common + fi + + add-apt-repository universe >/dev/null + apt-get update -qq >/dev/null + ;; + esac + + apt-get -qq -y --no-install-recommends install sudo git make software-properties-common +} + +install-proxeus() { + if [[ -n $GIT_BRANCH ]]; then + install-proxeus-from-source "origin/$GIT_BRANCH" + elif [[ -n $GIT_TAG ]]; then + local GIT_SEMVER="${GIT_TAG//v/}" + major=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[1]}') + minor=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[2]}') + patch=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[3]}') + + install-proxeus-from-source "$GIT_TAG" + else + install-proxeus-from-source + fi +} + +install-proxeus-from-source() { + local GIT_CHECKOUT="$1" + + if [[ ! -d ./proxeus ]]; then + git clone "$GIT_REPO" ./proxeus + fi + + cd ./proxeus + git fetch origin + [[ -n $GIT_CHECKOUT ]] && git checkout "$GIT_CHECKOUT" + make +} + +main() { + export SRV_DISTRO SRV_DISTRO_VERSION + # shellcheck disable=SC1091 + SRV_DISTRO=$(. /etc/os-release && echo "$ID") + # shellcheck disable=SC1091 + SRV_DISTRO_VERSION=$(. /etc/os-release && echo "$VERSION_ID") + + export DEBIAN_FRONTEND=noninteractive + export GIT_REPO=${GIT_REPO:-"https://github.com/ProxeusApp/proxeus-core.git"} + + ensure-environment + install-requirements + install-proxeus +} + +main "$@" + diff --git a/deploy/linode/README.md b/deploy/linode/README.md new file mode 100644 index 000000000..710b0a71f --- /dev/null +++ b/deploy/linode/README.md @@ -0,0 +1,26 @@ +Proxeus StackScript for fast Linode deployment +--- + +Creates a compact all-in-one instance of the Proxeus application (no code environment for smart contracts) using a bootstrapped release image for Docker. This is a good starting point for development or small installations. For more information visit https://github.com/ProxeusApp + +StackScripts are private or public managed scripts which run within a Linode instance during startup. Using a simple form, you can configure the basic details needed to quickly get a Proxeus instance up and running. + +This script is maintained for the community by Proxeus Association + +## Instructions + +1. Search for "proxeus" when deploying a new Linode, or log in and navigate to https://cloud.linode.com/stackscripts/758453 +1. Additional documentation is available from [Linode Guides](https://www.linode.com/docs/guides/platform/stackscripts/) +1. You will need to have your API keys for Infura and Sparkpost handy - see the root README for further details. +1. It takes a few minutes for the server to boot and install, then you should be able to open `http://:1323/init` +1. A configuration screen will be shown where you can set up an admin account and check settings. + +Once your server is running, visit the [User Handbook](https://docs.google.com/document/d/e/2PACX-1vTchv7PotoQeH2cBA2VIHcqV0I0N_IQpFnbESR-8C19cgBikek3HAMVdPtfJJcYkANzPWbfy_S3bf8X/pub) to get started. + +## References + +The basic set-up of a Debian or Ubuntu server is based roughly on Linode's [Basic OCA Helper One-Click](https://cloud.linode.com/stackscripts/401712). + +We suggest [Securing Public Shadowsocks Server](https://github.com/shadowsocks/shadowsocks/wiki/Securing-Public-Shadowsocks-Server) as one example guide to follow for further 'buttoning down' your instance. + +[Linode](https://linode.com) is a privately-owned American cloud hosting company that provides virtual private and managed servers around the world. diff --git a/deploy/linode/stackscript.sh b/deploy/linode/stackscript.sh new file mode 100644 index 000000000..caca84624 --- /dev/null +++ b/deploy/linode/stackscript.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# +# +# + +# Logs: tail -f /var/log/stackscript.log +# Logs: cat /var/log/stackscript.log + +# Log to /var/log/stackscript.log for future troubleshooting + +# Logging set up +exec 1> >(tee -a "/var/log/stackscript.log") 2>&1 +function log { + echo "### $1 -- `date '+%D %T'`" +} + +# Common bash functions +source +log "Common lib loaded" + +# Apply harden script +source +log "Hardening activated" + +log "Configuring System Updates" +apt-get -o Acquire::ForceIPv4=true update -y +DEBIAN_FRONTEND=noninteractive apt-get -y -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" install grub-pc +apt-get -o Acquire::ForceIPv4=true update -y + +## Set hostname, configure apt and perform update/upgrade +log "Setting hostname" +IP=`hostname -I | awk '{print$1}'` +hostnamectl set-hostname $FQDN +echo $IP $FQDN >> /etc/hosts + +log "Updating .." +export DEBIAN_FRONTEND=noninteractive +apt-get update -y + +## Remove older installations and get set for Docker install +log "Getting ready to install Docker" +sudo apt-get remove docker docker-engine docker.io containerd runc +sudo apt-get update +sudo apt-get install -y \ + apt-transport-https \ + ca-certificates \ + curl \ + make \ + gnupg-agent \ + software-properties-common \ + apache2-utils + +log "Installing Docker Engine for $lsb_dist" +lsb_dist="$(. /etc/os-release && echo "$ID")" +lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" + +## Add Docker’s official GPG key +curl -fsSL "https://download.docker.com/linux/$lsb_dist/gpg" | sudo apt-key add - + +## Install stable docker as daemon +add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/$lsb_dist \ + $(lsb_release -cs) \ + stable" +apt-get update +apt-get install -y docker-ce docker-ce-cli docker-compose containerd.io +systemctl enable docker + +## Set up fail2ban +log "Installing fail2ban" +apt-get install fail2ban -y +cd /etc/fail2ban +cp fail2ban.conf fail2ban.local +cp jail.conf jail.local +systemctl start fail2ban +systemctl enable fail2ban + +## Set up firewall with port 1323 open to default Proxeus platform +# Set up nginx separately to proxy to 443 +log "Configuring firewall" +apt-get install ufw -y +ufw default allow outgoing +ufw default deny incoming + +ufw allow ssh +ufw allow https +ufw allow http +ufw allow 1323 + +ufw enable + +systemctl enable ufw +ufw logging off + +## ---------------------------------------------- +## Install & configure proxeus + +log "Installing Proxeus" +mkdir -p /srv +cd /srv + +wget https://raw.githubusercontent.com/ProxeusApp/proxeus-core/master/bootstrap.sh; +bash bootstrap.sh + +cd proxeus +cat <.env +PROXEUS_BLOCKCHAIN_CONTRACT_ADDRESS=0x1d3e5c81bf4bc60d41a8fbbb3d1bae6f03a75f71 +PROXEUS_ALLOW_HTTP=true +PROXEUS_DATA_DIR=./data +PROXEUS_INFURA_API_KEY=$INFURA +PROXEUS_SPARKPOST_API_KEY=$SPARKPOST +PROXEUS_PLATFORM_DOMAIN=http://$FQDN:1323 +PROXEUS_VIRTUAL_HOST=$FQDN + +END + +log "Starting Proxeus Core" +docker-compose up -d & + +# In a production setting you might want to use a separate env file and/or overrides +# docker-compose --env-file .env.prod -f docker-compose.yml -f docker-compose-cloud.override.yml up -d & + + +# Open http://$FQDN:1323/init to configure your server +log "After a minute, open: http://$FQDN:1323/init" + +## ---------------------------------------------- + +echo "Installation complete!"