-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (52 loc) · 1.63 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Use the official Dart SDK image as base
FROM dart:stable AS build
# Set the working directory
WORKDIR /app
# Copy pubspec files and get dependencies
COPY pubspec.* ./
RUN dart pub get --no-precompile
# Copy the rest of the application
COPY . .
# Ensure dependencies are properly installed
RUN dart pub get --offline
# Compile the application
RUN dart compile exe lib/main.dart \
-o bitcoin_ath_bot
# # Create a smaller runtime image
FROM debian:stable-slim
# Install cron
RUN apt-get update && apt-get install -y cron \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /app
# Copy the compiled executable
COPY --from=build /app/bitcoin_ath_bot ./
# Create a wrapper script that loads environment variables and runs the bot
RUN echo '#!/bin/sh\n\
# Load environment variables\n\
if [ -f /app/env.sh ]; then\n\
. /app/env.sh\n\
fi\n\
/app/bitcoin_ath_bot >> /var/log/cron.log 2>&1' > /app/run-bot.sh \
&& chmod +x /app/run-bot.sh
# Create env.sh script (will be populated at runtime)
RUN touch /app/env.sh && chmod +x /app/env.sh
# Script to setup environment variables and start services
COPY <<-"EOF" /app/entrypoint.sh
#!/bin/sh
# Clear existing env.sh
echo "#!/bin/sh" > /app/env.sh
# Export all environment variables to env.sh
env | while read -r line; do
echo "export $line" >> /app/env.sh
done
# Start cron and tail logs
cron && tail -f /var/log/cron.log
EOF
RUN chmod +x /app/entrypoint.sh
# Set up the cron job
RUN echo "*/1 * * * * /app/run-bot.sh" | crontab -
# Create the log file
RUN touch /var/log/cron.log
# Use the entrypoint script instead of direct cron command
CMD ["/app/entrypoint.sh"]