From a5c8e5962ba25153a5a510640cfd4e2aa6e3bc84 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 27 Dec 2023 18:25:55 +0100 Subject: [PATCH] Add Dockerfile for project build Introduced Dockerfile to manage the build process for the project, including its dependencies. This development will standardize the environment, thus making it easier for others to build and run the app. Also added necessary 'passwd' and 'group' files in 'support-files' directory for managing user details in Docker. --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ support-files/group | 1 + support-files/passwd | 1 + 3 files changed, 36 insertions(+) create mode 100644 Dockerfile create mode 100644 support-files/group create mode 100644 support-files/passwd diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9eac18e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2023 Winni Neessen +# +# SPDX-License-Identifier: MIT + +## Build first +FROM golang:alpine AS builder +RUN mkdir /builddir +ADD cmd/ /builddir/cmd/ +ADD template/ /builddir/template +ADD *.go /builddir/ +ADD plugins/ /builddir/plugins +ADD go.mod /builddir/ +ADD go.sum /builddir/ +WORKDIR /builddir +RUN go mod tidy +RUN go mod download +RUN go mod verify +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags \ + '-w -s -extldflags "-static"' \ + -o /builddir/logranger github.com/wneessen/logranger/cmd/server + +## Create scratch image +FROM scratch +LABEL maintainer="wn@neessen.dev" +COPY ["support-files/passwd", "/etc/passwd"] +COPY ["support-files/group", "/etc/group"] +COPY --chown=logranger ["README.md", "/logranger/README.md"] +COPY --chown=logranger ["etc/logranger.toml", "/etc/logranger/"] +COPY --from=builder ["/builddir/logranger", "/logranger/logranger"] +WORKDIR /logranger +USER logranger +VOLUME ["/etc/logranger"] +EXPOSE 9099 +ENTRYPOINT ["/logranger/logranger"] \ No newline at end of file diff --git a/support-files/group b/support-files/group new file mode 100644 index 0000000..e366a17 --- /dev/null +++ b/support-files/group @@ -0,0 +1 @@ +logranger:x:1000:logranger \ No newline at end of file diff --git a/support-files/passwd b/support-files/passwd new file mode 100644 index 0000000..29a98a8 --- /dev/null +++ b/support-files/passwd @@ -0,0 +1 @@ +logranger:x:1000:1000:Logranger user:/logranger:/bin/false \ No newline at end of file