Skip to content

Commit

Permalink
Add ddex to audius-compose and improve its build (#7013)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoilie authored Dec 21, 2023
1 parent d364016 commit 9e337d5
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .circleci/src/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
name: push-ddex
context: [GCP, dockerhub, slack-secrets]
service: ddex
# notify_slack_on_failure: true
notify_slack_on_failure: true

- push-arm-image:
name: push-discovery-provider-arm
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
- push-healthz
- push-protocol-dashboard
- push-uptime
# - push-ddex
- push-ddex
# uncomment these when arm builds are stable
# - push-identity-service-arm
# - push-mediorum-arm
Expand Down
1 change: 1 addition & 0 deletions dev-tools/audius-compose
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def build(
"--profile=solana",
"--profile=block-explorer",
"--profile=uptime",
"--profile=ddex",
"build",
*args,
*services,
Expand Down
14 changes: 14 additions & 0 deletions dev-tools/compose/docker-compose.ddex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.9'

services:
ddex:
container_name: ddex
build:
context: ${PROJECT_ROOT}/packages/ddex
dockerfile: Dockerfile
args:
app_name: ddex
TURBO_TEAM: '${TURBO_TEAM}'
TURBO_TOKEN: '${TURBO_TOKEN}'
profiles:
- ddex
8 changes: 8 additions & 0 deletions dev-tools/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ services:
service: sla-auditor
<<: *common

# DDEX

ddex:
extends:
file: docker-compose.ddex.yml
service: ddex
<<: *common

# Storage (content node)

mediorum:
Expand Down
11 changes: 11 additions & 0 deletions packages/ddex/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
dist/
logs/
.git/
.gitignore
.vscode/
README.md
Dockerfile
.dockerignore
.env
.env.*
26 changes: 14 additions & 12 deletions packages/ddex/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
FROM node:18.17-slim

RUN apt update && apt install -y python3 make gcc g++

ENV WORKDIR /app
WORKDIR ${WORKDIR}
FROM node:18.17-slim as builder
RUN apt-get update && apt-get install -y python3 make gcc g++
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

COPY index.html package.json postcss.config.js tailwind.config.js tsconfig.json tsconfig.node.json vite.config.ts ./
ADD src ./src
ADD public ./public
ADD scripts ./scripts
RUN chmod +x ./scripts/docker-entrypoint.sh
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/dist /tmp/dist

RUN npm install
RUN apk add --no-cache findutils coreutils
COPY ./scripts/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
14 changes: 14 additions & 0 deletions packages/ddex/Dockerfile.fast
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# To use this file for testing on staging:
# 0. npm i && npm run build
# 1. in docker-compose.ddex.yml, set dockerfile to Dockerfile.fast
# 2. comment out dist/ in .dockerignore
# 3. run audius-compose push --prod "ddex" (first do env = os.environ.copy() and env["DOCKER_DEFAULT_PLATFORM"] = "linux/amd64") in the audius-compose build command code)

FROM alpine:latest
WORKDIR /app
RUN apk add --no-cache findutils coreutils
COPY dist /tmp/dist

COPY ./scripts/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
35 changes: 22 additions & 13 deletions packages/ddex/scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#!/bin/sh

FIRST_RUN_FLAG="./.firstrun"
# Directory where build artifacts are stored in the image before being copied to the volume
TEMP_BUILD_DIR="/tmp/dist"

if [ ! -f "$FIRST_RUN_FLAG" ]; then
echo "Building dist..."
npm run build
# Directory mounted as a volume
VOLUME_DIR="/app/dist"

if [ $? -eq 0 ]; then
echo "Successfully built dist"
touch "$FIRST_RUN_FLAG"
else
echo "'npm run build' failed with exit code $?. Exiting..."
exit 1
fi
# Calculate the current checksum of the temporary build directory
CHECKSUM_FILE="$VOLUME_DIR/.checksum"
current_checksum=$(find "$TEMP_BUILD_DIR" -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1)

# Read the last checksum (if it exists)
last_checksum=""
if [ -f "$CHECKSUM_FILE" ]; then
last_checksum=$(cat "$CHECKSUM_FILE")
fi

# Compare checksums and copy if different
if [ "$current_checksum" != "$last_checksum" ]; then
echo "Changes detected. Updating files in volume..."
cp -r $TEMP_BUILD_DIR/* $VOLUME_DIR/
echo "$current_checksum" > "$CHECKSUM_FILE"
else
echo "dist already built"
echo "No changes detected. No update needed."
fi

exec npm run serve
# Keep the container running by tailing /dev/null
tail -f /dev/null

0 comments on commit 9e337d5

Please sign in to comment.