diff --git a/.gitignore b/.gitignore index e939f9e..cf72dc8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ data main.log input frontend/.vscode +backend/vendor +backend/deploy.tar diff --git a/backend/captain-definition b/backend/captain-definition new file mode 100644 index 0000000..462dc51 --- /dev/null +++ b/backend/captain-definition @@ -0,0 +1,4 @@ +{ + "schemaVersion": 2, + "dockerfilePath": "./dockerfile" +} \ No newline at end of file diff --git a/backend/deploy.sh b/backend/deploy.sh new file mode 100644 index 0000000..6259d2f --- /dev/null +++ b/backend/deploy.sh @@ -0,0 +1 @@ +go mod vendor && tar -cf deploy.tar *.sql *.go dockerfile captain-definition go.mod go.sum vendor \ No newline at end of file diff --git a/backend/dockerfile b/backend/dockerfile new file mode 100644 index 0000000..7da819f --- /dev/null +++ b/backend/dockerfile @@ -0,0 +1,45 @@ +# Build stage +# FROM golang:1.23-bullseye as base +FROM golang:bullseye as base + +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid 65532 \ + small-user + +WORKDIR /app + +COPY . . + +# RUN go mod download +# RUN go mod verify + +RUN GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main . + +# Final stage +# Pick your poison +# Ordered by size desc +# FROM ubuntu:latest +# FROM alpine:latest +FROM scratch + +# Run this for ubuntu +# RUN apt-get update && apt-get install -y curl vim git && apt-get clean + +# Copy the binary from the build stage +COPY --from=base /app/main /main + +# Copy necessary files from the build stage +COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=base /etc/passwd /etc/passwd +COPY --from=base /etc/group /etc/group + +# Use the non-root user +# USER small-user +EXPOSE 8090 + +CMD ["/main"] \ No newline at end of file