Skip to content

Commit

Permalink
Add workflow and Dockerfile necessary to build the rust services (#13)
Browse files Browse the repository at this point in the history
* Add workflow and Dockerfile necessary to build the rust services

* Use ghcr

* Add permission for workflow

* Add tilt configs

* Add monitor service image
  • Loading branch information
m30m authored Feb 7, 2024
1 parent 57de360 commit 7a53ef1
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/push-rust-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and Push Rust Services Image
on:
push:
tags:
- v*
workflow_dispatch:
inputs:
dispatch_description:
description: "Dispatch description"
required: true
type: string
permissions:
contents: read
id-token: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
server-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set image tag to version of the git tag
if: ${{ startsWith(github.ref, 'refs/tags/server-v') }}
run: |
PREFIX="refs/tags/server-"
VERSION="${GITHUB_REF:${#PREFIX}}"
echo "IMAGE_TAG=${VERSION}" >> "${GITHUB_ENV}"
- name: Set image tag to the git commit hash
if: ${{ !startsWith(github.ref, 'refs/tags/server-v') }}
run: |
echo "IMAGE_TAG=${{ github.sha }}" >> "${GITHUB_ENV}"
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta_server
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Extract metadata (tags, labels) for Docker
id: meta_monitor
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-monitor
- name: Build and push server docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta_server.outputs.tags }}
labels: ${{ steps.meta_server.outputs.labels }}
- name: Build and push vault monitor docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ./per_sdk/Dockerfile
push: true
tags: ${{ steps.meta_monitor.outputs.tags }}
labels: ${{ steps.meta_monitor.outputs.labels }}
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG RUST_VERSION=1.66.1

# Get the solidity dependencies using npm
FROM node:21-alpine3.18 AS npm_build
WORKDIR /src
COPY per_multicall per_multicall
WORKDIR /src/per_multicall
RUN npm install


FROM rust:${RUST_VERSION} AS build
# Set default toolchain
RUN rustup default nightly-2023-07-23

# Install dependencies
RUN curl -L https://foundry.paradigm.xyz | bash
ENV PATH="${PATH}:/root/.foundry/bin/"
RUN foundryup

# Add solidity dependencies
WORKDIR /src
COPY per_multicall per_multicall
COPY --from=npm_build /src/per_multicall/node_modules/ /src/per_multicall/node_modules/
WORKDIR /src/per_multicall
RUN forge install foundry-rs/forge-std --no-git --no-commit
RUN forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit

# Build auction-server
WORKDIR /src
COPY auction-server auction-server
WORKDIR /src/auction-server
RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release

# Build vault-simulator
WORKDIR /src
COPY vault-simulator vault-simulator
WORKDIR /src/vault-simulator
RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release


FROM rust:${RUST_VERSION}
# Copy artifacts from other images
COPY --from=build /src/auction-server/target/release/auction-server /usr/local/bin/
COPY --from=build /src/vault-simulator/target/release/vault-simulator /usr/local/bin/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ The updated enviornment variables can then be seen via `env`. We can then run th
pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo.

The checks are also performed in the CI to ensure the code follows consistent formatting.

### Development with Tilt

Run `tilt up --namespace dev-<YOUR_NAMESPACE>` to start tilt.
13 changes: 13 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load('ext://configmap', 'configmap_create')
default_registry("192824654885.dkr.ecr.eu-west-2.amazonaws.com", single_name="development")
allow_k8s_contexts(["arn:aws:eks:eu-west-2:192824654885:cluster/violet"])
if k8s_namespace() == 'default':
fail("failing early to avoid deploying to 'default' namespace")

docker_build("server", ".",
only=["./auction-server", "./vault-simulator", "./per_multicall"],
ignore=["./auction-server/target", "./auction-server/config.yaml", "./vault-simulator/target", "./per_multicall/lib", "./per_multicall/node_modules"],
dockerfile="./Dockerfile")
k8s_yaml("./tilt/deployment.yaml")
configmap_create('auction-server-config', from_file=['config.yaml=./tilt/config.yaml'])
k8s_resource("per-server", port_forwards=["9000:9000"])
2 changes: 1 addition & 1 deletion per_multicall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Run the following commands to install necessary libraries:

```shell
$ npm install @pythnetwork/pyth-sdk-solidity
$ npm install
$ forge install foundry-rs/forge-std --no-git --no-commit
$ forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit
```
Expand Down
62 changes: 62 additions & 0 deletions per_sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
ARG RUST_VERSION=1.66.1
ARG PYTHON_VERSION=3.11
ARG POETRY_VERSION=1.6.1

FROM node:21-alpine3.18 AS npm_build

WORKDIR /src
COPY per_multicall per_multicall
WORKDIR /src/per_multicall
RUN npm install


FROM rust:${RUST_VERSION} AS contract_build
# Set default toolchain
RUN rustup default nightly-2023-07-23

# Install dependencies
RUN curl -L https://foundry.paradigm.xyz | bash
ENV PATH="${PATH}:/root/.foundry/bin/"
RUN foundryup

# Add solidity dependencies
WORKDIR /src
COPY per_multicall per_multicall
COPY --from=npm_build /src/per_multicall/node_modules/ /src/per_multicall/node_modules/
WORKDIR /src/per_multicall
RUN forge install foundry-rs/forge-std --no-git --no-commit
RUN forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit
RUN forge build --via-ir


FROM python:$PYTHON_VERSION


ARG APP_NAME
ARG APP_PATH
ARG POETRY_VERSION

ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
POETRY_VERSION=$POETRY_VERSION \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1

# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python
ENV PATH="$POETRY_HOME/bin:$PATH"

# Copy only requirements to cache them in docker layer
WORKDIR /src
COPY per_sdk/poetry.lock per_sdk/pyproject.toml /src/per_sdk/
COPY --from=contract_build /src/per_multicall/out/ /src/per_multicall/out/

# Project initialization:
RUN poetry -C per_sdk install --no-interaction --no-ansi

# Creating folders, and files for a project:
COPY per_sdk/ /src/per_sdk
41 changes: 41 additions & 0 deletions tilt/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: per-server
spec:
selector:
matchLabels:
app: per-server
replicas: 1
template:
metadata:
labels:
app: per-server
spec:
containers:
- name: anvil
image: ghcr.io/foundry-rs/foundry:latest
command:
- /bin/sh
- -c
- "anvil --gas-limit 500000000000000000 --block-time 1"
- name: auction-server
image: server
command:
- /bin/sh
- -c
- "auction-server run"
volumeMounts:
- name: config-vol
mountPath: /config
readOnly: true
env:
# default first private key of anvil
- name: PER_PRIVATE_KEY
value: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
- name: PER_CONFIG
value: /config/config.yaml
volumes:
- name: config-vol
configMap:
name: auction-server-config

0 comments on commit 7a53ef1

Please sign in to comment.