Skip to content

Commit

Permalink
Initial content
Browse files Browse the repository at this point in the history
This should enable the repo to build the application into an
container image.
  • Loading branch information
dominikholler committed Feb 24, 2024
1 parent 65c9084 commit d438e9a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM docker.io/library/golang:1.22 as builder
#FROM registry.redhat.io/rhel9/go-toolset:1.20 as builder
WORKDIR /opt/app-root/src/

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

COPY *.go ./

RUN CGO_ENABLED=0 go build -o /opt/app-root/webdavserver
RUN mkdir /tmp/webdav


FROM scratch
ARG USER=1001

COPY --from=builder /opt/app-root/webdavserver /webdavserver
COPY --from=builder --chown=$USER:$USER /tmp/webdav /srv/webdav

USER $USER:$USER

CMD ["-webdavDir", "/srv/webdav/"]
ENTRYPOINT ["/webdavserver"]
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# webdavserver
# webdavserver

[![Container Repository on Quay](https://quay.io/repository/dominikholler/webdavserver/status "Container Repository on Quay")](https://quay.io/repository/dominikholler/webdavserver)

webdavserver is a example application utilizing the webdav server of the golang standard library.

```
export WEBDAVDIR=/tmp/webdav
mkdir $WEBDAVDIR
chmod 777 $WEBDAVDIR
podman run --rm -p 8080:8080 -v $WEBDAVDIR:/srv/webdav:z -it quay.io/dominikholler/webdavserver
```
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/dominikholler/webdavserver

go 1.20

require golang.org/x/net v0.21.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"flag"
"log"
"net/http"

"golang.org/x/net/webdav"
)

func logRequest(r *http.Request, err error) {
log.Println(r.RemoteAddr, r.Method, r.URL.Path)
}


func main() {
var address, prefix, webdavDir string

flag.StringVar(&address, "address", "0.0.0.0:8080", "Address to listen to.")
flag.StringVar(&prefix, "prefix", "", "Prefix is the URL path prefix to strip from WebDAV resource paths.")
flag.StringVar(&webdavDir, "webdavDir", ".", "Path to serve")
flag.Parse()

handler := &webdav.Handler{
Prefix: prefix,
FileSystem: webdav.Dir(webdavDir),
LockSystem: webdav.NewMemLS(),
Logger: logRequest,
}

log.Println("serving", webdavDir, "on", address)
http.ListenAndServe(address, handler)
}

0 comments on commit d438e9a

Please sign in to comment.