Skip to content

Commit c70b9b8

Browse files
committed
Validate in docker
1 parent 1e43457 commit c70b9b8

4 files changed

Lines changed: 57 additions & 4 deletions

File tree

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
storage/*.sqlite3
2+
log/*
3+
tmp/*
4+
.git
5+
node_modules

Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,25 @@ FROM base
4848
RUN apt-get update -qq && \
4949
apt-get install --no-install-recommends -y \
5050
libsecp256k1-dev \
51-
libyaml-0-2 && \
51+
libyaml-0-2 \
52+
ca-certificates \
53+
tini \
54+
bash && \
5255
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
5356

5457
# Copy built artifacts
5558
COPY --from=build /usr/local/bundle /usr/local/bundle
5659
COPY --from=build /rails /rails
5760

61+
# Copy and set up entrypoint script
62+
COPY docker-entrypoint.sh /usr/local/bin/
63+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
64+
5865
# Set up non-root user
5966
RUN useradd rails --create-home --shell /bin/bash && \
6067
chown -R rails:rails log tmp storage
6168
USER rails:rails
6269

63-
# Set up databases (creates SQLite files even when validation disabled)
64-
RUN DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:setup db:schema:load:queue
70+
# Database initialization moved to runtime in entrypoint script
6571

66-
CMD ["bundle", "exec", "clockwork", "config/derive_ethscriptions_blocks.rb"]
72+
ENTRYPOINT ["tini", "--", "/usr/local/bin/docker-entrypoint.sh"]

docker-compose/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ services:
3535
PROFILE_IMPORT: ${PROFILE_IMPORT:-true}
3636
ETHSCRIPTIONS_API_BASE_URL: ${ETHSCRIPTIONS_API_BASE_URL-''}
3737
DEBUG: 0
38+
volumes:
39+
- node-storage:/rails/storage
3840
depends_on:
3941
geth:
4042
condition: service_healthy
4143

4244
volumes:
4345
geth-data:
46+
node-storage:

docker-entrypoint.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
export RAILS_ENV="${RAILS_ENV:-production}"
5+
6+
# Initialize DBs on first run if using a fresh/mounted volume
7+
set +e
8+
if [ ! -f "storage/production.sqlite3" ] || [ ! -f "storage/production_queue.sqlite3" ]; then
9+
echo "Initializing databases..."
10+
DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:setup db:schema:load:queue
11+
else
12+
echo "Running any pending migrations..."
13+
bundle exec rails db:migrate
14+
fi
15+
set -e
16+
17+
echo "Starting SolidQueue workers..."
18+
bundle exec bin/jobs &
19+
JOBS_PID=$!
20+
21+
echo "Starting importer..."
22+
bundle exec clockwork config/derive_ethscriptions_blocks.rb &
23+
CLOCKWORK_PID=$!
24+
25+
cleanup() {
26+
echo "Shutting down..."
27+
kill "${JOBS_PID:-}" "${CLOCKWORK_PID:-}" 2>/dev/null || true
28+
29+
# Optionally reap children to avoid zombies (tini also reaps)
30+
wait "${JOBS_PID:-}" "${CLOCKWORK_PID:-}" 2>/dev/null || true
31+
}
32+
trap cleanup SIGTERM SIGINT
33+
34+
# Wait for either process to exit and preserve its exit code
35+
wait -n
36+
exit_code=$?
37+
echo "One process exited, shutting down..."
38+
kill "${JOBS_PID:-}" "${CLOCKWORK_PID:-}" 2>/dev/null || true
39+
exit "$exit_code"

0 commit comments

Comments
 (0)