Restructure. Broken kube.yml, working compose.yml.

This commit is contained in:
Imbus 2023-10-20 03:28:22 +02:00
parent 3a3003be7e
commit a01d56405d
5 changed files with 31 additions and 2 deletions

42
container/Containerfile Normal file
View file

@ -0,0 +1,42 @@
# Client/frontend build in an isolated stage
# We use node:latest as the base image.
# Essentially we build the frontend SPA with vite and
# make it available in the public directory.
FROM docker.io/node:latest as client
WORKDIR /build
ADD ./client-solid /build
RUN npm install
RUN npm run build
# 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
RUN cargo build --target x86_64-unknown-linux-musl --release
# 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
COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/server /runner/server
# Copy the frontend SPA build into public
COPY --from=client /build/dist /runner/public
# Make sure the user can access the files
RUN chown -R user:user /runner
USER user
# Run the server
EXPOSE 8080
CMD ["./server"]

View file

@ -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"]

14
container/compose.yml Normal file
View file

@ -0,0 +1,14 @@
version: '3.3'
services:
frostbyte:
container_name: frostbyte
build:
context: "."
dockerfile: Containerfile
ports:
- '8080:8080'
restart: always
logging:
options:
max-size: 10m
image: frostbyte

15
container/kube.yml Normal file
View file

@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: frostbyte-pod
name: fbpod
spec:
containers:
- image: "."
# - image: localhost/fb-server:latest
name: frostbyte
ports:
- containerPort: 8080
hostPort: 8080
securityContext: {}