Skip to content

Commit

Permalink
Add WebUI for S3 bucket (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps authored Oct 10, 2024
1 parent dc9d8bb commit 16d3979
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build:
make -C packages/system/kubeovn image
make -C packages/system/dashboard image
make -C packages/system/kamaji image
make -C packages/system/bucket image
make -C packages/core/testing image
make -C packages/core/installer image
make manifests
Expand Down
8 changes: 8 additions & 0 deletions packages/apps/bucket/templates/dashboard-resourcemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ rules:
- secrets
resourceNames:
- {{ .Release.Name }}
- {{ .Release.Name }}-credentials
verbs: ["get", "list", "watch"]
- apiGroups:
- networking.k8s.io
resources:
- ingresses
resourceNames:
- {{ .Release.Name }}-ui
verbs: ["get", "list", "watch"]
18 changes: 18 additions & 0 deletions packages/apps/bucket/templates/helmrelease.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: {{ .Release.Name }}-system
spec:
chart:
spec:
chart: cozy-bucket
reconcileStrategy: Revision
sourceRef:
kind: HelmRepository
name: cozystack-system
namespace: cozy-system
version: '*'
interval: 1m0s
timeout: 5m0s
values:
bucketName: {{ .Release.Name }}
2 changes: 2 additions & 0 deletions packages/system/bucket/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hack
.gitkeep
3 changes: 3 additions & 0 deletions packages/system/bucket/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: cozy-bucket
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process
25 changes: 25 additions & 0 deletions packages/system/bucket/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
S3MANAGER_TAG=v0.5.0

export NAME=s3manager-system

include ../../../scripts/common-envs.mk
include ../../../scripts/package.mk

update:
rm -rf charts
helm pull oci://ghcr.io/aenix-io/charts/etcd-operator --untar --untardir charts

image: image-s3manager

image-s3manager:
docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 images/s3manager \
--provenance false \
--tag $(REGISTRY)/s3manager:$(call settag,$(S3MANAGER_TAG)) \
--cache-from type=registry,ref=$(REGISTRY)/s3manager:latest \
--cache-to type=inline \
--metadata-file images/s3manager.json \
--push=$(PUSH) \
--load=$(LOAD)
echo "$(REGISTRY)/s3manager:$(call settag,$(S3MANAGER_TAG))@$$(yq e '."containerimage.digest"' images/s3manager.json -o json -r)" \
> images/s3manager.tag
rm -f images/s3manager.json
1 change: 1 addition & 0 deletions packages/system/bucket/images/s3manager.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ghcr.io/aenix-io/cozystack/s3manager:latest@sha256:7a1a0864f823dc3343d79dffa44ab73f77f0e1b3642a0fe0fa29b280c3184a9b
20 changes: 20 additions & 0 deletions packages/system/bucket/images/s3manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Source: https://github.com/cloudlena/s3manager/blob/main/Dockerfile

FROM docker.io/library/golang:1 AS builder
WORKDIR /usr/src/app
RUN wget -O- https://github.com/cloudlena/s3manager/archive/9a7c8e446b422f8973b8c461990f39fdafee9c27.tar.gz | tar -xzf- --strip 1
ADD cozystack.patch /
RUN git apply /cozystack.patch
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o bin/s3manager

FROM docker.io/library/alpine:latest
WORKDIR /usr/src/app
RUN addgroup -S s3manager && adduser -S s3manager -G s3manager
RUN apk add --no-cache \
ca-certificates \
dumb-init
COPY --from=builder --chown=s3manager:s3manager /usr/src/app/bin/s3manager ./
USER s3manager
EXPOSE 8080
ENTRYPOINT [ "/usr/bin/dumb-init", "--" ]
CMD [ "/usr/src/app/s3manager" ]
26 changes: 26 additions & 0 deletions packages/system/bucket/images/s3manager/cozystack.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/web/template/bucket.html.tmpl b/web/template/bucket.html.tmpl
index e2f8d28..87add13 100644
--- a/web/template/bucket.html.tmpl
+++ b/web/template/bucket.html.tmpl
@@ -13,7 +13,7 @@

<nav class="nav-extended">
<div class="nav-wrapper container">
- <a href="/buckets/{{$.BucketName}}" class="brand-logo center"><i class="material-icons">folder_open</i>{{ .BucketName }}</a>
+ <a href="/" class="brand-logo">Cozystack S3 Manager</a>
{{ if not .Objects }}
<ul class="right">
<li>
diff --git a/web/template/buckets.html.tmpl b/web/template/buckets.html.tmpl
index c7ea184..fb1dce7 100644
--- a/web/template/buckets.html.tmpl
+++ b/web/template/buckets.html.tmpl
@@ -1,7 +1,7 @@
{{ define "content" }}
<nav>
<div class="nav-wrapper container">
- <a href="/" class="brand-logo">S3 Manager</a>
+ <a href="/" class="brand-logo">Cozystack S3 Manager</a>
</div>
</nav>

35 changes: 35 additions & 0 deletions packages/system/bucket/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.bucketName }}-ui
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.bucketName }}-ui
template:
metadata:
labels:
app: {{ .Values.bucketName }}-ui
spec:
containers:
- name: s3manager
image: "{{ $.Files.Get "images/s3manager.tag" | trim }}"
env:
- name: ENDPOINT
valueFrom:
secretKeyRef:
name: {{ .Values.bucketName }}-credentials
key: endpoint
- name: SKIP_SSL_VERIFICATION
value: "true"
- name: ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{ .Values.bucketName }}-credentials
key: accessKey
- name: SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.bucketName }}-credentials
key: secretKey
28 changes: 28 additions & 0 deletions packages/system/bucket/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
{{- $host := index $myNS.metadata.annotations "namespace.cozystack.io/host" }}
{{- $ingress := index $myNS.metadata.annotations "namespace.cozystack.io/ingress" }}

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.bucketName }}-ui
annotations:
nginx.ingress.kubernetes.io/auth-type: "basic"
nginx.ingress.kubernetes.io/auth-secret: "{{ .Values.bucketName }}-ui-auth"
nginx.ingress.kubernetes.io/auth-realm: "Authentication Required"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/proxy-read-timeout: "99999"
nginx.ingress.kubernetes.io/proxy-send-timeout: "99999"
spec:
ingressClassName: {{ $ingress }}
rules:
- host: {{ .Values.bucketName }}.{{ $host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Values.bucketName }}-ui
port:
number: 8080
22 changes: 22 additions & 0 deletions packages/system/bucket/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace .Values.bucketName }}
{{- $bucketInfo := fromJson (b64dec (index $existingSecret.data "BucketInfo")) }}
{{- $accessKeyID := index $bucketInfo.spec.secretS3 "accessKeyID" }}
{{- $accessSecretKey := index $bucketInfo.spec.secretS3 "accessSecretKey" }}
{{- $endpoint := index $bucketInfo.spec.secretS3 "endpoint" }}

apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.bucketName }}-credentials
type: Opaque
stringData:
accessKey: {{ $accessKeyID | quote }}
secretKey: {{ $accessSecretKey | quote }}
endpoint: {{ trimPrefix "https://" $endpoint }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.bucketName }}-ui-auth
data:
auth: {{ htpasswd $accessKeyID $accessSecretKey | b64enc | quote }}
12 changes: 12 additions & 0 deletions packages/system/bucket/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.bucketName }}-ui
spec:
selector:
app: {{ .Values.bucketName }}-ui
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: ClusterIP
1 change: 1 addition & 0 deletions packages/system/bucket/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bucketName: ""

0 comments on commit 16d3979

Please sign in to comment.