Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
version: 2.1

templates:
tagged-filter: &tagged-filter
tags:
only: /^[0-9]+(\.[0-9]+)*((a|b|rc)[0-9]+)?(\.dev[0-9]+)?/

executors:
ubuntu-builder:
docker:
- image: trustlines/builder:master61
resource_class:
medium
working_directory: ~/repo

jobs:
deploy-docker-image:
executor: ubuntu-builder
environment:
DOCKER_REPO: trustlines/relay
LOCAL_IMAGE: relay
working_directory: ~/repo
steps:
- checkout
- setup_remote_docker:
version: 20.10.7
- attach_workspace:
at: '~'
- run:
name: Login to dockerhub
command: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin
- run:
name: Upload tagged version
environment:
DOCKERHUB_PROJECT: safe-relay-service
command: |
bash scripts/deploy_docker.sh staging

deploy-docker-image-release:
executor: ubuntu-builder
environment:
DOCKER_REPO: trustlines/relay
LOCAL_IMAGE: relay
working_directory: ~/repo
steps:
- checkout
- setup_remote_docker:
version: 20.10.7
- attach_workspace:
at: "~"
- run:
name: Login to dockerhub
command: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin
- run:
name: Upload tagged release
environment:
DOCKERHUB_PROJECT: safe-relay-service
command: |
bash scripts/deploy_docker.sh $CIRCLE_TAG

# run-end2end-tests:
# executor: ubuntu-builder
# environment:
# DOCKER_REPO: trustlines/relay
# LOCAL_IMAGE: relay
# working_directory: ~
# steps:
# - config-path
# - setup_remote_docker:
# version: 20.10.7
# - attach_workspace:
# at: '~'
# - run:
# name: Checkout end2end repo
# command: |
# git clone https://github.com/trustlines-protocol/end2end.git
# - run:
# name: Load docker image
# command: |
# docker load --input ~/images/$LOCAL_IMAGE.tar
# - run:
# name: run end2end tests
# command: |
# docker tag $LOCAL_IMAGE $DOCKER_REPO
# cd end2end
# ./run-e2e.sh
# - run:
# name: copy out the end2end coverage file from remote docker to host
# command: |
# scp circleci@remote-docker:project/end2end/end2end-coverage/coverage.xml /home/circleci/repo/coverage.xml
# - run:
# name: upload end2end codecov
# command: |
# cd ~/repo
# codecov --file coverage.xml



workflows:
version: 2
default:
jobs:

- deploy-docker-image:
filters:
branches:
only: safe-relay-fork
context: docker-credentials

- deploy-docker-image-release:
filters:
<<: *tagged-filter
branches:
ignore: /.*/
context: docker-credentials
68 changes: 27 additions & 41 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ name: Python CI
on: [push, pull_request]

jobs:
linting:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files

test-app:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -35,57 +52,46 @@ jobs:
docker run --detach --publish 8545:8545 --network-alias ganache -e DOCKER=true trufflesuite/ganache:latest --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --chain.chainId 1337 --chain.networkId 1337 -d
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
name: Cache pip
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-test.txt') }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v3
name: Cache pre-commit
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-precommit-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-precommit-
cache: 'pip'
cache-dependency-path: 'requirements*.txt'
- name: Install dependencies
run: |
pip install wheel
pip install -r requirements-test.txt coveralls pre-commit
pip install -r requirements-test.txt coveralls
env:
PIP_USE_MIRRORS: true
- name: Run pre-commit
run: pre-commit run --all-files
- name: Run tests and coverage
run: |
python manage.py check
python manage.py makemigrations --check --dry-run
coverage run --source=$SOURCE_FOLDER -m py.test -rxXs
env:
SOURCE_FOLDER: safe_relay_service
CELERY_BROKER_URL: redis://localhost:6379/0
DJANGO_SETTINGS_MODULE: config.settings.test
DATABASE_URL: psql://postgres:postgres@localhost/postgres
ETHEREUM_NODE_URL: http://localhost:8545
ETHEREUM_TRACING_NODE_URL: http://localhost:8545
ETH_HASH_BACKEND: pysha3
REDIS_URL: redis://localhost:6379/0
CELERY_BROKER_URL: redis://localhost:6379/0
- name: Send results to coveralls
continue-on-error: true # Ignore coveralls problems
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required for coveralls
docker-deploy:
runs-on: ubuntu-latest
needs: test-app
needs:
- linting
- test-app
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Dockerhub login
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand All @@ -104,23 +110,3 @@ jobs:
run: bash scripts/deploy_docker.sh ${GITHUB_REF##*/}
env:
DOCKERHUB_PROJECT: safe-relay-service
autodeploy:
runs-on: ubuntu-latest
needs: [docker-deploy]
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Deploy Staging
if: github.ref == 'refs/heads/master'
run: bash scripts/autodeploy.sh
env:
AUTODEPLOY_URL: ${{ secrets.AUTODEPLOY_URL }}
AUTODEPLOY_TOKEN: ${{ secrets.AUTODEPLOY_TOKEN }}
TARGET_BRANCH: "staging"
- name: Deploy Develop
if: github.ref == 'refs/heads/develop'
run: bash scripts/autodeploy.sh
env:
AUTODEPLOY_URL: ${{ secrets.AUTODEPLOY_URL }}
AUTODEPLOY_TOKEN: ${{ secrets.AUTODEPLOY_TOKEN }}
TARGET_BRANCH: "develop"
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: check-docstring-first
- id: check-merge-conflict
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ How is this possible? The **Transaction Relay Service** acts as a proxy, paying
back due to the transaction architecture we use. It also enables the user to pay for ethereum transactions
using **ERC20 tokens**.

Docs
----
Docs are available on [Gnosis Docs](https://docs.gnosis.io/safe/docs/services_relay/)
You can open the diagrams explaining _Pre CREATE2_ deployment under `docs/` with [Staruml](http://staruml.io/)

Setup for development (using ganache)
-------------------------------------
This is the recommended configuration for developing and testing the Relay service. `docker-compose` is required for
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
command: docker/web/celery/worker/run.sh

ganache:
image: trufflesuite/ganache-cli
command: -d --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --chain.chainId 1337 --chain.networkId 1337
image: trufflesuite/ganache:latest
command: --defaultBalanceEther 10000 --gasLimit 10000000 -a 30 --chain.chainId 1337 --chain.networkId 1337 -d
ports:
- "8545:8545"
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ volumes:

services:
nginx:
image: nginx:1.21-alpine
image: nginx:1-alpine
hostname: nginx
ports:
- "8000:8000"
Expand All @@ -16,7 +16,7 @@ services:
- web

redis:
image: redis:5-alpine
image: redis:7-alpine
ports:
- "6379:6379"

Expand All @@ -28,6 +28,7 @@ services:
POSTGRES_PASSWORD: postgres

web:
platform: linux/amd64
build:
context: .
dockerfile: docker/web/Dockerfile
Expand All @@ -44,6 +45,7 @@ services:
command: docker/web/run_web.sh

worker: &worker
platform: linux/amd64
build:
context: .
dockerfile: docker/web/Dockerfile
Expand All @@ -55,6 +57,7 @@ services:
command: docker/web/celery/worker/run.sh

scheduler:
platform: linux/amd64
<<: *worker
command: docker/web/celery/scheduler/run.sh

21 changes: 10 additions & 11 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
FROM python:3.10-slim

ENV PYTHONUNBUFFERED 1
WORKDIR /app
ARG APP_HOME=/app
WORKDIR ${APP_HOME}
ENV PYTHONUNBUFFERED=1

# Signal handling for PID1 https://github.com/krallin/tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
# https://eth-hash.readthedocs.io/en/latest/quickstart.html#specify-backend-by-environment-variable
# `pysha3` is way faster than `pycryptodome` for CPython
ENV ETH_HASH_BACKEND=pysha3

COPY requirements.txt ./
RUN set -ex \
&& buildDeps=" \
build-essential \
git \
libssl-dev \
libgmp-dev \
pkg-config \
libpq-dev \
" \
&& apt-get update \
&& apt-get install -y --no-install-recommends $buildDeps \
&& apt-get install -y --no-install-recommends $buildDeps tmux postgresql-client \
&& pip install -U --no-cache-dir wheel setuptools pip \
&& pip install --no-cache-dir -r requirements.txt \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
Expand All @@ -28,5 +29,3 @@ RUN set -ex \

COPY . .
RUN DJANGO_SETTINGS_MODULE=config.settings.local DJANGO_DOT_ENV_FILE=.env.local python manage.py collectstatic --noinput

ENTRYPOINT ["/tini", "--"]
14 changes: 7 additions & 7 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-r requirements.txt
coverage==6.3.2
django-stubs==1.10.1
coverage==6.5.0
django-stubs==1.13.0
factory-boy==3.2.1
faker==13.3.3
mypy==0.942
pytest==7.1.1
faker==15.1.1
mypy==0.982
pytest==7.1.3
pytest-celery==0.0.0
pytest-django==4.5.2
pytest-env==0.6.2
pytest-sugar==0.9.4
pytest-env==0.8.1
pytest-sugar==0.9.6
Loading