Skip to content

Commit

Permalink
Dockerize#24
Browse files Browse the repository at this point in the history
  • Loading branch information
4TT1L4 committed Mar 21, 2024
1 parent 2b00c23 commit 7d70285
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
# ==================================[ BUILD ]========================================
WORKDIR /DEX

# COPY **/*.cabal ./
# RUN cabal build --only-dependencies -j4 geniusyield-orderbot
# TODO: first build only dependencies

COPY . .

RUN cabal update
RUN cabal build all

Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'
services:
backend:
image: sha256:4e7f93853238619bc97207db356730e5d6b1f50b80f270d91e623b5867d26943
container_name: backend
secrets:
- CORE_MAESTRO_API_KEY
- MAESTRO_API_KEY
- SERVER_API_KEY
environment:
SERVER_CONFIG: |
coreProvider:
maestroToken: <<CORE_MAESTRO_API_KEY>>
turboSubmit: false
networkId: "mainnet" # supported: mainner ot preprod
logging:
- type: {tag: stderr}
severity: "Debug" # Debug, Info, Warning or Error
verbosity: V2 # Available: `V0`, `V1`, `V2`, `V3` and `V4` (See katip docs for details)
port: 8082
maestroToken: <<MAESTRO_API_KEY>>
serverApiKey: <<SERVER_API_KEY>>
restart: always
secrets:
CORE_MAESTRO_API_KEY: { file: ./secrets/core_maestro_api_key }
MAESTRO_API_KEY: { file: ./secrets/maesto_api_key }
SERVER_API_KEY: { file: ./secrets/server_api_key }
49 changes: 49 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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 "===================================="
# TODO: remove
echo $SERVER_CONFIG
echo "===================================="
echo "Starting geniusyield-server..."
set -x
cabal run geniusyield-server -- serve

0 comments on commit 7d70285

Please sign in to comment.