TTime/container/Containerfile

42 lines
1,006 B
Text
Raw Normal View History

2024-02-12 12:30:38 +01:00
# 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:alpine as client
2024-02-12 12:30:38 +01:00
WORKDIR /build
ADD frontend /build
RUN npm install
RUN npm run build
# Builds the server in an isolated stage
FROM docker.io/golang:alpine as go
RUN apk add gcompat
RUN apk add gcc
RUN apk add musl-dev
2024-02-12 12:30:38 +01:00
ADD backend /build
WORKDIR /build
# Get the dependencies
RUN go mod download
# RUN go build -o server
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./cmd/
# The final stage for building a minimal image
FROM docker.io/alpine:latest as runner
WORKDIR /app
# Copy the frontend SPA build into public
COPY --from=client /build/dist /app/static
# Copy the server binary
COPY --from=go /build/server /app/server
# Copy the migration scripts
COPY --from=go /build/migrations /app/migrations
2024-02-12 12:30:38 +01:00
# Expose port 8080
EXPOSE 8080
# Run the server
CMD ["./server"]