mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Merge pull request #492 from filebrowser/chore/build
chore: new build process
Former-commit-id: 5c703aea976d95470a5f427a2c2d7b15d08c0e9e [formerly 326fcdd2d11d414c557986c74ec343d5c2221168] [formerly 7a5991c0e85806e82256b201b515a070e0e95ec9 [formerly 8ad626b0bc
]]
Former-commit-id: f78d78c109181cd9c52bd91753d4e39e8f65e077 [formerly 05e6b729485ddfa48ad428c389bd85d8ab11f366]
Former-commit-id: e91d24edfdff15c075e4f980a88b3dc8cf9d5254
This commit is contained in:
commit
d4e9f5ba53
@ -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: /.*/
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -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
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "frontend"]
|
||||
path = frontend
|
||||
url = https://github.com/filebrowser/frontend
|
38
.gometalinter.json
Normal file
38
.gometalinter.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
@ -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
|
||||
|
57
.travis.yml
Normal file
57
.travis.yml
Normal file
@ -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
|
25
Dockerfile
25
Dockerfile
@ -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"]
|
12
build/build.sh
Executable file
12
build/build.sh
Executable file
@ -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 ./
|
45
build/build_all.sh
Executable file
45
build/build_all.sh
Executable file
@ -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
|
18
build.sh → build/build_assets.sh
Normal file → Executable file
18
build.sh → build/build_assets.sh
Normal file → Executable file
@ -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
|
9
build/build_img.sh
Executable file
9
build/build_img.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
cp dockerfiles/filebrowser Dockerfile
|
||||
docker build -t filebrowser/filebrowser .
|
||||
rm -f Dockerfile
|
12
build/build_img_dev.sh
Executable file
12
build/build_img_dev.sh
Executable file
@ -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
|
BIN
build/deploy_key.enc
Normal file
BIN
build/deploy_key.enc
Normal file
Binary file not shown.
27
build/docker_login.sh
Executable file
27
build/docker_login.sh
Executable file
@ -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
|
34
build/push_ricebox.sh
Executable file
34
build/push_ricebox.sh
Executable file
@ -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
|
||||
|
53
build/release.sh
Normal file
53
build/release.sh
Normal file
@ -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!"
|
15
build/run_gometalinter.sh
Executable file
15
build/run_gometalinter.sh
Executable file
@ -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
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
34
dockerfiles/dev
Normal file
34
dockerfiles/dev
Normal file
@ -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
|
12
dockerfiles/filebrowser
Normal file
12
dockerfiles/filebrowser
Normal file
@ -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"]
|
@ -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.
|
||||
|
1
frontend
Submodule
1
frontend
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 157b2da133c76f429c86087cace21f08db934407
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"name": "filebrowser",
|
||||
"author": "File Browser contributors",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"filebrowser-frontend": "1.6.0"
|
||||
}
|
||||
}
|
21
publish.sh
21
publish.sh
@ -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!"
|
@ -1 +0,0 @@
|
||||
5df38dbe052d7325c543606612fe6f4d9a1cdb98
|
Loading…
Reference in New Issue
Block a user