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
|
client_secret=secret
|
||||||
keycloak_token_url=https://keycloak.example.com/auth/realms/master/protocol/openid-connect/token
|
keycloak_token_url=https://keycloak.example.com/auth/realms/master/protocol/openid-connect/token
|
||||||
realm=master
|
realm=master
|
||||||
users_path=/srv/dav/public
|
data_path=/srv/dav/public
|
||||||
base_uri=/
|
base_uri=/
|
||||||
redis_host=localhost
|
redis_host=localhost
|
||||||
redis_port=6379
|
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",
|
"name": "estym/keycloak-webdav",
|
||||||
"description": "A simple web development environment using Docker with NGINX, PHP, MySQL and Xdebug.",
|
"description": "A simple webdav server with a Keycloak integration",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"docker",
|
"docker",
|
||||||
"development",
|
"webdav",
|
||||||
"environment",
|
|
||||||
"php",
|
"php",
|
||||||
"xdebug",
|
"phpredis"
|
||||||
"nginx"
|
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Jan Lucki",
|
"name": "Evann (Estym) Regnault",
|
||||||
"email": "jan@lucki.dev"
|
"email": "contact@regnault.dev"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"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
|
// The autoloader
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
|
if (is_file(".env")){
|
||||||
$dotenv = Dotenv::createImmutable(__DIR__);
|
$dotenv = Dotenv::createImmutable(__DIR__);
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
|
}
|
||||||
|
|
||||||
$redis_client = new Redis();
|
$redis_client = new Redis();
|
||||||
$redis_client->connect($_ENV['redis_host'], intval($_ENV['redis_port']));
|
$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']);
|
$authBackend->setRealm($_ENV['realm']);
|
||||||
$authPlugin = new DAV\Auth\Plugin($authBackend);
|
$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
|
// 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)]);
|
$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
|
class HomeCollection extends Collection
|
||||||
{
|
{
|
||||||
private $plugin;
|
private $plugin;
|
||||||
private $userPath;
|
private $dataPath;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(AuthPlugin $authPlugin, string $userPath)
|
public function __construct(AuthPlugin $authPlugin, string $dataPath)
|
||||||
{
|
{
|
||||||
$this->plugin = $authPlugin;
|
$this->plugin = $authPlugin;
|
||||||
$this->userPath = $userPath;
|
$this->dataPath = $dataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChildren(): array
|
public function getChildren(): array
|
||||||
{
|
{
|
||||||
$principal = $this->plugin->getCurrentPrincipal();
|
$principal = $this->plugin->getCurrentPrincipal();
|
||||||
$username = explode("/", $principal)[1];
|
$username = explode("/", $principal)[1];
|
||||||
$path = $this->userPath;
|
$path = $this->dataPath;
|
||||||
|
|
||||||
if (!is_dir($path.$username)) {
|
if (!is_dir($path . '/users/' . $username)) {
|
||||||
mkdir($path.$username, 0777 , true);
|
mkdir($path . '/users/' . $username, 0777 , true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [new Directory($path.$username, $username)];
|
return [new Directory($path . '/users/' . $username, $username)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
|
|
|
@ -9,22 +9,22 @@ use Sabre\DAV\FSExt\Directory as SabreDirectory;
|
||||||
class RolesCollection extends Collection {
|
class RolesCollection extends Collection {
|
||||||
|
|
||||||
private RolesBackend $principalBackend;
|
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;
|
$this->principalBackend = $principal_backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChildren() : array {
|
public function getChildren() : array {
|
||||||
$path = $this->dataRoot;
|
$path = $this->dataPath;
|
||||||
$dirs = [];
|
$dirs = [];
|
||||||
foreach ($this->principalBackend->roles as $role) {
|
foreach ($this->principalBackend->roles as $role) {
|
||||||
if (!is_dir($path . 'public/' . $role)){
|
if (!is_dir($path . '/groups/' . $role)){
|
||||||
mkdir($path . 'public/' . $role, 0777, true);
|
mkdir($path . '/groups/' . $role, 0777, true);
|
||||||
}
|
}
|
||||||
$dirs[] = new SabreDirectory($path . 'public/' . $role, $role);
|
$dirs[] = new SabreDirectory($path . '/groups/' . $role, $role);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dirs;
|
return $dirs;
|
||||||
|
|
Loading…
Reference in a new issue