add demo app
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
FROM golang:1.22-alpine AS build
|
||||
WORKDIR /src
|
||||
COPY go.mod ./
|
||||
COPY main.go ./
|
||||
RUN CGO_ENABLED=0 go build -o /app .
|
||||
|
||||
FROM alpine:3.20
|
||||
COPY --from=build /app /app
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/app"]
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
@Library('devops-lib') _
|
||||
homelabPipeline(repo_name: 'demo-go-app')
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
# Read by devops-lib's loadConfig stage after checkout — merges into the
|
||||
# pipeline's config map, overriding whatever homelabPipeline(repo_name: ...)
|
||||
# passed in the Jenkinsfile. Everything here is optional; this file exists
|
||||
# mainly to prove the hooks mechanism actually runs, not because this app
|
||||
# needs to override any of the pipeline defaults.
|
||||
hooks:
|
||||
pre_build:
|
||||
- name: gofmt-check
|
||||
script: scripts/pre-build-check.sh
|
||||
# Advisory on purpose for this demo — a real repo would probably
|
||||
# want this blocking (the default), but failing the one demo app
|
||||
# over a formatting nit isn't the point here.
|
||||
blocking: false
|
||||
post_build:
|
||||
- name: report-tag
|
||||
script: scripts/post-build-notify.sh
|
||||
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Read from the environment, not baked in at build time — the Helm
|
||||
// chart's deployment.env sets APP_VERSION from the same image tag
|
||||
// updateHelmTag.groovy just bumped, so curling /version proves the
|
||||
// whole CI/CD loop (build -> push -> tag-bump -> deploy) actually
|
||||
// worked end to end, not just that "some" image is running.
|
||||
version := os.Getenv("APP_VERSION")
|
||||
if version == "" {
|
||||
version = "dev"
|
||||
}
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello from demo-go-app, version %s\n", version)
|
||||
})
|
||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintln(w, "ok")
|
||||
})
|
||||
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, version)
|
||||
})
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
log.Printf("listening on :%s (version %s)", port, version)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# Proves HOOK_IMAGE_TAG is actually populated post-build (empty during
|
||||
# pre_build, since buildDocker hasn't set env.TAG yet at that point).
|
||||
set -e
|
||||
echo "post_build hook: ${HOOK_REPO} built and pushed as tag ${HOOK_IMAGE_TAG}"
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# Runs in the docker-cli container (Alpine, no Go toolchain — the actual
|
||||
# Go build happens inside the Dockerfile's golang:1.22-alpine builder
|
||||
# stage, not on the agent itself). Kept simple on purpose: this exists to
|
||||
# prove the hooks mechanism runs, not to be a real lint step.
|
||||
set -e
|
||||
echo "pre_build hook running for ${HOOK_REPO} (phase=${HOOK_PHASE})"
|
||||
test -f go.mod || { echo "go.mod missing"; exit 1; }
|
||||
test -f Dockerfile || { echo "Dockerfile missing"; exit 1; }
|
||||
echo "go.mod and Dockerfile both present — looks buildable."
|
||||
Reference in New Issue
Block a user