Add kubernetes manifests and static file handler

This commit is contained in:
Tobias B 2021-11-17 11:43:01 +01:00
parent 1fb695a0ab
commit dcc0cbb659
No known key found for this signature in database
GPG Key ID: 5EF4C92355A3B53D
7 changed files with 93 additions and 8 deletions

View File

@ -5,12 +5,17 @@ import (
"github.com/go-co-op/gocron"
"github.com/joho/godotenv"
"github.com/superioz/aqua/internal/handler"
"github.com/superioz/aqua/internal/storage"
"github.com/superioz/aqua/pkg/env"
"github.com/superioz/aqua/pkg/middleware"
"k8s.io/klog"
"time"
)
// TODO add documentation on Kubernetes
// TODO add documentation of how to configure it with ShareX
// TODO add structure diagram (api for uploading, file backend with metadata database, scheduler for expiration)
func main() {
err := godotenv.Load()
if err != nil {
@ -41,8 +46,7 @@ func main() {
}
s.StartAsync()
r.GET("/healthz", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "UP"})
})
r.Static("/", env.StringOrDefault("FILE_STORAGE_PATH", storage.EnvDefaultFileStoragePath))
_ = r.Run(":8765")
}

View File

@ -63,7 +63,6 @@ func (u *UploadHandler) Upload(c *gin.Context) {
// empty string, if not given
token := getToken(c)
klog.Infof("Checking authentication for token=%s", token)
if !u.AuthConfig.HasToken(token) {
c.JSON(http.StatusUnauthorized, gin.H{"msg": "the token is not valid"})
return
@ -92,7 +91,6 @@ func (u *UploadHandler) Upload(c *gin.Context) {
}
ct := getContentType(file)
klog.Infof("Detected content type: %s", ct)
if !isContentTypeValid(ct) {
c.JSON(http.StatusBadRequest, gin.H{"msg": "content type of file is not valid"})
return
@ -103,6 +101,9 @@ func (u *UploadHandler) Upload(c *gin.Context) {
return
}
mb := float64(c.Request.ContentLength) / 1024 / 1024
klog.Infof("Received valid upload request (type: %s, size: %.3fmb)", ct, mb)
of, err := file.Open()
if err != nil {
klog.Error(err)

View File

@ -42,7 +42,7 @@ func (l LocalFileSystem) DeleteFile(id string) error {
}
func (l LocalFileSystem) GetFile(id string) (*os.File, error) {
panic("implement me")
return os.Open(l.FolderPath + id)
}
func NewLocalFileStorage(path string) *LocalFileSystem {

View File

@ -15,6 +15,9 @@ import (
const (
ExpireNever = -1
EnvDefaultFileStoragePath = "/var/lib/aqua/files/"
EnvDefaultMetaDbPath = "/var/lib/aqua/"
)
type StoredFile struct {
@ -36,14 +39,14 @@ type FileStorage struct {
}
func NewFileStorage() *FileStorage {
metaDbFilePath := env.StringOrDefault("FILE_META_DB_PATH", "/var/lib/aqua/")
metaDbFilePath := env.StringOrDefault("FILE_META_DB_PATH", EnvDefaultMetaDbPath)
fileMetaDb := NewSqliteFileMetaDatabase(metaDbFilePath)
err := fileMetaDb.Connect()
if err != nil {
klog.Errorf("Could not connect to file meta db: %v", err)
}
fileStoragePath := env.StringOrDefault("FILE_STORAGE_PATH", "/var/lib/aqua/files/")
fileStoragePath := env.StringOrDefault("FILE_STORAGE_PATH", EnvDefaultFileStoragePath)
fileSystem := NewLocalFileStorage(fileStoragePath)
return &FileStorage{

11
kubernetes/configmap.yaml Normal file
View File

@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: aqua-auth-config
data:
auth.yml: |
validTokens:
- token: 71a4c056ab9b0fb965063344cd6616bc
fileTypes:
- image/png
- image/jpeg

View File

@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: aqua
resources:
- configmap.yaml
- deployment.yaml
- pvc.yaml

View File

@ -0,0 +1,59 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: aqua-server
spec:
selector:
matchLabels:
app: aqua
serviceName: "aqua"
replicas: 1
template:
metadata:
labels:
app: aqua
spec:
containers:
- name: aqua
image: ghcr.io/superioz/aqua:latest
ports:
- containerPort: 8765
env:
- name: AUTH_CONFIG_PATH
value: /etc/aqua/auth.yml
- name: FILE_STORAGE_PATH
value: /var/lib/aqua/
- name: FILE_NAME_LENGTH
value: 16
- name: FILE_META_DB_PATH
value: /var/lib/aqua/
- name: FILE_EXPIRATION_CYCLE
value: 5
volumeMounts:
- name: auth
mountPath: /etc/aqua/
- name: aqua-files
volumes:
- name: auth
configMap:
name: aqua-auth-config
volumeClaimTemplates:
- metadata:
name: aqua-files
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 20Gi
---
apiVersion: v1
kind: Service
metadata:
name: aqua-server
labels:
app: aqua
spec:
selector:
app: aqua
ports:
- port: 8765