From 5b39e448d2519eee652473ecc6a63f69dd1728e6 Mon Sep 17 00:00:00 2001 From: Imbus Date: Wed, 18 Oct 2023 20:52:51 +0200 Subject: [PATCH] Justfile comments and some new targets, Containerfile for debug server --- ContainerfileDebug | 36 ++++++++++++++++++++++++++++++++++++ justfile | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 ContainerfileDebug diff --git a/ContainerfileDebug b/ContainerfileDebug new file mode 100644 index 0000000..0877b41 --- /dev/null +++ b/ContainerfileDebug @@ -0,0 +1,36 @@ +# This file builds the server only, and does not copy the frontend build. +# This is useful for frontend development, as it allows you to run the frontend +# with an actual backend. +# Note that this runs the server in debug mode, which is slower than release mode. + +# Builds the server in an isolated stage +# We use musl to get a truly static binary +# that runs cleanly without depending on glibc. +FROM docker.io/rust:latest as builder +WORKDIR /build +ADD ./server /build +RUN apt update +RUN apt install musl musl-dev musl-tools -y +RUN rustup target add x86_64-unknown-linux-musl +# Note that '--release' is missing here, so we build in debug mode +RUN cargo build --target x86_64-unknown-linux-musl + +# Final stage, copy the server binary and the frontend build +# This stage is the actual container, and is based on alpine +# a minimal linux distribution resulting in a small image. +FROM docker.io/alpine:latest as runner + +# Add a non-root user for running the server +RUN addgroup -S user && adduser -S user -G user + +WORKDIR /runner +# Copy the server binary and the public directory, note the debug binary +COPY --from=builder /build/target/x86_64-unknown-linux-musl/debug/server /runner/server + +# Make sure the user can access the files +RUN chown -R user:user /runner +USER user + +# Run the server +EXPOSE 8080 +CMD ["./server"] diff --git a/justfile b/justfile index 7b5af42..9ffdd99 100644 --- a/justfile +++ b/justfile @@ -1,22 +1,54 @@ -dev: +# Builds a debug container and runs it +# Starts the client in dev mode +dev: start-debug npm-install cd client && npm run dev -build-client: +# Builds the client with npm (result in client/distt +npm-install: cd client && npm install + +# Builds the client with npm (result in client/dist) +npm-build: npm-install cd client && npm run build -# npm run build places the build in the server/public directory -build-container: +# Builds a debug container +build-container-server-debug: + podman build -t fb-server-debug -f ContainerfileDebug . + +# Builds a debug container and runs it +start-debug: build-container-server-debug + podman container rm -f frostbyte-debug + podman run -d -p 8080:8080 --name frostbyte-debug fb-server-debug + +# Builds a release container +build-container-release: podman build -t fb-server . -start-release: build-container +# Builds a release container and runs it +start-release: build-container-release podman container rm -f frostbyte podman run -d -p 8080:8080 --name frostbyte fb-server +# Deletes everything podman related (even unrelated to the project) +prune-podman: + podman stop -a + podman rm -af + podman system prune -af + podman image rm -af + podman system reset --force + +# Cleans up everything related to the project clean: podman container rm -f frostbyte + podman container rm -f frostbyte-debug podman image rm -f fb-server + podman image rm -f fb-server-debug rm -rf client/dist rm -rf client/node_modules rm -rf server/public - rm -rf server/target \ No newline at end of file + rm -rf server/target + @echo "Cleaned up! Make sure to run 'just prune-podman' to nuke everything podman related." + +# Nukes everything. No mercy. Leave no trace. +nuke: clean prune-podman + @echo "Nuked everything! You're starting from scratch now."