Skip to content

Commit

Permalink
feat: isolate components (#81)
Browse files Browse the repository at this point in the history
* feat: add nvmrc file to trigger use of expected node version

* feat: update cmds to be able to run in macos

* feat: add cmds and dockerfile for local blockchain

* feat: add cmds and dockerfile for solver

* feat: add cmds and dockerfile for job creator

* [wip] feat: add cmds and dockerfile for resource provider

* [wip] feat: add cmds and dockerfile for bacalhau

* [wip] feat: update cmd for mediator

* [wip] feat: update cmd for integration tests

* feat: add user to hardhat accounts

* feat: simplify stack

* feat: add deploy scripts
  • Loading branch information
AquiGorka authored May 16, 2024
1 parent 70ac27c commit e04d15e
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 219 deletions.
147 changes: 147 additions & 0 deletions .github/workflows/devnet_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Deploy Devnet

on:
push:
branches:
- main
- gorka/isolate-components

jobs:
contracts:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
context: app

- name: Compile and deploy contracts
id: compile-and-deploy-contracts
env:
WEB3_RPC_URL: ${{ secrets.WEB3_RPC_URL }}
run: |
echo "# TODO"
solver-build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
context: app

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: Solver build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_SOLVER: ${{ secrets.ECR_REPOSITORY_SOLVER }}
CLOUDFLARE_TOKEN_SOLVER: ${{ secrets.CLOUDFLARE_TOKEN_SOLVER }}
run: |
docker build \
-t $ECR_REPOSITORY_SOLVER \
-f ./docker/solver/Dockerfile \
--build-arg="expose_via=cloudflare" \
--build-arg="cloudflare_token=${CLOUDFLARE_TOKEN_SOLVER}"\
--build-arg="doppler_config=devnet" \
.
docker tag $ECR_REPOSITORY_SOLVER:latest $ECR_REGISTRY/$ECR_REPOSITORY_SOLVER:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY_SOLVER:latest
- name: Solver deploy to EC2 instance
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_SOLVER: ${{ secrets.ECR_REPOSITORY_SOLVER }}
DOPPLER_TOKEN_SOLVER: ${{ secrets.DOPPLER_TOKEN_SOLVER }}
with:
host: ${{ secrets.EC2_HOST_SOLVER }}
username: ${{ secrets.EC2_USERNAME_SOLVER }}
key: ${{ secrets.EC2_PRIVATE_KEY_SOLVER }}
envs: ECR_REGISTRY, ECR_REPOSITORY_SOLVER, DOPPLER_TOKEN_SOLVER
script_stop: true
script: |
docker stop solver || true
docker rm solver || true
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_REGISTRY
docker system prune -af
docker pull $ECR_REGISTRY/$ECR_REPOSITORY_SOLVER:latest
docker run \
-d \
--restart always \
--name solver \
-e DOPPLER_TOKEN=$DOPPLER_TOKEN_SOLVER \
$ECR_REGISTRY/$ECR_REPOSITORY_SOLVER:latest
job-creator-build-deploy:
needs: [solver-build-deploy]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
context: app

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: Job creator build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_JOB_CREATOR: ${{ secrets.ECR_REPOSITORY_JOB_CREATOR }}
run: |
docker build \
-t $ECR_REPOSITORY_JOB_CREATOR \
-f ./docker/job-creator/Dockerfile \
--build-arg doppler_config=devnet \
.
docker tag $ECR_REPOSITORY_JOB_CREATOR:latest $ECR_REGISTRY/$ECR_REPOSITORY_JOB_CREATOR:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY_JOB_CREATOR:latest
- name: Job creator deploy to EC2 instance
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_JOB_CREATOR: ${{ secrets.ECR_REPOSITORY_JOB_CREATOR }}
DOPPLER_TOKEN_JOB_CREATOR: ${{ secrets.DOPPLER_TOKEN_JOB_CREATOR }}
with:
host: ${{ secrets.EC2_HOST_JOB_CREATOR }}
username: ${{ secrets.EC2_USERNAME_JOB_CREATOR }}
key: ${{ secrets.EC2_PRIVATE_KEY_JOB_CREATOR }}
envs: ECR_REGISTRY, ECR_REPOSITORY_JOB_CREATOR, DOPPLER_TOKEN_JOB_CREATOR
script_stop: true
script: |
docker stop job-creator || true
docker rm job-creator || true
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_REGISTRY
docker system prune -af
docker pull $ECR_REGISTRY/$ECR_REPOSITORY_JOB_CREATOR:latest
docker run \
-d \
--restart always \
--name job-creator \
-e DOPPLER_TOKEN=$DOPPLER_TOKEN_JOB_CREATOR \
$ECR_REGISTRY/$ECR_REPOSITORY_JOB_CREATOR:latest
69 changes: 69 additions & 0 deletions .github/workflows/devnet_deploy_chain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy Devnet chain

on: workflow_dispatch

jobs:
chain-build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
context: app

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: Chain build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_CHAIN: ${{ secrets.ECR_REPOSITORY_CHAIN }}
CLOUDFLARE_TOKEN_HTTP: ${{ secrets.CLOUDFLARE_TOKEN_HTTP }}
CLOUDFLARE_TOKEN_WS: ${{ secrets.CLOUDFLARE_TOKEN_WS }}
ADMIN_ADDRESS: ${{ secrets.ADMIN_ADDRESS }}
run: |
docker build \
-t $ECR_REPOSITORY_CHAIN \
-f ./docker/chain/Dockerfile \
--build-arg="admin_address=${ADMIN_ADDRESS}" \
--build-arg="expose_via=cloudflare" \
--build-arg="cloudflare_token_http=${CLOUDFLARE_TOKEN_HTTP}"\
--build-arg="cloudflare_token_ws=${CLOUDFLARE_TOKEN_WS}"\
.
docker tag $ECR_REPOSITORY_CHAIN:latest $ECR_REGISTRY/$ECR_REPOSITORY_CHAIN:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY_CHAIN:latest
- name: Chain deploy to EC2 instance
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_CHAIN: ${{ secrets.ECR_REPOSITORY_CHAIN }}
with:
host: ${{ secrets.EC2_HOST_CHAIN }}
username: ${{ secrets.EC2_USERNAME_CHAIN }}
key: ${{ secrets.EC2_PRIVATE_KEY_CHAIN }}
envs: ECR_REGISTRY, ECR_REPOSITORY_CHAIN
script_stop: true
script: |
docker stop chain || true
docker rm chain || true
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_REGISTRY
docker system prune -af
docker pull $ECR_REGISTRY/$ECR_REPOSITORY_CHAIN:latest
docker run \
-d \
--restart always \
--name chain \
-v /data/chain:/data/chain \
$ECR_REGISTRY/$ECR_REPOSITORY_CHAIN:latest
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
24 changes: 24 additions & 0 deletions docker/bacalhau/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM docker:dind

ADD https://github.com/bacalhau-project/bacalhau/releases/download/v1.3.0/bacalhau_v1.3.0_linux_amd64.tar.gz .
RUN tar xfv bacalhau_v1.3.0_linux_amd64.tar.gz
RUN mv bacalhau /usr/local/bin

COPY ./do .
#COPY ./stack .
#COPY ./docker/bacalhau/Dockerfile .

CMD ["/bin/sh", "./do"]

# TODO
# contents of do:
# # wait for docker to initialize
# while ! docker -v; do sleep 1; done

# export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
# TODO
# check if this is needed
# export BACALHAU_API_HOST=localhost
# export LOG_LEVEL=debug

# bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked --ipfs-api-listen-addresses=/ip4/0.0.0.0/tcp/0
63 changes: 63 additions & 0 deletions docker/chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ARG expose_via=local

FROM golang:1.22.3 AS base

ARG arch=amd64
ARG cloudflare_token_http="not-a-token"
ARG cloudflare_token_ws="not-a-token"
ARG geth_version=v1.13.5

WORKDIR /geth

RUN git clone --quiet --branch ${geth_version} --depth 1 https://github.com/ethereum/go-ethereum .
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go run build/ci.go install -static ./cmd/geth

RUN /geth/build/bin/geth version
RUN mv /geth/build/bin/geth /usr/local/bin/

ARG admin_address="0x0"

RUN touch fund-admin
RUN echo "#!/bin/bash" >> fund-admin
RUN echo "geth --exec \"eth.sendTransaction({from: eth.coinbase, to: \\\"${admin_address}\\\", value: new web3.BigNumber(eth.getBalance(eth.coinbase)).minus(web3.toWei(1, \\\"ether\\\")) })\" attach /data/chain/geth.ipc" >> fund-admin
RUN chmod +x fund-admin

RUN touch run-node
RUN echo "#!/bin/bash" >> run-node
RUN echo "geth --datadir /data/chain --dev --ws --ws.api web3,eth,net --ws.addr 0.0.0.0 --ws.port 8546 --ws.origins '*' --http --http.api web3,eth,net --http.addr 0.0.0.0 --http.corsdomain '*' --http.port 8545 --http.vhosts '*' &" >> run-node
RUN chmod +x run-node

RUN touch reset
RUN echo "#!/bin/bash" >> reset
RUN echo "echo '- Kill geth'" >> reset
RUN echo "pkill -INT geth" >> reset
RUN echo "sleep 5" >> reset
RUN echo "echo '- Clear data'" >> reset
RUN echo "rm -rf /data/chain/*" >> reset
RUN echo "echo '- Restart geth'" >> reset
RUN echo "./run-node" >> reset
RUN echo "sleep 5" >> reset
RUN echo "echo '- Fund admin'" >> reset
RUN echo "./fund-admin" >> reset
RUN echo "echo '- Done'" >> reset
RUN chmod +x reset

RUN touch run
RUN echo "#!/bin/bash" >> run

FROM base AS expose-cloudflare
RUN curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${arch}.deb
RUN dpkg -i cloudflared.deb
RUN echo "cloudflared tunnel --metrics 0.0.0.0:11111 run --token $cloudflare_token_http --url http://localhost:8545 &" >> run
RUN echo "cloudflared tunnel --metrics 0.0.0.0:11112 run --token $cloudflare_token_ws --url http://localhost:8546 &" >> run

FROM base AS expose-local
EXPOSE 8545
EXPOSE 8546

FROM expose-$expose_via AS final
RUN echo "./run-node" >> run
RUN echo "sleep infinity" >> run
RUN chmod +x run

CMD ["/bin/bash", "./run"]
18 changes: 18 additions & 0 deletions docker/job-creator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:latest as base
WORKDIR /usr/src/app

ARG doppler_config=dev

COPY . .
RUN go mod download && go mod verify
RUN go build -v .
RUN go install

RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sh

RUN touch run
RUN echo "#!/bin/bash" >> run
RUN echo "doppler run -p job-creator -c $doppler_config -- lilypad jobcreator" >> run
RUN chmod +x run

CMD ["/bin/bash", "./run"]
27 changes: 27 additions & 0 deletions docker/resource-provider/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:latest as base
WORKDIR /usr/src/app

ARG doppler_config=dev
ARG DOPPLER_TOKEN_BACALHAU
ARG DOPPLER_TOKEN_RESOURCE_PROVIDER

COPY . .
RUN go mod download && go mod verify
RUN go build -v .
RUN go install

RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sh

# RUN wget https://github.com/bacalhau-project/bacalhau/releases/download/v1.0.3/bacalhau_v1.0.3_linux_amd64.tar.gz
# RUN tar xfv bacalhau_v1.0.3_linux_amd64.tar.gz
# RUN mv bacalhau /usr/local/bin
# # RUN sysctl -w net.core.rmem_max=7500000
# # RUN sysctl -w net.core.wmem_max=7500000

RUN touch run
RUN echo "#!/bin/bash" >> run
#RUN echo "doppler run --token=$DOPPLER_TOKEN_BACALHAU -p bacalhau -c $doppler_config -- ./stack bacalhau-serve &" >> run
RUN echo "doppler run --token=$DOPPLER_TOKEN_RESOURCE_PROVIDER -p resource-provider -c $doppler_config -- lilypad resource-provider" >> run
RUN chmod +x run

CMD ["/bin/bash", "./run"]
32 changes: 32 additions & 0 deletions docker/solver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG expose_via=local

FROM golang:latest as base
WORKDIR /usr/src/app

ARG arch=amd64
ARG doppler_config=dev
ARG cloudflare_token="not-a-token"

COPY . .
RUN go mod download && go mod verify
RUN go build -v .
RUN go install

RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sh

RUN touch run
RUN echo "#!/bin/bash" >> run

FROM base AS expose-cloudflare
RUN curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${arch}.deb
RUN dpkg -i cloudflared.deb
RUN echo "cloudflared tunnel --metrics 0.0.0.0:11113 run --token $cloudflare_token --url http://localhost:8080 &" >> run

FROM base AS expose-local
EXPOSE 8080

FROM expose-$expose_via AS FINAL
RUN echo "doppler run -p solver -c $doppler_config -- lilypad solver" >> run
RUN chmod +x run

CMD ["/bin/bash", "./run"]
Loading

0 comments on commit e04d15e

Please sign in to comment.