# Tunnel-only Dockerfile V2 - Uses localhost with host network mode
FROM alpine:latest

# Install wget to download cloudflared
RUN apk update && apk add --no-cache wget ca-certificates

# 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/

# Create directories for cloudflared
RUN mkdir -p /etc/cloudflared

# Copy the certificate file and config
COPY cert.pem /etc/cloudflared/cert.pem
COPY credentials.json /etc/cloudflared/credentials.json
COPY config.tunnel-only-v2.json /etc/cloudflared/config.json

# Setup DNS routing for the tunnel (only needs to be done once)
RUN cloudflared tunnel route dns 5d2682ef-0b5b-47e5-b0fa-ad48968ce016 api.ishikabhoyar.tech || echo "DNS routing already set up or failed - continuing anyway"

# Run cloudflared tunnel
CMD ["cloudflared", "tunnel", "--config", "/etc/cloudflared/config.json", "run"]
