Skip to content

Commit

Permalink
Replace darkhttpd with cozystack-assets-server (#596)
Browse files Browse the repository at this point in the history
fixes #602
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Introduced a new custom assets server for serving static files
	- Replaced `darkhttpd` with a custom Go-based file server

- **Improvements**
	- Updated base images to Alpine Linux 3.21
	- Simplified container dependencies
	- Enhanced server configuration with command-line flags

- **Infrastructure**
	- Rebuilt Kubernetes deployment configuration for assets service
	- Updated server startup parameters and container settings
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
kvaps authored Jan 27, 2025
1 parent cc5eb47 commit 80b4c15
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
29 changes: 29 additions & 0 deletions cmd/cozystack-assets-server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"flag"
"log"
"net/http"
"path/filepath"
)

func main() {
addr := flag.String("address", ":8123", "Address to listen on")
dir := flag.String("dir", "/cozystack/assets", "Directory to serve files from")
flag.Parse()

absDir, err := filepath.Abs(*dir)
if err != nil {
log.Fatalf("Error getting absolute path for %s: %v", *dir, err)
}

fs := http.FileServer(http.Dir(absDir))
http.Handle("/", fs)

log.Printf("Server starting on %s, serving directory %s", *addr, absDir)

err = http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatalf("Server failed to start: %v", err)
}
}
11 changes: 7 additions & 4 deletions packages/core/installer/images/cozystack/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine3.19 as k8s-await-election-builder
FROM golang:alpine3.21 as k8s-await-election-builder

ARG K8S_AWAIT_ELECTION_GITREPO=https://github.com/LINBIT/k8s-await-election
ARG K8S_AWAIT_ELECTION_VERSION=0.4.1
Expand All @@ -13,27 +13,30 @@ RUN git clone ${K8S_AWAIT_ELECTION_GITREPO} /usr/local/go/k8s-await-election/ \
&& make \
&& mv ./out/k8s-await-election-${TARGETARCH} /k8s-await-election

FROM alpine:3.19 AS builder
FROM golang:alpine3.21 as builder

RUN apk add --no-cache make git
RUN apk add helm --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community

COPY . /src/
WORKDIR /src

RUN go build -o /cozystack-assets-server -ldflags '-extldflags "-static" -w -s' ./cmd/cozystack-assets-server

# Check that versions_map is not changed
RUN make repos

FROM alpine:3.19
FROM alpine:3.21

RUN apk add --no-cache make darkhttpd
RUN apk add --no-cache make
RUN apk add helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community

COPY scripts /cozystack/scripts
COPY --from=builder /src/packages/core /cozystack/packages/core
COPY --from=builder /src/packages/system /cozystack/packages/system
COPY --from=builder /src/_out/repos /cozystack/assets/repos
COPY --from=builder /src/_out/logos /cozystack/assets/logos
COPY --from=builder /cozystack-assets-server /usr/bin/cozystack-assets-server
COPY --from=k8s-await-election-builder /k8s-await-election /usr/bin/k8s-await-election
COPY dashboards /cozystack/assets/dashboards

Expand Down
9 changes: 4 additions & 5 deletions packages/core/installer/templates/cozystack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: darkhttpd
- name: assets
image: "{{ .Values.cozystack.image }}"
command:
- /usr/bin/darkhttpd
- /cozystack/assets
- --port
- "8123"
- /usr/bin/cozystack-assets-server
- "-dir=/cozystack/assets"
- "-address=:8123"
ports:
- name: http
containerPort: 8123
Expand Down

0 comments on commit 80b4c15

Please sign in to comment.