refactor Dockerfile and configuration for cloudflared tunnel setup
This commit is contained in:
@@ -1,26 +1,10 @@
|
||||
FROM node:18-alpine AS builder
|
||||
# Final stage
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM nginx:alpine
|
||||
|
||||
# Install supervisor and cloudflared
|
||||
# Install supervisor and wget
|
||||
RUN apk update && apk add --no-cache supervisor wget
|
||||
|
||||
# Get cloudflared
|
||||
# Get cloudflared directly from GitHub
|
||||
RUN wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/download/2023.5.0/cloudflared-linux-amd64 && \
|
||||
chmod +x cloudflared && \
|
||||
mv cloudflared /usr/local/bin/
|
||||
@@ -28,51 +12,24 @@ RUN wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/downl
|
||||
# Create directories for cloudflared
|
||||
RUN mkdir -p /etc/cloudflared
|
||||
|
||||
# Copy the credentials and config
|
||||
# Copy the cloudflared config and credentials
|
||||
COPY credentials.json /etc/cloudflared/credentials.json
|
||||
COPY config.json /etc/cloudflared/config.json
|
||||
|
||||
# Copy built files from builder
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Create nginx config for port 8001
|
||||
RUN echo 'server {' > /etc/nginx/conf.d/default.conf && \
|
||||
echo ' listen 8001;' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' server_name localhost;' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' root /usr/share/nginx/html;' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' index index.html;' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo '' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' location / {' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' try_files $uri $uri/ /index.html;' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo ' }' >> /etc/nginx/conf.d/default.conf && \
|
||||
echo '}' >> /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Create supervisord config
|
||||
# Create supervisord config (only cloudflared, no frontend inside container)
|
||||
RUN mkdir -p /etc/supervisor/conf.d/
|
||||
RUN echo '[supervisord]' > /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'nodaemon=true' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'user=root' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo '' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo '[program:nginx]' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'command=nginx -g "daemon off;"' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'autostart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'autorestart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stderr_logfile=/dev/stderr' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo '' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo '[program:cloudflared]' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'command=cloudflared tunnel --config /etc/cloudflared/config.json run' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'autostart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'autorestart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stderr_logfile=/dev/stderr' >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf
|
||||
RUN echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "user=root" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "[program:cloudflared]" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "command=cloudflared tunnel --config /etc/cloudflared/config.json run" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "autostart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "autorestart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "stdout_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||
echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Expose port 8001
|
||||
EXPOSE 8001
|
||||
|
||||
# Use supervisord to manage processes
|
||||
# Use supervisord to manage cloudflared
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
|
||||
Reference in New Issue
Block a user