From 454fe9b4bc3bde4760962fd8292a0bd799321617 Mon Sep 17 00:00:00 2001 From: Bhasher Date: Wed, 3 Jan 2024 18:13:54 +0100 Subject: [PATCH] Dockerfiles --- backend/.dockerignore | 4 ++++ backend/Dockerfile | 20 ++++++++++++++++++++ backend/main.go | 8 +++++++- frontend/.dockerignore | 10 ++++++++++ frontend/Dockerfile | 17 +++++++++++++++++ frontend/package-lock.json | 10 ++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..5776730 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,4 @@ +*.sqlite +Dockerfile +docker-compose.yaml +.dockerignore \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..97795ab --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.21.5 as backend-builder + +WORKDIR /app + +COPY . . + +RUN CGO_ENABLED=1 GOOS=linux go build -o main . + +# FROM alpine:latest +FROM debian:stable-slim + +VOLUME /data +WORKDIR /app + +COPY --from=backend-builder /app/main . + +EXPOSE 3000 +ENV DB_PATH=/data/db.sqlite + +CMD ["./main"] diff --git a/backend/main.go b/backend/main.go index 2a1d353..f36533e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" @@ -14,8 +15,13 @@ import ( func main() { driver := "sqlite3" - connStr := "db.sqlite" port := "3000" + connStr := os.Getenv("DB_PATH") + + if connStr == "" { + connStr = "db.sqlite" + } + origins := "*" if err := db.InitDB(driver, connStr); err != nil { diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..3427079 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,10 @@ +node_modules +.eslint* +.prettier* +.git* +Dockerfile +docker-compose.yaml +public +.svelte-kot +build +.dockerignore \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..58da63c --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,17 @@ +FROM node:20 as frontend-builder + +WORKDIR /app + +COPY . . + +RUN npm install +RUN npm run build + +FROM node:20-alpine + +# COPY --from=frontend-builder /app/public /usr/share/nginx/html +COPY --from=frontend-builder /app . + +EXPOSE 4173 + +CMD ["npm", "run", "preview", "--", "--port", "4173", "--host", "0.0.0.0"] diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c623709..441383d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,6 +15,7 @@ "devDependencies": { "@playwright/test": "^1.28.1", "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-static": "^3.0.1", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@types/eslint": "8.56.0", @@ -835,6 +836,15 @@ "@sveltejs/kit": "^2.0.0" } }, + "node_modules/@sveltejs/adapter-static": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-3.0.1.tgz", + "integrity": "sha512-6lMvf7xYEJ+oGeR5L8DFJJrowkefTK6ZgA4JiMqoClMkKq0s6yvsd3FZfCFvX1fQ0tpCD7fkuRVHsnUVgsHyNg==", + "dev": true, + "peerDependencies": { + "@sveltejs/kit": "^2.0.0" + } + }, "node_modules/@sveltejs/kit": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.0.6.tgz",