Skip to content

Commit 588d2d7

Browse files
committed
add docker bake
1 parent 3ea572d commit 588d2d7

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

Dockerfile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ RUN go mod verify \
4141

4242
FROM alpine:3.20
4343

44-
# Traefik auto discover labels
45-
LABEL \
46-
traefik.http.services.portal-public-api-docs.loadbalancer.server.port="3020" \
47-
traefik.http.services.portal-public-api-docs.loadbalancer.healthcheck.path="/health" \
48-
traefik.http.services.portal-public-api-docs.loadbalancer.healthcheck.interval="10s" \
49-
traefik.http.services.portal-public-api-docs.loadbalancer.healthcheck.timeout="5s"
50-
5144
EXPOSE 3020
5245

5346
# Copy build artifacts from builder container
@@ -58,11 +51,10 @@ COPY --from=go-builder /go/src/app .
5851
ENV PORTAL_CLIENT_ROUTE="/"
5952
ENV PORTAL_PORT=3020
6053

61-
RUN addgroup -S go \
62-
&& adduser -S -G go go \
63-
&& chown -R go:go /go/src/app
54+
RUN addgroup --gid 1301 docs \
55+
&& adduser -u 444 -D -G docs docs \
56+
&& chown -R docs:docs /go/src/app
6457

65-
# Run as the go user
66-
USER go
58+
USER docs
6759

6860
CMD ["./server"]

docker-bake.hcl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Populated from GitHub Action
2+
variable "REPO" {
3+
default = ""
4+
}
5+
6+
group "default" {
7+
targets = [
8+
"portal-public-api-docs",
9+
]
10+
}
11+
12+
# Populated from GitHub Action
13+
target "docker-metadata-action" {
14+
tags = []
15+
}
16+
17+
target "bootstrap" {
18+
platforms = [ "linux/amd64" ]
19+
no-cache = true
20+
}
21+
22+
target "portal-public-api-docs" {
23+
inherits = ["bootstrap", "docker-metadata-action"]
24+
tags = [for tag in target.docker-metadata-action.tags : tag]
25+
dockerfile = "Dockerfile"
26+
}

scripts/docker.build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
REPO_NAME=quay.io/battelleecology/
3+
REPO_NAME=""
44
IMAGE_NAME=portal-public-api-docs
55

66
if [ -n "$1" ]; then

server/server.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ var (
2424
clientRoute string = os.Getenv("PORTAL_CLIENT_ROUTE")
2525
port string = os.Getenv("PORTAL_PORT")
2626
routeRegex = regexp.MustCompile(fmt.Sprintf(`^%s(.*)`, clientRoute))
27+
healthPath string = "/health"
28+
)
29+
30+
var (
31+
infoLog = log.New(os.Stdout, "", log.LstdFlags)
32+
errorLog = log.New(os.Stderr, "", log.LstdFlags)
2733
)
2834

2935
var healthResponse healthCheckResponse = healthCheckResponse{
3036
Status: "UP",
3137
}
3238

3339
func handleHealthCheck(w http.ResponseWriter) {
34-
log.Println("INFO: Health check up")
40+
infoLog.Println("INFO: Health check up")
3541
w.Header().Add("Content-Type", "application/json")
3642
if err := json.NewEncoder(w).Encode(healthResponse); err != nil {
3743
w.WriteHeader(http.StatusInternalServerError)
@@ -60,7 +66,7 @@ func (fs sanitizedFileSystem) Open(name string) (http.File, error) {
6066
if err != nil {
6167
return nil, err
6268
}
63-
s, err := f.Stat()
69+
s, _ := f.Stat()
6470
if s.IsDir() {
6571
index := fmt.Sprintf("%s/%s", strings.TrimSuffix(name, "/"), indexFilename)
6672
ff, err := fs.fs.Open(index)
@@ -77,7 +83,7 @@ func getRootHandlerFunc() http.HandlerFunc {
7783
handleFileServer := http.StripPrefix(clientRoute, fs)
7884
return func(w http.ResponseWriter, r *http.Request) {
7985
switch {
80-
case "/health" == r.URL.Path:
86+
case healthPath == r.URL.Path:
8187
handleHealthCheck(w)
8288
case routeRegex.MatchString(r.URL.Path):
8389
handleFileServer.ServeHTTP(w, r)
@@ -88,12 +94,12 @@ func getRootHandlerFunc() http.HandlerFunc {
8894
}
8995

9096
func main() {
91-
log.Println("INFO: Starting go static file server...")
97+
infoLog.Println("INFO: Starting go static file server...")
9298
runtime.GOMAXPROCS(runtime.NumCPU())
9399
http.HandleFunc("/", getRootHandlerFunc())
94-
log.Println(fmt.Sprintf("INFO: Listening on port %s", port))
95-
log.Println(fmt.Sprintf("INFO: Serving files from directory %s", fileDir))
100+
infoLog.Printf("INFO: Listening on port %s", port)
101+
infoLog.Printf("INFO: Serving files from directory %s", fileDir)
96102
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
97-
log.Fatalf("Error in ListenAndServe: %s", err)
103+
errorLog.Fatalf("Error in ListenAndServe: %s", err)
98104
}
99105
}

0 commit comments

Comments
 (0)