Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/pyth-lazer-pusher-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Pyth Lazer Pusher Docker image CI

on:
push:
workflow_dispatch:
inputs:
tag:
description: 'Tag to give the build. Try to make it unique.'
required: true

env:
CHANNEL: ${{ inputs.tag || github.head_ref || github.ref_name }}
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
TAG_BASE: rainprotocol/bulk-trade-pusher

jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build bulk-trade-pusher image
run: |
docker build \
-f apps/pyth-lazer-pusher/bulk-trade-pusher/Dockerfile \
-t "$TAG_BASE:$CHANNEL" \
--build-arg GIT_SHA=${{ github.sha }} \
--build-arg DOCKER_CHANNEL=$CHANNEL \
.

- name: Push image
run: docker push "$TAG_BASE:$CHANNEL"
14 changes: 12 additions & 2 deletions apps/pyth-lazer-pusher/bulk-trade-pusher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ RUN --mount=type=cache,target=/root/.cargo/registry \

# Runtime
FROM debian:bookworm-slim

# set git sha and docker tag from build-time args to run-time env in container
ARG GIT_SHA
ARG DOCKER_CHANNEL
ENV GIT_COMMIT=$GIT_SHA
ENV DOCKER_TAG=$DOCKER_CHANNEL

RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
apt-get install -y --no-install-recommends ca-certificates bash && \
rm -rf /var/lib/apt/lists/* && \
useradd -r -u 1000 appuser

COPY --from=build /src/target/release/bulk-pusher /usr/local/bin/bulk-pusher
COPY apps/pyth-lazer-pusher/bulk-trade-pusher/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY apps/pyth-lazer-pusher/bulk-trade-pusher/config.toml /etc/bulk-pusher/config.toml
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

USER appuser
ENTRYPOINT ["/usr/local/bin/bulk-pusher"]
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
29 changes: 29 additions & 0 deletions apps/pyth-lazer-pusher/bulk-trade-pusher/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Docker entrypoint for bulk-trade-pusher.
# Converts the SIGNING_KEY_BASE58 env var into a temp key file so the binary
# can run without any mounted files (DigitalOcean / cloud deployment).
#
# Required env vars (set these in DigitalOcean App Platform):
#
# SIGNING_KEY_BASE58 Ed25519 private key (base58)
# BULK_PUSHER__LAZER__ACCESS_TOKEN Pyth Lazer access token
# BULK_PUSHER__LAZER__ENDPOINTS JSON array, e.g. '["wss://pyth-lazer-0.dourolabs.app/v1/stream"]'
# BULK_PUSHER__BULK__ENDPOINTS JSON array, e.g. '["wss://exchange-wss.bulk.trade/ws"]'
# BULK_PUSHER__BULK__ORACLE_ACCOUNT_PUBKEY_BASE58 Oracle account public key (base58)
# BULK_PUSHER__FEEDS__SUBSCRIPTIONS JSON array, e.g. '[{"feed_id":86,"channel":"fixed_rate_1000ms"}]'
#
# Optional env vars (have defaults):
# BULK_PUSHER__FEEDS__UPDATE_INTERVAL default: 100ms
# BULK_PUSHER__PROMETHEUS_ADDRESS default: 0.0.0.0:9090
# BULK_PUSHER__LAZER__NUM_CONNECTIONS default: 2
# BULK_PUSHER__LAZER__TIMEOUT default: 5s

set -e

if [ -n "${SIGNING_KEY_BASE58}" ]; then
echo "${SIGNING_KEY_BASE58}" > /tmp/signing.key
chmod 600 /tmp/signing.key
export BULK_PUSHER__BULK__SIGNING_KEY_PATH=/tmp/signing.key
fi

exec /usr/local/bin/bulk-pusher --config /etc/bulk-pusher/config.toml "$@"
13 changes: 9 additions & 4 deletions apps/pyth-lazer-pusher/bulk-trade-pusher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ pub struct BulkConfig {
pub fn load_config<P: AsRef<Path>>(path: P) -> anyhow::Result<Config> {
let path = path.as_ref();
let config: Config = config::Config::builder()
.add_source(File::with_name(
path.to_str().context("invalid config path")?,
))
.add_source(Environment::with_prefix("BULK_PUSHER").separator("__"))
.add_source(
File::with_name(path.to_str().context("invalid config path")?)
.required(false),
)
.add_source(
Environment::with_prefix("BULK_PUSHER")
.separator("__")
.try_parsing(true),
)
.build()?
.try_deserialize()?;

Expand Down