Skip to content

Commit

Permalink
Merge pull request #2 from nucypher/docker
Browse files Browse the repository at this point in the history
deployment automation with docker+cron
  • Loading branch information
vzotova authored Feb 19, 2024
2 parents 232819d + a01b5e4 commit 0bac4ad
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Docker"

on:
push:
branches:
- 'main'

jobs:
deploy:
name: build && push image to docker hub
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v3
with:
ref: 'main'

- name: setup docker buildx
uses: docker/setup-buildx-action@v2

- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: build and push api
id: build-push-api
uses: docker/build-push-action@v3
with:
context: ../../
file: ./deploy/Dockerfile
push: true
tags: nucypher/train45:latest
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,76 @@ export WEB3_INFURA_PROJECT_ID=<Infura project ID>
export APE_ACCOUNTS_BOT_PASSPHRASE=<Passphrase for account with alias BOT>

ape run proof_bot --fx-root-tunnel 0x720754c84f0b1737801bf63c950914E0C1d4aCa2 --graphql-endpoint https://api.studio.thegraph.com/query/24143/polygonchildmumbai/version/latest --proof-generator https://proof-generator.polygon.technology/api/v1/mumbai/exit-payload/ --network :goerli:infura --account BOT
```
```


## Docker

##### Build

```bash
docker build -f deploy/Dockerfile -t nucypher/train45:latest .
```

##### Run

First, create the log file:

```bash
touch /var/log/cron.log
```

Then run the bot:

```bash
docker run \
--name train45 \
--detach \
--env-file .env \
-f deploy/Dockerfile \
-v /var/log/cron.log:/var/log/cron.log \
-v /var/log/:/var/log/ \
-v ~/.ape/:/root/.ape \
nucypher/train45:latest
```

Enjoy the logs:

```bash
tail -f /var/log/cron.log
```

##### Stop

```bash
docker stop train45 && docker rm train45
```

## Docker-compose

##### Build

```bash
docker-compose build
```

##### Start (all services)

First, create the log file:

```bash
touch /var/log/cron.log
```

Then run the bot with docker-compose
(including log server and autoupdate service):

```bash
docker-compose up -d
```

##### Stop (all services)

```bash
docker-compose down
```
8 changes: 8 additions & 0 deletions deploy/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WEB3_INFURA_API_KEY=
GQL_URL=
PROOFS_URL=
NETWORK=
TUNNEL=
APE_ACCOUNTS_BOT_PASSPHRASE=
ACCOUNT=
INTERVAL= 0 * * * *
21 changes: 21 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.12-slim

# Layer 1: Install system requirements
RUN apt-get update && apt-get install -y cron python3 python3-pip

# Set the working directory
WORKDIR /app

# Layer 2: Install python requirements
COPY requirements.txt /app
RUN pip3 install --no-cache-dir -r requirements.txt

# Layer 3: Set execution rights for the entrypoints
COPY . /app
RUN chmod +x deploy/run.sh deploy/cron.sh && \
mkdir -p /root/.cache/log && \
touch /root/.cache/log/cron.log && \
chmod 644 /root/.cache/log/cron.log

# Set the defult entrypoint
CMD ["/app/deploy/cron.sh"]
8 changes: 8 additions & 0 deletions deploy/cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e
touch /root/.cache/log/cron.log
printenv | crontab -
(crontab -l; echo "$INTERVAL /app/deploy/run.sh >> /root/.cache/log/cron.log 2>&1") | crontab -
echo "Setup cron timecode: $INTERVAL"
cron -f
51 changes: 51 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3'

services:

train45:
image: nucypher/train45:dev
container_name: train45
platform: linux/amd64
restart: always
env_file:
- .env
build:
context: ../
dockerfile: deploy/Dockerfile
volumes:
- ~/.ape/:/root/.ape
- ~/.cache/log/:/root/.cache/log/

tail:
depends_on:
- train45
image: alpine:latest
container_name: tail
restart: always
volumes:
- ~/.cache/log/:/root/.cache/log/
command: tail -f /root/.cache/log/cron.log

dozzle:
depends_on:
- train45
- tail
image: amir20/dozzle:latest
container_name: dozzle
restart: always
ports:
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock

watchtower:
depends_on:
- train45
- tail
- dozzle
image: containrrr/watchtower:latest
container_name: watchtower
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: train45
10 changes: 10 additions & 0 deletions deploy/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd /app
echo "The train is leaving the station"
ape run proof_bot \
--network $NETWORK \
--account $ACCOUNT \
--fx-root-tunnel $TUNNEL \
--graphql-endpoint $GQL_URL \
--proof-generator $PROOFS_URL

0 comments on commit 0bac4ad

Please sign in to comment.