# Easy Gate Cloudron Package
#
# Easy Gate is a web dashboard that acts as the central hub for self-hosted
# infrastructure: services and notes are parsed in real time (hot reload,
# once per second) from a JSON/YAML config file, and items can be assigned
# to user groups which only see them based on their IP subnet.
#
# Upstream: https://github.com/wiredlush/easy-gate (v2.0.3, Go 1.23, Fiber)
#   - Single static binary (CGO_ENABLED=0), listens on 0.0.0.0:8080
#   - No database, no user accounts, no migrations
#
# Authentication: Easy Gate has NO user concept (IP-subnet grouping only).
# Packaged behind Cloudron's authentication proxy (httpAuth.type = proxy).
FROM golang:1.23-alpine AS builder

WORKDIR /easy-gate

# Cache dependency downloads separately from source changes.
COPY repo/go.mod repo/go.sum ./
RUN go mod download

# Build the static binary (mirrors upstream Makefile flags).
COPY repo/ .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-w -s" -o build/easy-gate cmd/easy-gate/main.go

FROM cloudron/base:3.2.0

COPY --from=builder /easy-gate/build/easy-gate /usr/local/bin/easy-gate

# start.sh seeds /app/data/easy-gate.json on first run (behind_proxy: true)
# and execs the binary. Made executable on the host, not at build time.
COPY start.sh /app/start.sh

WORKDIR /app/data

EXPOSE 8080

CMD ["/bin/bash", "/app/start.sh"]
