feat: docker

This commit is contained in:
trev 2025-03-13 05:03:45 -04:00
parent da993d9ef5
commit 4e9a3de12a
2 changed files with 29 additions and 62 deletions

View File

@ -1,49 +1,28 @@
## BUF BUILD # Nix builder
FROM bufbuild/buf:1.50.0 AS buf FROM nixos/nix:latest AS builder
WORKDIR /buf
# Create client and server services # Copy our source and setup our working dir.
COPY buf.yaml buf.gen.yaml base.openapi.yaml ./ COPY . /tmp/build
COPY proto ./proto WORKDIR /tmp/build
RUN buf generate
# Build our Nix environment
RUN nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
build
## CLIENT BUILD # Copy the Nix store closure into a directory. The Nix store closure is the
FROM node:22-alpine AS client # entire set of Nix store values that we need for our build.
WORKDIR /client RUN mkdir /tmp/nix-store-closure
RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure
# Install client dependencies # Final image is based on scratch. We copy a bunch of Nix dependencies
COPY client/package.json client/package-lock.json ./ # but they're fully self-contained so we don't need Nix anymore.
RUN npm ci FROM scratch
# Get client source WORKDIR /app
COPY client .
# Get buf service # Copy /nix/store
COPY --from=buf /buf/client/src/lib/services ./src/lib/services COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/build/result /app
# Build client CMD ["/app/bin/app"]
RUN npm run build
## SERVER BUILD
FROM golang:1.23 AS server
WORKDIR /server
# Install server dependencies
COPY server/go.mod server/go.sum ./
RUN go mod download && go mod verify
# Get server source
COPY server .
# Get client build
COPY --from=client /client/build ./client
# Get buf service
COPY --from=buf /buf/server/internal/services ./internal/services
# Build server
RUN go build -v -o /server/main .
CMD ["/server/main"]

View File

@ -35,6 +35,11 @@
name = "client"; name = "client";
src = gitignore.lib.gitignoreSource ./client; src = gitignore.lib.gitignoreSource ./client;
npmDepsHash = "sha256-hOmZZrCSuHyRQhG6M7Yu5uRLTdCYOL/giT4zUm9iTRE="; npmDepsHash = "sha256-hOmZZrCSuHyRQhG6M7Yu5uRLTdCYOL/giT4zUm9iTRE=";
nodejs = pkgs.nodejs_22;
installPhase = ''
cp -r build "$out"
chmod -R u+w "$out"
'';
}; };
in in
@ -123,26 +128,9 @@
pname = "trevstack"; pname = "trevstack";
version = "1.0"; version = "1.0";
src = gitignore.lib.gitignoreSource ./server; src = gitignore.lib.gitignoreSource ./server;
vendorHash = ""; vendorHash = "sha256-PE9ns1W+7/ZBBxb7+96aXqBTzpDo5tGcfnCXAV8vp8E=";
buildInputs = with pkgs; [ preBuild = ''
# Go backend
go
gotools
gopls
# Protobuf middleware
buf
protoc-gen-go
protoc-gen-connect-go
protoc-gen-es
protoc-gen-connect-openapi
# Svelte frontend
nodejs_22
];
configurePhase = ''
cp -r ${client} client cp -r ${client} client
''; '';
}; };