From e263732e3ca49b621975e233905c41e9605e3f21 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Fri, 23 Aug 2024 01:02:33 +0200 Subject: [PATCH] feat: Add Dockerfile to build and containerize the application * Add basic Dockerfile * Add build CI pipeline * Some quick adaptations to the config file location --- .woodpecker/build.yaml | 20 ++++++++++++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ config.yaml => config/config.yaml | 0 main.go | 3 ++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .woodpecker/build.yaml create mode 100644 Dockerfile rename config.yaml => config/config.yaml (100%) diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml new file mode 100644 index 0000000..e2d8ad3 --- /dev/null +++ b/.woodpecker/build.yaml @@ -0,0 +1,20 @@ +--- +when: + branch: main + path: + - Dockerfile + - .woodpecker/build.yaml + +variables: + - &buildx woodpeckerci/plugin-docker-buildx:4.2.0 + - &buildx_settings + platforms: linux/amd64 + +steps: + dryrun: + image: *buildx + settings: + <<: *buildx_settings + dry_run: true + when: + event: pull_request \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..146b69c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.22.4 AS builder + +WORKDIR /app + +COPY go.mod go.sum main.go ./ +RUN go mod download +RUN go build + +FROM gcr.io/distroless/base-debian12 + +WORKDIR / + +COPY --from=builder /app/labtime /labtime + +# This is the port currently hardcoded in the application +EXPOSE 2112 + +# For now the config file path/name are hardcoded in the application +VOLUME ["/config"] + +USER nonroot:nonroot + +ENTRYPOINT ["/labtime"] \ No newline at end of file diff --git a/config.yaml b/config/config.yaml similarity index 100% rename from config.yaml rename to config/config.yaml diff --git a/main.go b/main.go index 324b750..531579c 100644 --- a/main.go +++ b/main.go @@ -89,7 +89,8 @@ func Ping(url string) (int, time.Duration, error) { func main() { // Load config - config, err := NewConfig("config.yaml") + // TODO: Use a flag to specify the config file + config, err := NewConfig("config/config.yaml") if err != nil { log.Fatalf("Error loading config: %s", err) }