diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 0000000..0df9789 --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,49 @@ +name: Build and push skale-proxy container +on: + workflow_dispatch: + push: +jobs: + build: + runs-on: ubuntu-18.04 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + steps: + - name: Login to docker + run: docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} + - uses: actions/checkout@v1 + - name: submodule update + run: git submodule update --init --recursive + - name: build and deploy test image + run: python3 scripts/docker_build.py Dockerfile skale-proxy ${GITHUB_SHA} + - name: deploy docker image + if: | + contains(github.ref, 'develop') || contains(github.ref, 'beta') || + contains(github.ref, 'master') + run : | + export BRANCH=${GITHUB_REF##*/} + echo "Branch $BRANCH" + export VERSION=$(cat VERSION) + echo "Version $VERSION" + export VERSION=$(bash ./scripts/calculate_version.sh $BRANCH $VERSION) + echo "::set-env name=VERSION::$VERSION" + echo "Version $VERSION" + export RELEASE=true + echo "::set-env name=RELEASE::$RELEASE" + bash ./scripts/build_image.sh Dockerfile skale-proxy + bash ./scripts/publish_image.sh skale-proxy + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + - name: Create Release + if: contains(github.ref, 'develop') || contains(github.ref, 'beta') || contains(github.ref, 'master') + id: create_release + uses: actions/create-release@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.VERSION }} + release_name: ${{ env.VERSION }} + draft: false + prerelease: true + diff --git a/README.md b/README.md index 552b54a..14efa21 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ -# skale-proxy +# Skale-proxy + +skale-proxy is a public service that provides proxied and load-balanced JSON-RPC endpoints for SKL chains. + +It is based on Nginx reverse proxy that receives SKALE chain names and IP addresses of SKL nodes from SKALE manager. + +# Endpoints + +For SKALE mainnet the endpoints that proxy provides are in the form of + +http://proxy.skale.network/mainnet/CHAIN_NAME + +or + +https://proxy.skale.network/mainnet/CHAIN_NAME + +For SKL testnet the endpoints that proxy provides are in the form of + +http://proxy.skale.network/testnet/CHAIN_NAME + +or + +https://proxy.skale.network/testnet/CHAIN_NAME -skale-proxy is a public service that provides proxied and load-balanced JSON-RPC endpoints for SKALE chains # running diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..79e15fd --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.77.0 diff --git a/scripts/build_image.sh b/scripts/build_image.sh new file mode 100644 index 0000000..16ca923 --- /dev/null +++ b/scripts/build_image.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e +set -x + +DOCKERFILE=$1 +CONTAINER_NAME=$2 + +: "${VERSION?Need to set VERSION}" +: "${BRANCH?Need to set BRANCH}" + +REPO_NAME=skalenetwork/$CONTAINER_NAME +IMAGE_NAME=$REPO_NAME:$VERSION + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +# Build image + +echo "Building $IMAGE_NAME..." +docker build -f "${DIR}"/../"${DOCKERFILE}" -t "${IMAGE_NAME}" . || exit $? + +if [ "${BRANCH}" = "stable" ]; +then + LATEST_IMAGE_NAME=$REPO_NAME:latest + docker tag "${IMAGE_NAME}" "${LATEST_IMAGE_NAME}" +else + LATEST_IMAGE_NAME=$REPO_NAME:$BRANCH-latest + docker tag "${IMAGE_NAME}" "${LATEST_IMAGE_NAME}" +fi + +echo "=========================================================================================" +echo "Built $IMAGE_NAME" diff --git a/scripts/calculate_version.sh b/scripts/calculate_version.sh new file mode 100644 index 0000000..98ba49d --- /dev/null +++ b/scripts/calculate_version.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +BRANCH=$1 +VERSION=$2 + +if [ -z "$BRANCH" ] +then + echo "A branch is not set." + exit 1 +fi + +if [ -z "$VERSION" ] +then + echo "The base version is not set." + exit 1 +fi + +git fetch --tags + +if [ "$BRANCH" = "master" ] +then + echo "$VERSION" + exit 0 +fi + +LABEL="develop" +if [ "$BRANCH" = "stable" ] +then + LABEL="stable" +elif [ "$BRANCH" = "beta" ] +then + LABEL="beta" +fi + +for (( VERSION_NUMBER=0; ; VERSION_NUMBER++ )) +do + RESULT_VERSION="$VERSION-$LABEL.$VERSION_NUMBER" + if ! [[ $(git tag -l | grep $RESULT_VERSION) ]]; then + echo "$RESULT_VERSION" | tr / - + break + fi +done diff --git a/scripts/docker_build.py b/scripts/docker_build.py new file mode 100644 index 0000000..7bfeaea --- /dev/null +++ b/scripts/docker_build.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Copyright (C) 2019-Present SKALE Labs +# +# This file is part of sgxwallet. +# +# sgxwallet is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# sgxwallet is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with sgxwallet. If not, see . +# +# @file docker_build.py +# @author Stan Kladko +# @date 2020 +# + +import sys, os, subprocess, time + +os.chdir("..") +topDir = os.getcwd() + "/skale-proxy" +DOCKER_FILE_NAME = sys.argv[1] +IMAGE_NAME = sys.argv[2] +COMMIT_HASH = sys.argv[3] + +FULL_IMAGE_TAG = "skalenetwork/" + IMAGE_NAME + ":" + COMMIT_HASH + +print("Starting build", flush=True) + +assert subprocess.call(["pwd"]) == 0 + +assert subprocess.call(["docker", "build", topDir, "--file", topDir + "/" + DOCKER_FILE_NAME, "--tag", + FULL_IMAGE_TAG]) == 0 + +assert subprocess.call(["docker", "push", FULL_IMAGE_TAG]) == 0 diff --git a/scripts/publish_image.sh b/scripts/publish_image.sh new file mode 100644 index 0000000..6705409 --- /dev/null +++ b/scripts/publish_image.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e +set -x + +CONTAINER_NAME=$1 + +: "${VERSION?Need to set VERSION}" +: "${BRANCH?Need to set BRANCH}" + +REPO_NAME=skalenetwork/$CONTAINER_NAME +IMAGE_NAME=$REPO_NAME:$VERSION + +LATEST_IMAGE_NAME=$REPO_NAME:$BRANCH-latest +docker tag "${IMAGE_NAME}" "${LATEST_IMAGE_NAME}" + +: "${DOCKER_USERNAME?Need to set DOCKER_USERNAME}" +: "${DOCKER_PASSWORD?Need to set DOCKER_PASSWORD}" + +echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin + +docker push "$IMAGE_NAME" || exit $? +docker push "$LATEST_IMAGE_NAME" || exit $?