forked from limosa-io/laravel-scim-server
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
242 lines (191 loc) · 6.15 KB
/
Copy pathDockerfile
File metadata and controls
242 lines (191 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
FROM php:8.1-alpine
# Base tools and PHP extensions
RUN apk add --no-cache git jq moreutils \
&& apk add --no-cache $PHPIZE_DEPS postgresql-dev sqlite-dev \
&& docker-php-ext-install pdo_pgsql pdo_sqlite \
&& pecl install xdebug-3.1.5 \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host = 172.19.0.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Composer + fresh Laravel app
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer create-project --prefer-dist laravel/laravel example && cd example
WORKDIR /example
# Link local package
COPY . /laravel-scim-server
RUN jq '.repositories=[{"type": "path","url": "/laravel-scim-server"}]' ./composer.json | sponge ./composer.json
# Install package and dev helpers
RUN composer require arietimmerman/laravel-scim-server @dev && \
composer require laravel/tinker
# SQLite config
RUN touch /example/database.sqlite && \
echo "DB_CONNECTION=sqlite" >> /example/.env && \
echo "DB_DATABASE=/example/database.sqlite" >> /example/.env && \
echo "APP_URL=http://localhost:18123" >> /example/.env
# Make users.password nullable to allow SCIM-created users without passwords
RUN sed -i -E "s/\\$table->string\('password'\);/\\$table->string('password')->nullable();/g" \
database/migrations/*create_users_table.php || true
# Groups table migration
RUN cat > /example/database/migrations/2021_01_01_000001_create_groups_table.php <<'EOM'
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('groups', function (Blueprint $table) {
$table->id();
$table->string('displayName')->unique();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('groups');
}
};
EOM
# Group model with members() relation
RUN cat > app/Models/Group.php <<'EOM'
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use App\Models\User;
class Group extends Model
{
use HasFactory;
protected $fillable = ['displayName'];
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class, 'group_user', 'group_id', 'user_id')->withTimestamps();
}
}
EOM
# Override SCIM config to use app's Group model
RUN mkdir -p app/SCIM && cat > app/SCIM/CustomSCIMConfig.php <<'EOM'
<?php
namespace App\SCIM;
use ArieTimmerman\Laravel\SCIMServer\SCIMConfig as BaseSCIMConfig;
use App\Models\Group;
class CustomSCIMConfig extends BaseSCIMConfig
{
public function getGroupClass()
{
return Group::class;
}
}
EOM
# Bind CustomSCIMConfig in the container
RUN cat > app/Providers/AppServiceProvider.php <<'EOM'
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use ArieTimmerman\Laravel\SCIMServer\SCIMConfig as BaseSCIMConfig;
use App\SCIM\CustomSCIMConfig;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(BaseSCIMConfig::class, CustomSCIMConfig::class);
}
public function boot(): void
{
//
}
}
EOM
# Group factory
RUN cat > database/factories/GroupFactory.php <<'EOM'
<?php
namespace Database\Factories;
use App\Models\Group;
use Illuminate\Database\Eloquent\Factories\Factory;
class GroupFactory extends Factory
{
protected $model = Group::class;
public function definition(): array
{
return [
'displayName' => $this->faker->unique()->company(),
];
}
}
EOM
# Pivot table for memberships
RUN cat > /example/database/migrations/2021_01_01_000002_create_group_user_table.php <<'EOM'
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('group_user', function (Blueprint $table) {
$table->id();
$table->foreignId('group_id')->constrained('groups')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->timestamps();
$table->unique(['group_id', 'user_id']);
});
}
public function down(): void
{
Schema::dropIfExists('group_user');
}
};
EOM
# Ensure User model has groups() relation (overwrite default)
RUN cat > app/Models/User.php <<'EOM'
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
public function groups(): BelongsToMany
{
return $this->belongsToMany(Group::class, 'group_user', 'user_id', 'group_id')->withTimestamps();
}
}
EOM
# Seeder for demo data
RUN cat > /example/database/seeders/DemoSeeder.php <<'EOM'
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Group;
class DemoSeeder extends Seeder
{
public function run(): void
{
$users = User::factory()->count(50)->create();
$groups = Group::factory()->count(10)->create();
foreach ($groups as $g) {
$g->members()->sync($users->random(rand(3, 10))->pluck('id')->toArray());
}
}
}
EOM
# Run migrations and seed demo data
RUN php artisan migrate && php artisan db:seed --class=Database\\Seeders\\DemoSeeder
CMD ["php","artisan","serve","--host=0.0.0.0","--port=8000"]