add Dockerfile, docker-compose, and scripts for frontend tunnel setup
This commit is contained in:
81
Frontend/Dockerfile.tunnel
Normal file
81
Frontend/Dockerfile.tunnel
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
FROM node:18-alpine AS builder
|
||||||
|
|
||||||
|
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
|
||||||
|
RUN apk update && apk add --no-cache supervisor wget
|
||||||
|
|
||||||
|
# Get cloudflared
|
||||||
|
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/
|
||||||
|
|
||||||
|
# Create directories for cloudflared
|
||||||
|
RUN mkdir -p /etc/cloudflared
|
||||||
|
|
||||||
|
# Copy the credentials and config
|
||||||
|
COPY credentials.json /etc/cloudflared/credentials.json
|
||||||
|
COPY config.json /etc/cloudflared/config.json
|
||||||
|
|
||||||
|
# Setup DNS routing for the tunnel
|
||||||
|
RUN cloudflared tunnel route dns 8c559c7c-42bb-4b9d-96a2-99cefd274b06 monaco.ishikabhoyar.tech || echo "DNS routing already set up or failed - continuing anyway"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
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
|
||||||
|
|
||||||
|
# Expose port 8001
|
||||||
|
EXPOSE 8001
|
||||||
|
|
||||||
|
# Use supervisord to manage processes
|
||||||
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||||
13
Frontend/config.json
Normal file
13
Frontend/config.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"tunnel": "8c559c7c-42bb-4b9d-96a2-99cefd274b06",
|
||||||
|
"credentials-file": "/etc/cloudflared/credentials.json",
|
||||||
|
"ingress": [
|
||||||
|
{
|
||||||
|
"hostname": "monaco.ishikabhoyar.tech",
|
||||||
|
"service": "http://localhost:8001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "http_status:404"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
Frontend/credentials.json
Normal file
5
Frontend/credentials.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"AccountTag": "453afb9373a00a55876e6127cf0efd97",
|
||||||
|
"TunnelSecret": "afJ6YY25rj9+G6qqHy+2jss4h+QKfw6YntijRZvo4ZQ=",
|
||||||
|
"TunnelID": "8c559c7c-42bb-4b9d-96a2-99cefd274b06"
|
||||||
|
}
|
||||||
19
Frontend/docker-compose.tunnel.yml
Normal file
19
Frontend/docker-compose.tunnel.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
frontend-tunnel:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile.tunnel
|
||||||
|
ports:
|
||||||
|
- "8001:8001"
|
||||||
|
restart: unless-stopped
|
||||||
|
container_name: monaco-frontend-tunnel
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
networks:
|
||||||
|
- monaco-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
monaco-network:
|
||||||
|
driver: bridge
|
||||||
51
Frontend/start-tunnel.sh
Normal file
51
Frontend/start-tunnel.sh
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${GREEN}================================${NC}"
|
||||||
|
echo -e "${GREEN}Monaco Frontend Tunnel Setup${NC}"
|
||||||
|
echo -e "${GREEN}================================${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if credentials.json exists
|
||||||
|
if [ ! -f "credentials.json" ]; then
|
||||||
|
echo -e "${RED}Error: credentials.json not found!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if config.json exists
|
||||||
|
if [ ! -f "config.json" ]; then
|
||||||
|
echo -e "${RED}Error: config.json not found!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Building Docker image...${NC}"
|
||||||
|
docker-compose -f docker-compose.tunnel.yml build
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}Build successful!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Starting services...${NC}"
|
||||||
|
docker-compose -f docker-compose.tunnel.yml up -d
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}Services started successfully!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}Frontend is now accessible at:${NC}"
|
||||||
|
echo -e " ${YELLOW}Local:${NC} http://localhost:8001"
|
||||||
|
echo -e " ${YELLOW}Tunnel:${NC} https://monaco.ishikabhoyar.tech"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}To view logs:${NC} docker-compose -f docker-compose.tunnel.yml logs -f"
|
||||||
|
echo -e "${YELLOW}To stop:${NC} docker-compose -f docker-compose.tunnel.yml down"
|
||||||
|
else
|
||||||
|
echo -e "${RED}Failed to start services!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${RED}Build failed!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user