Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24 dockerize #25

Merged
merged 3 commits into from
Mar 21, 2024
Merged
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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Dockerfile
.*
secrets
secrets/*
dist-newstyle
.git
.github
.dockerignore
.gitignore
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM haskell:9.2.8-slim as builder

ENV LANG C.UTF-8

RUN apt-get update && \
apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
chrony \
libncursesw5 \
liblzma-dev \
libpq-dev \
libssl-dev \
libsystemd-dev \
libtool \
pkg-config \
procps \
snapd \
wget \
tmux && \
rm -rf /var/lib/apt/lists/*

# Update and install wget and ca-certificates to download yq
RUN wget https://github.com/mikefarah/yq/releases/download/v4.6.1/yq_linux_amd64 -O /usr/local/bin/yq && \
chmod +x /usr/local/bin/yq && \
rm -rf /var/lib/apt/lists/*

# Libsodium:
RUN git clone https://github.com/input-output-hk/libsodium && \
cd libsodium && \
git checkout dbb48cc && \
./autogen.sh && \
./configure && \
make && \
make install

# Libsecp256k1:
RUN git clone https://github.com/bitcoin-core/secp256k1 && \
cd secp256k1 && \
git checkout ac83be33d0956faf6b7f61a60ab524ef7d6a473a && \
./autogen.sh && \
./configure --prefix=/usr --enable-module-schnorrsig --enable-experimental && \
make && \
make install

ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

# ==================================[ BUILD ]========================================
WORKDIR /DEX

# TODO: first build only dependencies

COPY . .
RUN cabal update
RUN cabal build all --enable-tests --enable-benchmarks

# =============================[ SERVER ]================================
LABEL org.opencontainers.image.source="https://github.com/geniusyield/dex-contracts-api"

ENTRYPOINT ["/bin/bash", "./start.sh"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: build

build:
docker build -t ghcr.io/geniusyield/server:latest .

24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'
services:
server:
image: ghcr.io/geniusyield/server:latest
container_name: server
env_file:
- path: ./secrets/default.env
environment:
CORE_MAESTRO_API_KEY: ${CORE_MAESTRO_API_KEY}
MAESTRO_API_KEY: ${MAESTRO_API_KEY}
SERVER_API_KEY: ${SERVER_API_KEY}
SERVER_CONFIG: |
coreProvider:
maestroToken: <<CORE_MAESTRO_API_KEY>>
turboSubmit: false
networkId: "mainnet" # supported: mainnet ot preprod
logging:
- type: {tag: stderr}
severity: "Debug" # Options: Debug, Info, Warning or Error
verbosity: V2 # Options: `V0`, `V1`, `V2`, `V3` and `V4` (See katip docs for details)
port: 8082
maestroToken: <<MAESTRO_API_KEY>>
serverApiKey: <<SERVER_API_KEY>>
restart: always
46 changes: 46 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
echo "======[geniusyield-server]======"
echo "Startup checks...."
# Check if SERVER_CONFIG environment variable is set
if [ -z "./SERVER_CONFIG" ]; then
echo "Error: SERVER_CONFIG environment variable is not set." >&2
exit 1 # Exit code 1 for unset variable
fi
if [ -z "./CORE_MAESTRO_API_KEY" ]; then
echo "Error: CORE_MAESTRO_API_KEY environment variable is not set." >&2
exit 1 # Exit code 1 for unset variable
fi
if [ -z "./MAESTRO_API_KEY" ]; then
echo "Error: MAESTRO_API_KEY environment variable is not set." >&2
exit 1 # Exit code 1 for unset variable
fi
if [ -z "./SERVER_API_KEY" ]; then
echo "Error: SERVER_API_KEY environment variable is not set." >&2
exit 1 # Exit code 1 for unset variable
fi

# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "Error: yq is not installed. Please install yq to validate YAML content." >&2
exit 2 # Exit code 2 for yq not installed
fi

# Attempt to parse SERVER_CONFIG as YAML
echo "$SERVER_CONFIG" | yq eval . - > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: SERVER_CONFIG does not contain a valid YAML document." >&2
exit 3 # Exit code 3 for invalid YAML content
fi

# If the script reaches this point, SERVER_CONFIG is both set and valid
echo "SERVER_CONFIG is set and contains a valid YAML document."
echo "===================================="
echo "Replace placeholders...."
export SERVER_CONFIG=$(echo "$SERVER_CONFIG" | sed "s%<<CORE_MAESTRO_API_KEY>>%$CORE_MAESTRO_API_KEY%g")
export SERVER_CONFIG=$(echo "$SERVER_CONFIG" | sed "s%<<MAESTRO_API_KEY>>%$MAESTRO_API_KEY%g")
export SERVER_CONFIG=$(echo "$SERVER_CONFIG" | sed "s%<<SERVER_API_KEY>>%$SERVER_API_KEY%g")
echo "[OK] Done. Replaced placeholders."
echo "===================================="
echo "Starting geniusyield-server..."
set -x
cabal run geniusyield-server -- serve