diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 96a638ed..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,84 +0,0 @@ -version: 2 -jobs: - linting: - docker: - - image: circleci/golang:1.10 - working_directory: /go/src/github.com/filebrowser/filebrowser - steps: - - checkout - - run: - name: Install Dependencies - command: | - curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 - chmod +x $GOPATH/bin/dep - dep ensure -v - go get github.com/alecthomas/gometalinter - gometalinter --install - - run: - name: Run linting - command: | - gometalinter --exclude="rice-box.go" \ - --deadline=300s \ - -D goconst \ - -D gocyclo \ - -D vetshadow \ - -D errcheck \ - -D golint \ - -D gas \ - -D gosec - build: - docker: - - image: circleci/golang:1.10 - working_directory: /go/src/github.com/filebrowser/filebrowser - steps: - - checkout - - run: - name: Install Dependencies - command: | - curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 - chmod +x $GOPATH/bin/dep - dep ensure -v - - run: - name: Building - command: go build github.com/filebrowser/filebrowser/cmd/filebrowser - deploy: - docker: - - image: circleci/golang:1.10 - working_directory: /go/src/github.com/filebrowser/filebrowser - steps: - - checkout - - run: - name: Install Dependencies - command: | - curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 - chmod +x $GOPATH/bin/dep - dep ensure -v - - run: - name: Deploy - command: curl -sL https://git.io/goreleaser | bash - -workflows: - version: 2 - lint-build-deploy: - jobs: - - linting: - filters: - tags: - only: /.*/ - branches: - only: /.*/ - - build: - filters: - tags: - only: /.*/ - branches: - only: /.*/ - - deploy: - requires: - - linting - - build - filters: - tags: - only: /v[0-9]+(\.[0-9]+)*(-.*)*/ - branches: - ignore: /.*/ diff --git a/.gitignore b/.gitignore index 98b81469..a6d57c40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,15 @@ .DS_Store -node_modules/ */dist/* *.db *.db.lock -npm-debug.log* -yarn-debug.log* -yarn-error.log* .idea .vscode -package-lock.json -yarn.lock +Dockerfile +filebrowser +rice-box.go vendor +npm-debug.log* +package-lock.json +yarn-debug.log* +yarn-error.log* +yarn.lock diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..41ab3862 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "frontend"] + path = frontend + url = https://github.com/filebrowser/frontend diff --git a/.gometalinter.json b/.gometalinter.json new file mode 100644 index 00000000..638f67c5 --- /dev/null +++ b/.gometalinter.json @@ -0,0 +1,38 @@ +{ + "Enable": [ + "deadcode", + "gotype", + "gotypex", + "ineffassign", + "interfacer", + "maligned", + "megacheck", + "structcheck", + "unconvert", + "varcheck", + "vet" + ], + "Disable": [ + "dupl", + "errcheck", + "gochecknoglobals", + "gochecknoinits", + "goconst", + "gocyclo", + "gofmt", + "goimports", + "golint", + "gosec", + "gosimple", + "lll", + "misspell", + "nakedret", + "safesql", + "staticcheck", + "test", + "testify", + "unparam", + "unused", + "vetshadow" + ] +} diff --git a/.goreleaser.yml b/.goreleaser.yml index 84543a50..84a38345 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,8 @@ +project_name: filebrowser + build: + env: + - CGO_ENABLED=0 main: cmd/filebrowser/main.go binary: filebrowser goos: @@ -37,3 +41,19 @@ archive: format_overrides: - goos: windows format: zip + +release: + disable: true + +dockers: + - + goos: linux + goarch: amd64 + goarm: '' + image: filebrowser/filebrowser + skip_push: true + tag_templates: + - "{{ .Tag }}" + - latest + extra_files: + - Docker.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..99187c03 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,57 @@ +os: linux +services: docker +language: minimal +install: skip +addons: + apt: + packages: + - docker-ce + - pass +env: + global: + - USE_DOCKER="true" + - WDIR=/go/src/github.com/filebrowser/filebrowser +stages: + - lint + - test + - release +cache: + directories: + - vendor + - rice-box.go +jobs: + include: + - stage: lint + script: "./build/run_gometalinter.sh" + - stage: test + script: "./build/build_all.sh" + deploy: + provider: script + skip_cleanup: true + script: + - cp dockerfiles/filebrowser Dockerfile + - docker build -t filebrowser/filebrowser . + - ./build/docker_login.sh + - docker push filebrowser/filebrowser + - docker logout + on: + tags: false + repo: filebrowser/filebrowser + branch: master + - stage: release + script: + - cp dockerfiles/filebrowser Dockerfile + - ./build/docker_login.sh + - docker run --rm -itv $(pwd):$WDIR -v /var/run/docker.sock:/var/run/docker.sock filebrowser/dev goreleaser + - docker logout + - ./build/push_ricebox.sh + if: tag IS present + deploy: + provider: releases + api_key: + secure: GCURbl9xmjOmeNc7cYSvfSwbEp46cacWmJRczcsU6rQa0aWqzjELYdyIsl6HWW+o0dzuZvbWRD6muxYqIud92oPLYDuXSnra9tM3mCjswrjiPCJ57bksWkSPBfFQcxIyB6c3o+A/FMnX3nnSE/2r5HYZnPNFbEcBbC7WSgwx9ejXUuyWn1PUFK9YQWANdl6J7b7EKsk+9MxS9Pmw6M2ycBwX8ScUQdofkUPvR/nqlXISm+3hs30VubqQi9Ha6DM9Bw3aFK3/Ts/ujCOxP1ZoMCBZ6tfnaQOElIG96WTwnt77eDYlZezBOLym3Z18iif+Qny+XndFKDbexaiUT06VlWFXCKtt3iLs6HJwRcjmiHmB0Z3v+W4cKPl3cEyxxrU2aal54k1PBhU+5L0Xc8ileKbDMYg5tps88zWHNefeZVfaxYSVrmUHkuygMe481oaBLacDXTxs4t6XEpStREuLmvx9NLTwTFAbWjMNM0PqlueDMxO4bdwNvzXg/TcKLWV9FezqAlre8lFNZK5wX6lKFVSZ3hFjxCfwrJL2cPwg5A8Yd5EOC4Nh81WdgYuFGOxZzMAoSJlaVRvQS1trCUP/++ONnDep3ExSxvw4B7vijGZWeXUhrOMiPQHXu+t6BnrlnDjQ4gi44QTW0y/iM2WC2DBKfgYjAKwyHx13hFrmOCg= + file: "dist/*.*" + file_glob: true + on: + repo: filebrowser/filebrowser + branch: master diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 024f6be1..00000000 --- a/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM golang:alpine - -COPY . /go/src/github.com/filebrowser/filebrowser - -WORKDIR /go/src/github.com/filebrowser/filebrowser -RUN apk --no-cache --update upgrade && apk --no-cache add ca-certificates git curl && \ - curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && \ - chmod +x /usr/local/bin/dep -RUN dep ensure -vendor-only - -WORKDIR /go/src/github.com/filebrowser/filebrowser/cmd/filebrowser -RUN CGO_ENABLED=0 go build -a -RUN mv filebrowser /go/bin/filebrowser - -FROM scratch -COPY --from=0 /go/bin/filebrowser /filebrowser -COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt - -VOLUME /tmp -VOLUME /srv -EXPOSE 80 - -COPY Docker.json /config.json - -ENTRYPOINT ["/filebrowser", "--config", "/config.json"] diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 00000000..4ba8ad8f --- /dev/null +++ b/build/build.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +cd $(dirname $0)/.. + +dep ensure -vendor-only + +cd cmd/filebrowser +CGO_ENABLED=0 go build -a +cd ../.. +cp cmd/filebrowser/filebrowser ./ diff --git a/build/build_all.sh b/build/build_all.sh new file mode 100755 index 00000000..24860c0e --- /dev/null +++ b/build/build_all.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +cd $(dirname $0)/.. + +if [ -d "rice-box.go" ]; then + rm -rf rice-box.go +fi + +if [ "$USE_DOCKER" != "" ]; then + if [ -d "frontend/dist" ]; then + rm -rf frontend/dist + fi; + + if [ "$WDIR" = "" ]; then + WDIR="/go/src/github.com/filebrowser/filebrowser" + fi; + + $(command -v winpty) docker run -it \ + --name filebrowser-tmp \ + -v /$(pwd):/src:z \ + -w /${WDIR} \ + filebrowser/dev \ + sh -c "\ + cp -r //src/* /$WDIR && \ + cd build && \ + dos2unix build_assets.sh && \ + dos2unix build.sh && \ + ./build_assets.sh && \ + ./build.sh \ + " + exitcode=$? + + if [ $exitcode -eq 0 ]; then + for d in "dist/" "node_modules/"; do + docker cp filebrowser-tmp:/$WDIR/frontend/$d frontend + done + for d in "vendor/" "rice-box.go" "filebrowser"; do + docker cp filebrowser-tmp:/$WDIR/$d ./ + done + fi + docker rm -f filebrowser-tmp +else + ./build/build_assets.sh + ./build/build.sh +fi diff --git a/build.sh b/build/build_assets.sh old mode 100644 new mode 100755 similarity index 65% rename from build.sh rename to build/build_assets.sh index fc2fca57..bd86ac6f --- a/build.sh +++ b/build/build_assets.sh @@ -1,14 +1,22 @@ -#!/bin/bash +#!/bin/sh + set -e +cd $(dirname $0)/.. + +# Clean the dist folder and build the assets +cd frontend +if [ -d "dist" ]; then + rm -rf dist/* +fi; +yarn install +yarn build +cd .. + # Install rice tool if not present if ! [ -x "$(command -v rice)" ]; then go get github.com/GeertJohan/go.rice/rice fi -# Clean the dist folder and build the assets -rm -rf node_modules -npm install - # Embed the assets using rice rice embed-go diff --git a/build/build_img.sh b/build/build_img.sh new file mode 100755 index 00000000..af1bcee5 --- /dev/null +++ b/build/build_img.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +cd $(dirname $0)/.. + +cp dockerfiles/filebrowser Dockerfile +docker build -t filebrowser/filebrowser . +rm -f Dockerfile diff --git a/build/build_img_dev.sh b/build/build_img_dev.sh new file mode 100755 index 00000000..d196069e --- /dev/null +++ b/build/build_img_dev.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +cd $(dirname $0)/.. + +mkdir -p tmp-dev +cd tmp-dev +cp ../dockerfiles/dev Dockerfile +docker build -t filebrowser/dev . +cd .. +rm -rf tmp-dev diff --git a/build/deploy_key.enc b/build/deploy_key.enc new file mode 100644 index 00000000..af98a5d4 Binary files /dev/null and b/build/deploy_key.enc differ diff --git a/build/docker_login.sh b/build/docker_login.sh new file mode 100755 index 00000000..fedeaf5a --- /dev/null +++ b/build/docker_login.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +# init key for pass +gpg --batch --gen-key <<-EOF +%echo Generating a standard key +Key-Type: DSA +Key-Length: 1024 +Subkey-Type: ELG-E +Subkey-Length: 1024 +Name-Real: Meshuggah Rocks +Name-Email: meshuggah@example.com +Expire-Date: 0 +# Do a commit here, so that we can later print "done" :-) +%commit +%echo done +EOF + +key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1) +pass init $key + +if [ "$(command -v docker-credential-pass)" = "" ]; then + docker run --rm -itv /usr/local/bin:/src filebrowser/dev sh -c "cp /go/bin/docker-credential-pass /src" +fi + +echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin diff --git a/build/push_ricebox.sh b/build/push_ricebox.sh new file mode 100755 index 00000000..12f1ffd5 --- /dev/null +++ b/build/push_ricebox.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +cd $(dirname $0) + +COMMIT_SHA="$(git rev-parse --verify HEAD | cut -c1-8)" + +eval `ssh-agent -s` +openssl aes-256-cbc -K $encrypted_9ca81b5594f5_key -iv $encrypted_9ca81b5594f5_iv -in ./deploy_key.enc -d | ssh-add - + +git clone git@github.com:filebrowser/caddy caddy +cd caddy +cp ../../rice-box.go assets/ +git checkout -b update-rice-box origin/master +git commit -am "update rice-box $COMMIT_SHA" + +if [ $(git tag | grep "$TRAVIS_TAG" | wc -l) -ne 0 ]; then + git tag -d "$TRAVIS_TAG" +fi + +git tag "$TRAVIS_TAG" + +if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then + git push -u origin update-rice-box +else + git push origin +update-rice-box +fi + +if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then + git push origin "$TRAVIS_TAG" +else + git push origin :"$TRAVIS_TAG" + git push origin "$TRAVIS_TAG" +fi + diff --git a/build/release.sh b/build/release.sh new file mode 100644 index 00000000..cf285d46 --- /dev/null +++ b/build/release.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +cd $(dirname $0)/.. + +echo "> Checking semver format" + +if [ $# -ne 1 ]; then + echo "This release script requires a single argument corresponding to the semver to be released. See semver.org" + exit 1 +fi + +semver=$(grep -P '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' <<< "$1") + +if [ $? -ne 0 ]; then + echo "Not valid semver format. See semver.org" + exit 1 +fi + +echo "> Checking matching $semver in frontend submodule" + +cd frontend +git fetch --all + +if [ $(git tag | grep "$semver" | wc -l) -eq 0 ]; then + echo "Tag $semver does not exist in submodule 'frontend'. Tag it and run this script again." + exit 1 +fi + +git rev-parse --verify --quiet release +if [ $? -ne 0 ]; then + git checkout -b release "$semver" +else + git checkout release + git reset --hard "$semver" +fi + +cd .. + +echo "> Updating submodule ref to $semver" + +sed -i "s|(untracked)|$1|g" filebrowser.go +git commit -am "chore: version $semver" +git tag "$1" +git push +git push --tags + +echo "> Commiting untracked version notice..." + +sed -i "s|$1|(untracked)|g" filebrowser.go +git commit -am "chore: setting untracked version [ci skip]" +git push + +echo "> Done!" diff --git a/build/run_gometalinter.sh b/build/run_gometalinter.sh new file mode 100755 index 00000000..2e7a7f20 --- /dev/null +++ b/build/run_gometalinter.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +cd $(dirname $0)/.. + +dolint='gometalinter --exclude="rice-box.go" --deadline=300s' + +if [ "$USE_DOCKER" != "" ]; then + docker run --rm -itv $(pwd):/src filebrowser/dev sh -c "\ + cp -r /src/. ./ && dep ensure -v -vendor-only && \ + CGO_ENABLED=0 $dolint" +else + $dolint +fi \ No newline at end of file diff --git a/caddy/filemanager/filemanager.go b/caddy/filemanager/filemanager.go deleted file mode 100644 index 055fdc13..00000000 --- a/caddy/filemanager/filemanager.go +++ /dev/null @@ -1,52 +0,0 @@ -package filemanager - -import ( - "net/http" - - "github.com/filebrowser/filebrowser" - "github.com/filebrowser/filebrowser/caddy/parser" - h "github.com/filebrowser/filebrowser/http" - "github.com/mholt/caddy" - "github.com/mholt/caddy/caddyhttp/httpserver" -) - -func init() { - caddy.RegisterPlugin("filemanager", caddy.Plugin{ - ServerType: "http", - Action: setup, - }) -} - -type plugin struct { - Next httpserver.Handler - Configs []*filebrowser.FileBrowser -} - -// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. -func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { - for i := range f.Configs { - // Checks if this Path should be handled by File Manager. - if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) { - continue - } - - h.Handler(f.Configs[i]).ServeHTTP(w, r) - return 0, nil - } - - return f.Next.ServeHTTP(w, r) -} - -// setup configures a new FileManager middleware instance. -func setup(c *caddy.Controller) error { - configs, err := parser.Parse(c, "") - if err != nil { - return err - } - - httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { - return plugin{Configs: configs, Next: next} - }) - - return nil -} diff --git a/caddy/hugo/hugo.go b/caddy/hugo/hugo.go deleted file mode 100644 index 97c55368..00000000 --- a/caddy/hugo/hugo.go +++ /dev/null @@ -1,52 +0,0 @@ -package hugo - -import ( - "net/http" - - "github.com/filebrowser/filebrowser" - "github.com/filebrowser/filebrowser/caddy/parser" - h "github.com/filebrowser/filebrowser/http" - "github.com/mholt/caddy" - "github.com/mholt/caddy/caddyhttp/httpserver" -) - -func init() { - caddy.RegisterPlugin("hugo", caddy.Plugin{ - ServerType: "http", - Action: setup, - }) -} - -type plugin struct { - Next httpserver.Handler - Configs []*filebrowser.FileBrowser -} - -// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. -func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { - for i := range f.Configs { - // Checks if this Path should be handled by File Manager. - if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) { - continue - } - - h.Handler(f.Configs[i]).ServeHTTP(w, r) - return 0, nil - } - - return f.Next.ServeHTTP(w, r) -} - -// setup configures a new FileManager middleware instance. -func setup(c *caddy.Controller) error { - configs, err := parser.Parse(c, "hugo") - if err != nil { - return err - } - - httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { - return plugin{Configs: configs, Next: next} - }) - - return nil -} diff --git a/caddy/jekyll/jekyll.go b/caddy/jekyll/jekyll.go deleted file mode 100644 index 7dc838d1..00000000 --- a/caddy/jekyll/jekyll.go +++ /dev/null @@ -1,52 +0,0 @@ -package jekyll - -import ( - "net/http" - - "github.com/filebrowser/filebrowser" - "github.com/filebrowser/filebrowser/caddy/parser" - h "github.com/filebrowser/filebrowser/http" - "github.com/mholt/caddy" - "github.com/mholt/caddy/caddyhttp/httpserver" -) - -func init() { - caddy.RegisterPlugin("jekyll", caddy.Plugin{ - ServerType: "http", - Action: setup, - }) -} - -type plugin struct { - Next httpserver.Handler - Configs []*filebrowser.FileBrowser -} - -// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. -func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { - for i := range f.Configs { - // Checks if this Path should be handled by File Manager. - if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) { - continue - } - - h.Handler(f.Configs[i]).ServeHTTP(w, r) - return 0, nil - } - - return f.Next.ServeHTTP(w, r) -} - -// setup configures a new FileManager middleware instance. -func setup(c *caddy.Controller) error { - configs, err := parser.Parse(c, "jekyll") - if err != nil { - return err - } - - httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { - return plugin{Configs: configs, Next: next} - }) - - return nil -} diff --git a/caddy/parser/parser.go b/caddy/parser/parser.go deleted file mode 100644 index e238adfb..00000000 --- a/caddy/parser/parser.go +++ /dev/null @@ -1,308 +0,0 @@ -package parser - -import ( - "crypto/md5" - "encoding/hex" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" - - "github.com/asdine/storm" - "github.com/filebrowser/filebrowser" - "github.com/filebrowser/filebrowser/bolt" - "github.com/filebrowser/filebrowser/staticgen" - "github.com/hacdias/fileutils" - "github.com/mholt/caddy" - "github.com/mholt/caddy/caddyhttp/httpserver" -) - -var databases = map[string]*storm.DB{} - -// Parse ... -func Parse(c *caddy.Controller, plugin string) ([]*filebrowser.FileBrowser, error) { - var ( - configs []*filebrowser.FileBrowser - err error - ) - - for c.Next() { - u := &filebrowser.User{ - Locale: "en", - AllowCommands: true, - AllowEdit: true, - AllowNew: true, - AllowPublish: true, - Commands: []string{"git", "svn", "hg"}, - CSS: "", - ViewMode: "mosaic", - Rules: []*filebrowser.Rule{}, - } - - baseURL := "/" - scope := "." - database := "" - noAuth := false - alterRecaptcha := false - reCaptchaKey := "" - reCaptchaSecret := "" - - if plugin != "" { - baseURL = "/admin" - } - - // Get the baseURL and scope - args := c.RemainingArgs() - - if plugin == "" { - if len(args) >= 1 { - baseURL = args[0] - } - - if len(args) > 1 { - scope = args[1] - } - } else { - if len(args) >= 1 { - scope = args[0] - } - - if len(args) > 1 { - baseURL = args[1] - } - } - - for c.NextBlock() { - switch c.Val() { - case "database": - if !c.NextArg() { - return nil, c.ArgErr() - } - - database = c.Val() - case "locale": - if !c.NextArg() { - return nil, c.ArgErr() - } - - u.Locale = c.Val() - case "allow_commands": - if !c.NextArg() { - u.AllowCommands = true - continue - } - - u.AllowCommands, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - case "allow_edit": - if !c.NextArg() { - u.AllowEdit = true - continue - } - - u.AllowEdit, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - case "allow_new": - if !c.NextArg() { - u.AllowNew = true - continue - } - - u.AllowNew, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - case "allow_publish": - if !c.NextArg() { - u.AllowPublish = true - continue - } - - u.AllowPublish, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - case "commands": - if !c.NextArg() { - return nil, c.ArgErr() - } - - u.Commands = strings.Split(c.Val(), " ") - case "css": - if !c.NextArg() { - return nil, c.ArgErr() - } - - file := c.Val() - css, err := ioutil.ReadFile(file) - if err != nil { - return nil, err - } - - u.CSS = string(css) - case "view_mode": - if !c.NextArg() { - return nil, c.ArgErr() - } - - u.ViewMode = c.Val() - if u.ViewMode != filebrowser.MosaicViewMode && u.ViewMode != filebrowser.ListViewMode { - return nil, c.ArgErr() - } - case "alternative_recaptcha": - if !c.NextArg() { - alterRecaptcha = true - continue - } - - alterRecaptcha, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - case "recaptcha_key": - if !c.NextArg() { - return nil, c.ArgErr() - } - - reCaptchaKey = c.Val() - case "recaptcha_secret": - if !c.NextArg() { - return nil, c.ArgErr() - } - - reCaptchaSecret = c.Val() - case "no_auth": - if !c.NextArg() { - noAuth = true - continue - } - - noAuth, err = strconv.ParseBool(c.Val()) - if err != nil { - return nil, err - } - } - } - - caddyConf := httpserver.GetConfig(c) - - path := filepath.Join(caddy.AssetsPath(), "filemanager") - err := os.MkdirAll(path, 0700) - if err != nil { - return nil, err - } - - // if there is a database path and it is not absolute, - // it will be relative to Caddy folder. - if !filepath.IsAbs(database) && database != "" { - database = filepath.Join(path, database) - } - - // If there is no database path on the settings, - // store one in .caddy/filemanager/name.db. - if database == "" { - // The name of the database is the hashed value of a string composed - // by the host, address path and the baseurl of this File Manager - // instance. - hasher := md5.New() - hasher.Write([]byte(caddyConf.Addr.Host + caddyConf.Addr.Path + baseURL)) - sha := hex.EncodeToString(hasher.Sum(nil)) - database = filepath.Join(path, sha+".db") - - fmt.Println("[WARNING] A database is going to be created for your File Manager instance at " + database + - ". It is highly recommended that you set the 'database' option to '" + sha + ".db'\n") - } - - u.Scope = scope - u.FileSystem = fileutils.Dir(scope) - - var db *storm.DB - if stored, ok := databases[database]; ok { - db = stored - } else { - db, err = storm.Open(database) - databases[database] = db - } - - if err != nil { - return nil, err - } - - recaptchaHost := "https://www.google.com" - if alterRecaptcha { - recaptchaHost = "https://recaptcha.net" - } - - m := &filebrowser.FileBrowser{ - NoAuth: noAuth, - BaseURL: "", - PrefixURL: "", - ReCaptchaHost: recaptchaHost, - ReCaptchaKey: reCaptchaKey, - ReCaptchaSecret: reCaptchaSecret, - DefaultUser: u, - Store: &filebrowser.Store{ - Config: bolt.ConfigStore{DB: db}, - Users: bolt.UsersStore{DB: db}, - Share: bolt.ShareStore{DB: db}, - }, - NewFS: func(scope string) filebrowser.FileSystem { - return fileutils.Dir(scope) - }, - } - - err = m.Setup() - if err != nil { - return nil, err - } - - switch plugin { - case "hugo": - // Initialize the default settings for Hugo. - hugo := &staticgen.Hugo{ - Root: scope, - Public: filepath.Join(scope, "public"), - Args: []string{}, - CleanPublic: true, - } - - // Attaches Hugo plugin to this file manager instance. - err = m.Attach(hugo) - if err != nil { - return nil, err - } - case "jekyll": - // Initialize the default settings for Jekyll. - jekyll := &staticgen.Jekyll{ - Root: scope, - Public: filepath.Join(scope, "_site"), - Args: []string{}, - CleanPublic: true, - } - - // Attaches Hugo plugin to this file manager instance. - err = m.Attach(jekyll) - if err != nil { - return nil, err - } - } - - if err != nil { - return nil, err - } - - m.NoAuth = noAuth - m.SetBaseURL(baseURL) - m.SetPrefixURL(strings.TrimSuffix(caddyConf.Addr.Path, "/")) - - configs = append(configs, m) - } - - return configs, nil -} diff --git a/dockerfiles/dev b/dockerfiles/dev new file mode 100644 index 00000000..b6c3cc57 --- /dev/null +++ b/dockerfiles/dev @@ -0,0 +1,34 @@ +FROM golang:alpine AS base + +RUN apk add -U --no-cache git && \ + go get github.com/alecthomas/gometalinter && \ + gometalinter --install + +FROM golang:alpine + +WORKDIR /go/src/github.com/filebrowser/filebrowser + +COPY --from=base /go/bin /go/bin + +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \ + sed -i -e "s/v[0-9]\.[0-9]/edge/g" /etc/apk/repositories && \ + apk --no-cache -U upgrade && apk --no-cache add ca-certificates yarn git curl dos2unix && \ + go get github.com/GeertJohan/go.rice/rice && \ + curl -fsSL -o /go/bin/dep $( \ + curl -s https://api.github.com/repos/golang/dep/releases/latest \ + | grep "browser_download_url.*linux-amd64\"" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + ) && \ + chmod +x /go/bin/dep && \ + curl -sL https://git.io/goreleaser -o /go/bin/goreleaser && \ + chmod +x /go/bin/goreleaser && \ + curl -fsSL https://download.docker.com/linux/static/edge/x86_64/docker-18.05.0-ce.tgz | tar xvz --strip-components=1 docker/docker -C /go/bin && \ + chmod +x /go/bin/docker && \ + curl -fsSL $( \ + curl -s https://api.github.com/repos/docker/docker-credential-helpers/releases/latest \ + | grep "browser_download_url.*pass-.*-amd64" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + ) | tar xv -C /go/bin && \ + chmod + /go/bin/docker-credential-pass diff --git a/dockerfiles/filebrowser b/dockerfiles/filebrowser new file mode 100644 index 00000000..c02c3037 --- /dev/null +++ b/dockerfiles/filebrowser @@ -0,0 +1,12 @@ +FROM scratch + +COPY --from=filebrowser/dev /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +VOLUME /tmp +VOLUME /srv +EXPOSE 80 + +COPY filebrowser /filebrowser +COPY Docker.json /config.json + +ENTRYPOINT ["/filebrowser", "--config", "/config.json"] diff --git a/filebrowser.go b/filebrowser.go index 1b23e24a..3879bbb1 100644 --- a/filebrowser.go +++ b/filebrowser.go @@ -119,7 +119,7 @@ type FSBuilder func(scope string) FileSystem func (m *FileBrowser) Setup() error { // Creates a new File Browser instance with the Users // map and Assets box. - m.Assets = rice.MustFindBox("./node_modules/filebrowser-frontend/dist") + m.Assets = rice.MustFindBox("./frontend/dist") m.Cron = cron.New() // Tries to get the encryption key from the database. diff --git a/frontend b/frontend new file mode 160000 index 00000000..157b2da1 --- /dev/null +++ b/frontend @@ -0,0 +1 @@ +Subproject commit 157b2da133c76f429c86087cace21f08db934407 diff --git a/package.json b/package.json deleted file mode 100644 index 76d69197..00000000 --- a/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "filebrowser", - "author": "File Browser contributors", - "private": true, - "dependencies": { - "filebrowser-frontend": "1.6.0" - } -} diff --git a/publish.sh b/publish.sh deleted file mode 100644 index e119218a..00000000 --- a/publish.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -e - -echo "Building assets" -./build.sh - -echo "Updating version number to $1..." -sed -i "s|(untracked)|$1|g" filebrowser.go -git add -A -git commit -m "chore: version $1" -git tag "v$1" -git push -git push --tags - -echo "Commiting untracked version notice..." -sed -i "s|$1|(untracked)|g" filebrowser.go -git add -A -git commit -m "chore: setting untracked version [ci skip]" -git push - -echo "Done!" diff --git a/rice-box.go.REMOVED.git-id b/rice-box.go.REMOVED.git-id deleted file mode 100644 index 151d4414..00000000 --- a/rice-box.go.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -5df38dbe052d7325c543606612fe6f4d9a1cdb98 \ No newline at end of file