Add container

This commit is contained in:
Tyler Perkins 2023-12-18 18:19:59 -05:00
parent 22e3ceaa3a
commit 7516256ab9
Signed by: tyler
GPG Key ID: 03B27509E17EFDC8
3 changed files with 100 additions and 0 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
# Use the official Filebrowser image as a base
FROM filebrowser/filebrowser
# Copy the entrypoint script into the container
COPY ./entrypoint.sh /entrypoint.sh
# Ensure the script uses Unix line endings and is executable
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh
# Set the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]

22
docker-compose.yml Normal file
View File

@ -0,0 +1,22 @@
version: '3.8'
services:
filebrowser:
build: .
ports:
- "8000:80"
environment:
ADMIN_PASS: "my-secure-password"
DEFAULT_USERNAME: "user"
DEFAULT_PASSWORD: "password"
BRANDING_NAME: "My Awesome File Storage"
AUTH_METHOD: "json"
AUTH_HEADER: "X-My-Header"
PERM_ADMIN: "false"
PERM_EXECUTE: "false"
PERM_CREATE: "true"
PERM_RENAME: "false"
PERM_MODIFY: "false"
PERM_DELETE: "false"
PERM_SHARE: "false"
PERM_DOWNLOAD: "true"

67
entrypoint.sh Normal file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Set default values for environment variables if they are not set
ADMIN_PASS=${ADMIN_PASS:-admin}
DEFAULT_USERNAME=${DEFAULT_USERNAME:-default}
DEFAULT_PASSWORD=${DEFAULT_PASSWORD:-default}
BRANDING_NAME=${BRANDING_NAME:-"My file storage"}
AUTH_METHOD=${AUTH_METHOD:-json}
AUTH_HEADER=${AUTH_HEADER:-"X-My-Header"}
# Set default values for permission-related environment variables
PERM_ADMIN=${PERM_ADMIN:-false}
PERM_EXECUTE=${PERM_EXECUTE:-false}
PERM_CREATE=${PERM_CREATE:-false}
PERM_RENAME=${PERM_RENAME:-false}
PERM_MODIFY=${PERM_MODIFY:-false}
PERM_DELETE=${PERM_DELETE:-false}
PERM_SHARE=${PERM_SHARE:-false}
PERM_DOWNLOAD=${PERM_DOWNLOAD:-false}
# Initialize Filebrowser if it's the first run
if [ ! -f /database.db ]; then
echo "Init the local database..."
./filebrowser config init
./filebrowser users add admin "$ADMIN_PASS" --perm.admin
fi
# Update the admin password in case it changes
echo "Update the admin user\'s password"
./filebrowser users update admin --password "$ADMIN_PASS"
# Check if DEFAULT_USERNAME is "admin" and error out if it is
if [ "$DEFAULT_USERNAME" = "admin" ]; then
echo "Error: DEFAULT_USERNAME cannot be 'admin'. Please choose a different username."
exit 1
fi
# Create the default user (assuming it does not exist)
./filebrowser users add "$DEFAULT_USERNAME" "$DEFAULT_PASSWORD" --perm.admin="$PERM_ADMIN" --perm.execute="$PERM_EXECUTE" --perm.create="$PERM_CREATE" --perm.rename="$PERM_RENAME" --perm.modify="$PERM_MODIFY" --perm.delete="$PERM_DELETE" --perm.share="$PERM_SHARE" --perm.download="$PERM_DOWNLOAD"
# Set branding name
echo "Set branding"
./filebrowser config set --branding.name "$BRANDING_NAME"
# Set authentication method
echo "Set authentication method"
case "$AUTH_METHOD" in
"json")
./filebrowser config set --auth.method=json
;;
"proxy")
./filebrowser config set --auth.method=proxy --auth.header="$AUTH_HEADER"
;;
*)
echo "Invalid AUTH_METHOD. Using default 'json'."
./filebrowser config set --auth.method=json
;;
esac
echo "--------- Configuration complete ----------"
echo "Configuration JSON:"
cat ./.filebrowswer.json
# Run Filebrowser
exec ./filebrowser -d /database.db