diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..77c33af --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.codex +dist +web/dist +web/node_modules +**/.DS_Store diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d0bcf7c --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Host port mapping +MINDFS_PORT=7331 + +# MindFS runtime options inside the container +MINDFS_ADDR=0.0.0.0:7331 +MINDFS_ROOT=/workspace + +# Docker Compose restart policy +MINDFS_RESTART=unless-stopped diff --git a/.gitignore b/.gitignore index 4b38567..2acdcea 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,10 @@ dist/ build/ *.log .env* +!.env.example *.exe *.test vendor/ *.out design/ -/mindfs \ No newline at end of file +/mindfs diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6483a8b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM archlinux:latest AS base + +RUN pacman -Syu --noconfirm \ + ca-certificates \ + git \ + go \ + nodejs \ + npm \ + && pacman -Scc --noconfirm + +FROM base AS web-builder + +WORKDIR /src/web + +COPY web/package.json web/package-lock.json ./ +RUN npm ci \ + && npm cache clean --force \ + && rm -rf /root/.npm + +COPY web/ ./ +RUN npm run build \ + && npm cache clean --force \ + && rm -rf /root/.npm + +FROM base AS go-builder + +ARG VERSION=dev +ARG TARGETOS=linux +ARG TARGETARCH + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY cli/ ./cli/ +COPY server/ ./server/ + +RUN CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH:-amd64}" \ + go build -trimpath -ldflags "-s -w" \ + -o /out/mindfs ./cli/cmd \ + && go clean -modcache -cache + +FROM base AS runtime + +RUN mkdir -p /opt/mindfs/bin /opt/mindfs/share/mindfs /workspace + +COPY --from=go-builder /out/mindfs /opt/mindfs/bin/mindfs +COPY --from=web-builder /src/web/dist /opt/mindfs/share/mindfs/web +COPY agents.json /opt/mindfs/share/mindfs/agents.json + +WORKDIR /workspace + +EXPOSE 7331 + +ENTRYPOINT ["/opt/mindfs/bin/mindfs"] +CMD ["--foreground", "-addr", "0.0.0.0:7331", "/workspace"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e025d03 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ +services: + mindfs: + build: + context: . + dockerfile: Dockerfile + ports: + - "${MINDFS_PORT:-7331}:7331" + volumes: + - ./workspace:/workspace + - ./data/config:/root/.config + - ./data/local:/root/.local + command: + - --foreground + - -addr + - ${MINDFS_ADDR:-0.0.0.0:7331} + - ${MINDFS_ROOT:-/workspace} + restart: ${MINDFS_RESTART:-unless-stopped}