# syntax=docker/dockerfile:1

FROM golang:1.25-alpine

WORKDIR /workspace

RUN go install github.com/air-verse/air@latest

RUN apk add --no-cache \
    bash \
    ca-certificates \
    cni-plugins \
    containerd \
    containerd-ctr \
    git \
    iptables \
    make \
    tzdata \
    wget \
  && mkdir -p /opt/cni/bin \
  && (cp -a /usr/lib/cni/. /opt/cni/bin/ 2>/dev/null || true) \
  && (cp -a /usr/libexec/cni/. /opt/cni/bin/ 2>/dev/null || true) \
  && mkdir -p /etc/cni/net.d /var/lib/cni /run/containerd /var/lib/containerd /opt/memoh/data

RUN printf '%s\n' \
  '{' \
  '  "cniVersion": "1.0.0",' \
  '  "name": "memoh-cni",' \
  '  "plugins": [' \
  '    {' \
  '      "type": "bridge",' \
  '      "bridge": "cni0",' \
  '      "isGateway": true,' \
  '      "ipMasq": true,' \
  '      "hairpinMode": true,' \
  '      "ipam": {' \
  '        "type": "host-local",' \
  '        "ranges": [[' \
  '          { "subnet": "10.88.0.0/16" }' \
  '        ]],' \
  '        "routes": [' \
  '          { "dst": "0.0.0.0/0" }' \
  '        ]' \
  '      }' \
  '    },' \
  '    {' \
  '      "type": "portmap",' \
  '      "capabilities": { "portMappings": true }' \
  '    }' \
  '  ]' \
  '}' > /etc/cni/net.d/10-memoh.conflist

COPY docker/server-dev-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

VOLUME ["/var/lib/containerd", "/opt/memoh/data"]

EXPOSE 8080

ENTRYPOINT ["/entrypoint.sh"]
