commit 7bfd8b73a86ac399aa0a097e91c262f7add86b22
parent c17291c696e3411b96c3637031f7619095f48e36
Author: Yongbin Kim <iam@yongbin.kim>
Date: Fri, 8 Sep 2023 19:03:25 +0900
Add docker-related files
Signed-off-by: Yongbin Kim <iam@yongbin.kim>
Diffstat:
3 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/.dockerignore b/.dockerignore
@@ -0,0 +1,10 @@
+# Ignore everything
+*
+
+# But not these files...
+!*.go
+!go.sum
+!go.mod
+
+# ...even if they are in subdirectories
+!*/
diff --git a/.gitignore b/.gitignore
@@ -9,6 +9,7 @@
# But not these files...
!/.gitignore
+!/.dockerignore
!*.go
!go.sum
@@ -19,5 +20,7 @@
!Makefile
+!Dockerfile
+
# ...even if they are in subdirectories
!*/
diff --git a/Dockerfile b/Dockerfile
@@ -0,0 +1,38 @@
+FROM golang:1.21-alpine AS builder
+
+ENV UID=10001
+
+RUN adduser \
+ --disabled-password \
+ --gecos "" \
+ --shell "/sbin/nologin" \
+ --no-create-home \
+ --uid "${UID}" \
+ "appuser"
+
+WORKDIR /app
+
+# Copy go mod and sum files
+COPY go.mod go.sum ./
+
+# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
+RUN go mod download
+RUN go mod verify
+
+# Copy the source from the current directory to the Working Directory inside the container
+COPY . .
+
+RUN go build -v -o /bin/functions ./cmd/functions
+
+
+FROM scratch
+
+COPY --from=builder /etc/passwd /etc/passwd
+COPY --from=builder /etc/group /etc/group
+COPY --from=builder /bin/functions /bin/functions
+
+USER appuser:appuser
+
+WORKDIR /
+
+ENTRYPOINT ["/bin/functions"]