From 726c83dbbb766375435e9c18d9dbc971b2c2670f Mon Sep 17 00:00:00 2001 From: Jona Heitzer Date: Fri, 3 Jan 2025 10:25:04 +0100 Subject: [PATCH] Prepare for deployment --- Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- static/index.html.tmpl | 4 ++-- static/result.html.tmpl | 4 ++-- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7af93b7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# Build stage +FROM golang:1.22-alpine AS builder + +WORKDIR /app + +# Copy and download dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy the source code +COPY . . + +# Install required packages for cgo +RUN apk add --no-cache gcc musl-dev + +# Build with cgo enabled +ENV CGO_ENABLED=1 + +# Build the Go application +RUN go build -o app . + +# Runtime stage +FROM alpine:latest + +WORKDIR /root/ + +# Install SQLite CLI for runtime +RUN apk add --no-cache sqlite + +# Copy the binary from the builder stage +COPY --from=builder /app/app . +COPY --from=builder /app/static/index.html.tmpl ./static/index.html.tmpl +COPY --from=builder /app/static/result.html.tmpl ./static/result.html.tmpl + +# Expose the port the app runs on +EXPOSE 8080 + +# Run the application +CMD ["./app"] + diff --git a/go.mod b/go.mod index 8d01cfe..fc2cf75 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module wa5p.eu/datefinder -go 1.22.0 +go 1.22 require github.com/mattn/go-sqlite3 v1.14.24 diff --git a/static/index.html.tmpl b/static/index.html.tmpl index c806c85..9ba78f3 100644 --- a/static/index.html.tmpl +++ b/static/index.html.tmpl @@ -116,7 +116,7 @@ console.log(`Submitting dates for ${submitName.value}`) console.log(JSON.stringify(choices)) - const url = "http://localhost:8080/api/submit"; + const url = "/api/submit"; fetch(url, { method: "POST", // Specify the HTTP method @@ -136,7 +136,7 @@ submitBtn.remove() submitNameLabel.remove() - const textNode = document.createTextNode("Choices submitted. Thx."); + const textNode = document.createTextNode("This is some text added to the body."); document.body.appendChild(textNode); }) .catch(error => { diff --git a/static/result.html.tmpl b/static/result.html.tmpl index 6364e22..4de2e59 100644 --- a/static/result.html.tmpl +++ b/static/result.html.tmpl @@ -118,7 +118,7 @@ tooltip.style.color = "white"; tooltip.style.borderRadius = "4px"; tooltip.style.fontSize = "12px"; - tooltip.style.visibility = "visible"; + tooltip.style.visibility = "hidden"; tooltip.style.whiteSpace = "nowrap"; tooltip.style.zIndex = "1000"; document.body.appendChild(tooltip); @@ -151,7 +151,7 @@ } } - const url = "http://localhost:8080/api/result/{{ .PollId }}" + const url = "/api/result/{{ .PollId }}" fetch(url, {method: "GET"}) .then(response => {