Dockerfile
This commit is contained in:
parent
ca67bad68e
commit
762a1f3430
8 changed files with 67 additions and 27 deletions
5
.dockerignore
Normal file
5
.dockerignore
Normal file
|
@ -0,0 +1,5 @@
|
|||
public
|
||||
data
|
||||
vendor
|
||||
.env
|
||||
composer.lock
|
|
@ -2,7 +2,7 @@ client_id=client
|
|||
client_secret=secret
|
||||
keycloak_token_url=https://keycloak.example.com/auth/realms/master/protocol/openid-connect/token
|
||||
realm=master
|
||||
users_path=/srv/dav/public
|
||||
data_path=/srv/dav/public
|
||||
base_uri=/
|
||||
redis_host=localhost
|
||||
redis_port=6379
|
||||
|
|
21
Dockerfile
Normal file
21
Dockerfile
Normal file
|
@ -0,0 +1,21 @@
|
|||
FROM php:8.3-fpm-alpine
|
||||
|
||||
RUN apk add --no-cache php-xml php-curl php-pear
|
||||
|
||||
RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
|
||||
&& pecl install redis \
|
||||
&& docker-php-ext-enable redis \
|
||||
&& apk del pcre-dev ${PHPIZE_DEPS} \
|
||||
&& rm -rf /tmp/pear
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
RUN mkdir /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN composer update
|
||||
|
||||
ENTRYPOINT [ "php", "-S", "0.0.0.0:8080", "index.php" ]
|
|
@ -1,20 +1,18 @@
|
|||
{
|
||||
"name": "jlucki/docker-php-dev-env",
|
||||
"description": "A simple web development environment using Docker with NGINX, PHP, MySQL and Xdebug.",
|
||||
"name": "estym/keycloak-webdav",
|
||||
"description": "A simple webdav server with a Keycloak integration",
|
||||
"type": "project",
|
||||
"keywords": [
|
||||
"docker",
|
||||
"development",
|
||||
"environment",
|
||||
"webdav",
|
||||
"php",
|
||||
"xdebug",
|
||||
"nginx"
|
||||
"phpredis"
|
||||
],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jan Lucki",
|
||||
"email": "jan@lucki.dev"
|
||||
"name": "Evann (Estym) Regnault",
|
||||
"email": "contact@regnault.dev"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
|
|
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
services:
|
||||
webdav:
|
||||
build: .
|
||||
ports:
|
||||
- 8080:8080
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- redis_host=redis
|
||||
- data_path=/data/
|
||||
volumes:
|
||||
- ./public:/data
|
||||
|
||||
redis:
|
||||
image: redis:7.0.15-alpine
|
|
@ -9,9 +9,10 @@ use Dotenv\Dotenv;
|
|||
// The autoloader
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$dotenv = Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
if (is_file(".env")){
|
||||
$dotenv = Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
$redis_client = new Redis();
|
||||
$redis_client->connect($_ENV['redis_host'], intval($_ENV['redis_port']));
|
||||
|
@ -23,7 +24,7 @@ $authBackend = new Keycloak\KeycloakAuth($redis_client, $principalBackend,$_ENV[
|
|||
$authBackend->setRealm($_ENV['realm']);
|
||||
$authPlugin = new DAV\Auth\Plugin($authBackend);
|
||||
|
||||
$path = $_ENV['users_path'];
|
||||
$path = $_ENV['data_path'];
|
||||
|
||||
// The server object is responsible for making sense out of the WebDAV protocol
|
||||
$server = new DAV\Server([new HomeCollection($authPlugin, $path), new RolesCollection($principalBackend, $path)]);
|
||||
|
|
|
@ -9,26 +9,26 @@ use Sabre\DAV\FS\Directory;
|
|||
class HomeCollection extends Collection
|
||||
{
|
||||
private $plugin;
|
||||
private $userPath;
|
||||
private $dataPath;
|
||||
|
||||
|
||||
public function __construct(AuthPlugin $authPlugin, string $userPath)
|
||||
public function __construct(AuthPlugin $authPlugin, string $dataPath)
|
||||
{
|
||||
$this->plugin = $authPlugin;
|
||||
$this->userPath = $userPath;
|
||||
$this->dataPath = $dataPath;
|
||||
}
|
||||
|
||||
public function getChildren(): array
|
||||
{
|
||||
$principal = $this->plugin->getCurrentPrincipal();
|
||||
$username = explode("/", $principal)[1];
|
||||
$path = $this->userPath;
|
||||
$path = $this->dataPath;
|
||||
|
||||
if (!is_dir($path.$username)) {
|
||||
mkdir($path.$username, 0777 , true);
|
||||
if (!is_dir($path . '/users/' . $username)) {
|
||||
mkdir($path . '/users/' . $username, 0777 , true);
|
||||
}
|
||||
|
||||
return [new Directory($path.$username, $username)];
|
||||
return [new Directory($path . '/users/' . $username, $username)];
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
|
|
@ -9,22 +9,22 @@ use Sabre\DAV\FSExt\Directory as SabreDirectory;
|
|||
class RolesCollection extends Collection {
|
||||
|
||||
private RolesBackend $principalBackend;
|
||||
private $dataRoot;
|
||||
private string $dataPath;
|
||||
|
||||
public function __construct(RolesBackend $principal_backend, string $dataRoot)
|
||||
public function __construct(RolesBackend $principal_backend, string $dataPath)
|
||||
{
|
||||
$this->$dataRoot = $dataRoot;
|
||||
$this->dataPath = $dataPath;
|
||||
$this->principalBackend = $principal_backend;
|
||||
}
|
||||
|
||||
public function getChildren() : array {
|
||||
$path = $this->dataRoot;
|
||||
$path = $this->dataPath;
|
||||
$dirs = [];
|
||||
foreach ($this->principalBackend->roles as $role) {
|
||||
if (!is_dir($path . 'public/' . $role)){
|
||||
mkdir($path . 'public/' . $role, 0777, true);
|
||||
if (!is_dir($path . '/groups/' . $role)){
|
||||
mkdir($path . '/groups/' . $role, 0777, true);
|
||||
}
|
||||
$dirs[] = new SabreDirectory($path . 'public/' . $role, $role);
|
||||
$dirs[] = new SabreDirectory($path . '/groups/' . $role, $role);
|
||||
}
|
||||
|
||||
return $dirs;
|
||||
|
|
Loading…
Reference in a new issue