Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/docker-build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ jobs:
run: |
echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV

- name: Compute version string
run: |
SHA12="${GITHUB_SHA:0:12}"
BRANCH="${GITHUB_REF_NAME}"
if [ -z "${BRANCH}" ]; then
VERSION="dev"
else
VERSION="dev/${BRANCH}@${SHA12}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV

- name: Build and push Docker image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ env.REPO_LC }}-snapshot:dev
build-args: |
VERSION=${{ env.VERSION }}

- name: Set lowercase package name
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-docker-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
build-args: |
VERSION=${{ github.ref_name }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@00014ed6ed5efc5b1ab7f7f34a39eb55d41aa4f8 # v3.1.0
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM golang:1.25.6 AS builder
# Set the working directory inside the container
WORKDIR /app

# Build argument for version injection
ARG VERSION=dev

# Copy the Go modules manifest and download dependencies
COPY go.mod go.sum ./
RUN go mod download
Expand All @@ -14,8 +17,8 @@ COPY . .
# Ensures a statically linked binary
ENV CGO_ENABLED=0

# Build the Go server
RUN go build -mod=readonly -o server .
# Build the Go server with version injection
RUN go build -mod=readonly -o server -ldflags "-X 'main.Version=${VERSION}'" .

# Use a minimal base image for running the compiled binary
FROM gcr.io/distroless/base-debian13
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"github.com/UnitVectorY-Labs/lockboxkms/internal/kms"
)

// Version is the application version, injected at build time via ldflags
var Version = "dev"

//go:embed templates/*
var templatesFS embed.FS

Expand Down Expand Up @@ -50,8 +53,12 @@ func main() {
// Regular expression for validating key names
keyNameRegex := regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)

// Load the HTML template from embedded filesystem
tpl := template.Must(template.ParseFS(templatesFS, "templates/index.html"))
log.Printf("Starting lockboxkms version %s", Version)

// Load the HTML template from embedded filesystem with version function
tpl := template.Must(template.New("index.html").Funcs(template.FuncMap{
"version": func() string { return Version },
}).ParseFS(templatesFS, "templates/index.html"))

// Set up HTTP handlers
http.HandleFunc("/", getHomeHandler(cfg, tpl))
Expand Down
23 changes: 23 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
body {
background-color: #f3f4f6;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
Expand Down Expand Up @@ -129,6 +130,20 @@
color: red;
margin-top: 1rem;
}

footer {
text-align: center;
color: #9ca3af;
font-size: 0.8em;
padding: 15px 10px;
}
footer a {
color: #6b7280;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
</style>
<script src="https://unpkg.com/htmx.org@2.0.3/dist/htmx.min.js" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx-ext-response-targets@2.0.1/response-targets.js" integrity="sha384-25EjMH+UroVBJlocVAefkTNIVpGryrC7PN/vwZFZrLDWJ64ZlgE+7tOg1z7pWEfW" crossorigin="anonymous"></script>
Expand Down Expand Up @@ -177,5 +192,13 @@ <h1>LockboxKMS</h1>
}
}
</script>
<footer>
<p>
<a href="https://github.com/UnitVectorY-Labs">UnitVectorY Labs</a> |
<a href="https://opensource.org/licenses/MIT">MIT License</a> |
<a href="https://github.com/UnitVectorY-Labs/lockboxkms"><strong>lockboxkms</strong> on GitHub</a>
</p>
<p>Version: {{ version }}</p>
</footer>
</body>
</html>
Loading