Skip to content

Commit

Permalink
add version information to status endpoint, use alpine as base image
Browse files Browse the repository at this point in the history
  • Loading branch information
denyskon committed Jan 6, 2024
1 parent 7830b60 commit f66ad06
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ postalion

LICENSE
README.md
.git
.github

7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
FROM golang:1.21-alpine AS build-stage

RUN apk add --no-cache git

WORKDIR /usr/src/app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go build -o /app/postalion
RUN go build -o /app/postalion -v -ldflags="-X 'github.com/denyskon/postalion/version.version=$(git describe)'"

FROM alpine:latest AS build-release-stage

COPY --from=build-stage /app/postalion /app/postalion
COPY templates /app/templates

VOLUME /app/templates
Expand Down
11 changes: 2 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package main
import (
"fmt"
"net/http"
"runtime/debug"

mail_services "github.com/denyskon/postalion/email"
form_service "github.com/denyskon/postalion/form"
"github.com/denyskon/postalion/version"
"github.com/go-playground/validator/v10"
"github.com/gorilla/pat"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -64,15 +64,8 @@ func main() {

router.Post("/form/{name}", formHandler)
router.Get("/status", func(wr http.ResponseWriter, req *http.Request) {
info, ok := debug.ReadBuildInfo()
if !ok {
log.Error("Failed to read build info")
wr.WriteHeader(http.StatusInternalServerError)
wr.Write([]byte("Failed to read build info"))
}

wr.WriteHeader(http.StatusOK)
wr.Write([]byte(fmt.Sprintf("POSTalion %s", info.Main.Version)))
wr.Write([]byte(fmt.Sprintf("POSTalion %s", version.Version())))
})

http.Handle("/", router)
Expand Down
7 changes: 7 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package version

var version = "development"

func Version() string {
return version
}

0 comments on commit f66ad06

Please sign in to comment.