Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
FROM docker.io/golang:1 AS builder
FROM docker.io/library/golang:1.26.4-alpine AS builder

WORKDIR /usr/src/app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o bin/s3manager

FROM docker.io/alpine:latest
RUN CGO_ENABLED=0 go build \
-ldflags="-s -w" \
-a \
-installsuffix cgo \
-o bin/s3manager

FROM docker.io/library/alpine:3.23

WORKDIR /usr/src/app
RUN addgroup -S s3manager && adduser -S s3manager -G s3manager
RUN apk add --no-cache \
ca-certificates \
dumb-init

RUN apk update \
&& apk upgrade --no-cache \
&& apk add --no-cache \
ca-certificates \
dumb-init \
&& addgroup -S s3manager \
&& adduser -S s3manager -G s3manager \
&& rm -rf /var/cache/apk/*

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" ]

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

CMD ["/usr/src/app/s3manager"]
5 changes: 5 additions & 0 deletions internal/app/s3manager/manager_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func HandleBucketsViewWithManager(manager *MultiS3Manager, templates fs.FS, allo
return
}

if bucketName != "" {
http.Redirect(w, r, rootURL+"/"+instanceName+"/buckets/"+bucketName, http.StatusTemporaryRedirect)
return
}

s3 := current.Client
instances := manager.GetAllInstances()

Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ func main() {
// Set up router
r := mux.NewRouter()

// Root redirects to first instance's buckets page
// Root redirects to first instance's buckets page (or directly to the configured bucket)
r.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
instances := s3Manager.GetAllInstances()
if len(instances) > 0 {
http.Redirect(w, r, rootURL+"/"+instances[0].Name+"/buckets", http.StatusPermanentRedirect)
} else {
if len(instances) == 0 {
http.Error(w, "No S3 instances configured", http.StatusInternalServerError)
return
}
if configuration.BucketName != "" {
http.Redirect(w, r, rootURL+"/"+instances[0].Name+"/buckets/"+configuration.BucketName, http.StatusPermanentRedirect)
} else {
http.Redirect(w, r, rootURL+"/"+instances[0].Name+"/buckets", http.StatusPermanentRedirect)
}
})).Methods(http.MethodGet)

Expand Down