diff --git a/.github/workflows/push-rust-services.yaml b/.github/workflows/push-rust-services.yaml new file mode 100644 index 00000000..2df22f1a --- /dev/null +++ b/.github/workflows/push-rust-services.yaml @@ -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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7f670ab6 --- /dev/null +++ b/Dockerfile @@ -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/ diff --git a/README.md b/README.md index 73c0ff19..1072570b 100644 --- a/README.md +++ b/README.md @@ -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-` to start tilt. diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 00000000..f4a5408d --- /dev/null +++ b/Tiltfile @@ -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"]) diff --git a/per_multicall/README.md b/per_multicall/README.md index 03825d1d..45e41aa7 100644 --- a/per_multicall/README.md +++ b/per_multicall/README.md @@ -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 ``` diff --git a/per_sdk/Dockerfile b/per_sdk/Dockerfile new file mode 100644 index 00000000..dfa618b4 --- /dev/null +++ b/per_sdk/Dockerfile @@ -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 diff --git a/tilt/deployment.yaml b/tilt/deployment.yaml new file mode 100644 index 00000000..ce641cf6 --- /dev/null +++ b/tilt/deployment.yaml @@ -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