fix rebuild warmup

This commit is contained in:
Rayhan Hanaputra committed 2025-10-26 18:58:33 +07:00
1 parent fda1e6b4cd
commit 326f887eec
1 file changed
+11 -5
+11 -5
View File
@@ -30,7 +30,7 @@ RUN mkdir -p /opt/files && chmod 755 /opt && chmod 755 /opt/files
# Copy the built binary from builder stage # Copy the built binary from builder stage
COPY --from=builder /app/challenge /opt/challenge COPY --from=builder /app/challenge /opt/challenge
RUN chmod 755 /opt/challenge RUN chmod 755 /opt/challenge && chown ctfuser:ctfuser /opt/challenge
# Copy HTML template # Copy HTML template
COPY src/index.html /opt/index.html COPY src/index.html /opt/index.html
@@ -54,11 +54,17 @@ RUN chown ctfuser:ctfuser /opt/main.go && chmod 644 /opt/main.go
RUN echo '#!/bin/bash' > /opt/rebuild.sh && \ RUN echo '#!/bin/bash' > /opt/rebuild.sh && \
echo 'echo "Building patched challenge..."' >> /opt/rebuild.sh && \ echo 'echo "Building patched challenge..."' >> /opt/rebuild.sh && \
echo 'cd /opt' >> /opt/rebuild.sh && \ echo 'cd /opt' >> /opt/rebuild.sh && \
echo 'go build -o challenge main.go' >> /opt/rebuild.sh && \ echo 'go build -o challenge.new main.go' >> /opt/rebuild.sh && \
echo 'chmod 755 /opt/challenge' >> /opt/rebuild.sh && \ echo 'if [ $? -ne 0 ]; then' >> /opt/rebuild.sh && \
echo ' echo "Build failed!"' >> /opt/rebuild.sh && \
echo ' exit 1' >> /opt/rebuild.sh && \
echo 'fi' >> /opt/rebuild.sh && \
echo 'chmod 755 /opt/challenge.new' >> /opt/rebuild.sh && \
echo 'echo "Restarting challenge..."' >> /opt/rebuild.sh && \ echo 'echo "Restarting challenge..."' >> /opt/rebuild.sh && \
echo 'mv /opt/challenge.new /opt/challenge' >> /opt/rebuild.sh && \
echo 'pkill -f /opt/challenge' >> /opt/rebuild.sh && \ echo 'pkill -f /opt/challenge' >> /opt/rebuild.sh && \
echo '/opt/challenge >/var/log/challenge.log 2>&1 &' >> /opt/rebuild.sh && \ echo 'sleep 1' >> /opt/rebuild.sh && \
echo '/opt/challenge >/tmp/challenge.log 2>&1 &' >> /opt/rebuild.sh && \
echo 'echo "Challenge rebuilt and restarted!"' >> /opt/rebuild.sh && \ echo 'echo "Challenge rebuilt and restarted!"' >> /opt/rebuild.sh && \
chmod +x /opt/rebuild.sh && \ chmod +x /opt/rebuild.sh && \
chown ctfuser:ctfuser /opt/rebuild.sh chown ctfuser:ctfuser /opt/rebuild.sh
@@ -68,7 +74,7 @@ COPY nginx.conf /etc/nginx/sites-available/warmup
RUN ln -s /etc/nginx/sites-available/warmup /etc/nginx/sites-enabled/warmup && rm -f /etc/nginx/sites-enabled/default && chown root:root /etc/nginx/sites-available/warmup && chmod 644 /etc/nginx/sites-available/warmup RUN ln -s /etc/nginx/sites-available/warmup /etc/nginx/sites-enabled/warmup && rm -f /etc/nginx/sites-enabled/default && chown root:root /etc/nginx/sites-available/warmup && chmod 644 /etc/nginx/sites-available/warmup
# Create startup script # Create startup script
RUN echo '#!/bin/bash' > /opt/start.sh && echo 'set -e' >> /opt/start.sh && echo 'service ssh start' >> /opt/start.sh && echo 'nginx -t && service nginx start || echo "Nginx config error"' >> /opt/start.sh && echo '/opt/challenge >/var/log/challenge.log 2>&1 &' >> /opt/start.sh && echo 'echo $! > /opt/challenge.pid' >> /opt/start.sh && echo 'trap "if [ -f /opt/challenge.pid ]; then kill -TERM $(cat /opt/challenge.pid) 2>/dev/null || true; fi; exit 0" SIGTERM SIGINT' >> /opt/start.sh && echo 'taLine truncated RUN echo '#!/bin/bash' > /opt/start.sh && echo 'set -e' >> /opt/start.sh && echo 'service ssh start' >> /opt/start.sh && echo 'nginx -t && service nginx start || echo "Nginx config error"' >> /opt/start.sh && echo 'su - ctfuser -c "/opt/challenge >/tmp/challenge.log 2>&1 &"' >> /opt/start.sh && echo 'sleep 1' >> /opt/start.sh && echo 'pgrep -f /opt/challenge > /tmp/challenge.pid' >> /opt/start.sh && echo 'trap "if [ -f /tmp/challenge.pid ]; then kill -TERM $(cat /tmp/challenge.pid) 2>/dev/null Line truncated
EXPOSE 8080 22 EXPOSE 8080 22