-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nucypher/docker
deployment automation with docker+cron
- Loading branch information
Showing
7 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * * * * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |