Files

77 lines
2.6 KiB
Docker

# Builds Fleet entirely from source, including the frontend bundle.
# Unlike ./Dockerfile (used by GoReleaser, which copies pre-built binaries),
# this file is meant for direct `docker build` usage and CI pipelines.
########## Stage 1: frontend assets ##########
FROM node:24-alpine AS frontend
WORKDIR /build
# Install JS dependencies first so this layer is cached
# unless package.json / yarn.lock change.
COPY package.json yarn.lock .yarnrc ./
RUN yarn --frozen-lockfile --network-timeout 600000
# Copy sources needed for the webpack production build.
COPY webpack.config.js babel.config.json postcss.config.js tsconfig.json ./
COPY frontend ./frontend
COPY assets ./assets
RUN NODE_ENV=production yarn run webpack
########## Stage 2: Go binary (with embedded frontend) ##########
FROM golang:1.26.5-alpine AS builder
WORKDIR /build
RUN apk add --no-cache git gcc musl-dev
# Download Go modules first so this layer is cached
# unless go.mod / go.sum change.
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Overlay the webpack-built bundle (assets/bundle.js) onto assets/.
COPY --from=frontend /build/assets ./assets
# Embed frontend templates, assets, and mail templates into Go source.
RUN go run github.com/kevinburke/go-bindata/go-bindata -pkg=bindata -tags full \
-o=server/bindata/generated.go \
frontend/templates/ assets/... server/mail/templates
ARG FLEET_VERSION=testing
RUN CGO_ENABLED=1 GOOS=linux go build -o fleet \
-tags=full,fts5,netgo \
-trimpath \
-ldflags="-s -w -extldflags '-static' \
-X github.com/fleetdm/fleet/v4/server/version.appName=fleet \
-X github.com/fleetdm/fleet/v4/server/version.version=${FLEET_VERSION}" \
./cmd/fleet
########## Stage 3: runtime ##########
FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11
ARG FLEET_VERSION=testing
LABEL maintainer="Fleet Developers"
LABEL org.opencontainers.image.version="${FLEET_VERSION}"
LABEL org.opencontainers.image.vendor="Fleet Device Management Inc."
LABEL org.opencontainers.image.title="fleet"
LABEL org.opencontainers.image.source="https://github.com/fleetdm/fleet"
LABEL org.opencontainers.image.url="https://fleetdm.com"
LABEL org.opencontainers.image.documentation="https://fleetdm.com/docs"
RUN apk --update add ca-certificates
RUN apk --no-cache add jq
RUN apk --no-cache upgrade openssl libcrypto3 libssl3
# Create fleet group and user
RUN addgroup -S fleet && adduser -S fleet -G fleet
# Create installers directory (Render mounts a persistent disk here)
RUN mkdir -p /opt/fleet/installers && chown -R fleet:fleet /opt/fleet
USER fleet
COPY --from=builder /build/fleet /usr/bin/fleet
CMD ["fleet", "serve"]