From 45696fd0a973755bbf4639158414a07aa298f210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Fri, 28 Mar 2025 13:50:10 +0100 Subject: [PATCH] feat: docker --- .dockerignore | 3 +++ Containerfile | 17 +++++++++++++++++ docker-compose.yml | 7 +++++++ main.go | 7 ++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Containerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d7d6600 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +healthr +healthr.db diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..b9c8d26 --- /dev/null +++ b/Containerfile @@ -0,0 +1,17 @@ +FROM golang:alpine AS backend_build +WORKDIR /app + +COPY go.mod ./ +RUN go mod download + +COPY . . + +RUN go build -o /healthr + +FROM alpine:edge AS backend + +COPY --from=backend_build /healthr /healthr + +EXPOSE 8090 + +CMD [ "/healthr" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7331561 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + healthr: + build: + context: . + dockerfile: Containerfile + ports: + - 8090:8090 diff --git a/main.go b/main.go index 8c70fe7..ce6bd84 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main -import "log" +import ( + "fmt" + "log" +) func main() { var db Database = &SqliteDatabase{} @@ -9,5 +12,7 @@ func main() { if err != nil { log.Fatal("There was an error initializing the database %w", err) } + + fmt.Println("Starting healthr webserver.") webServer(db) }