From 3e30701c64eafe738b89278fc2d62ae4200c688b Mon Sep 17 00:00:00 2001 From: Jintao Zhang Date: Wed, 20 Sep 2023 14:39:47 +0800 Subject: [PATCH] chore: add Dockerfile (#51) Signed-off-by: Jintao Zhang --- .dockerignore | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 22 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3aae539 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..882a9f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION=1.20 +ARG VERSION=dev +FROM golang:${GO_VERSION} AS build +WORKDIR /src + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + CGO_ENABLED=0 go build -o /bin/adc -ldflags "-X github.com/api7/adc/cmd.VERSION=$VERSION -X github.com/api7/adc/cmd.GitRevision=$VERSION" . + +FROM alpine:3.18 AS final + +# Copy the executable from the "build" stage. +COPY --from=build --chown=appuser:appuser /bin/adc /bin/ + +CMD /bin/adc