-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow and Dockerfile necessary to build the rust services (#13)
* 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
Showing
7 changed files
with
229 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,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 }} |
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,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/ |
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,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"]) |
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,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 |
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,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 |