-
Notifications
You must be signed in to change notification settings - Fork 5
/
photoprism.yaml
464 lines (464 loc) · 16.5 KB
/
photoprism.yaml
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
AWSTemplateFormatVersion: 2010-09-09
Description: An example CloudFormation template to deploy PhotoPrism on ECS Fargate along with a RDS MariaDB.
Parameters:
VPC:
Type: AWS::EC2::VPC::Id
Subnet1:
Type: AWS::EC2::Subnet::Id
Subnet2:
Type: AWS::EC2::Subnet::Id
# uncomment to allow HTTPS instead of HTTP
# Certificate:
# Type: String
# # Update with the certificate ARN from Certificate Manager, which must exist in the same region.
# Default: 'arn:aws:acm:region:123456789010:certificate/00000000-0000-0000-0000-000000000000'
Image:
Type: String
Default: photoprism/photoprism:latest
ServiceName:
Type: String
Default: PhotoprismService
ContainerPort:
Type: Number
Default: 2342
LoadBalancerPort:
Type: Number
Default: 80 # change to 443 for HTTPS
DatabaseName:
Type: String
Default: photoprism
DatabaseUsername:
Type: String
Default: photoprism
DatabasePassword:
Type: String
MinLength: 1
DatabasePort:
Type: Number
Default: 3306
HealthCheckPath:
Type: String
Default: /
# HostedZoneName:
# Type: String
# Default: company.com
# Subdomain:
# Type: String
# Default: Photoprismservice
MinContainers:
Type: Number
Default: 1
Description: for autoscaling
MaxContainers:
Type: Number
Default: 10
Description: for autoscaling
AutoScalingTargetValue:
Type: Number
Default: 50
Description: target CPU utilization (%)
PosixUserIdentifier:
Type: Number
Default: 1000
PosixGroupIdentifier:
Type: Number
Default: 1000
PhotoPrismAdminPassword:
Type: String
MinLength: 4
Description: Your initial admin password (min 4 characters)
PhotoPrismSiteTitle:
Type: String
Default: PhotoPrism
PhotoPrismSiteCaption:
Type: String
Default: Browse Your Life
PhotoPrismSiteDescription:
Type: String
Default: Description
PhotoPrismSiteAuthor:
Type: String
Default: Author
Resources:
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Join ['', [!Ref ServiceName, Cluster]]
TaskDefinition:
Type: AWS::ECS::TaskDefinition
# log group needs to be created before it is used.
DependsOn: LogGroup
Properties:
# Name for the task definition
Family: !Join ['', [!Ref ServiceName, TaskDefinition]]
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
Cpu: 2048
Memory: 4GB
# "The ARN of the task execution role that containers in this task can assume. All containers in this task are granted the permissions that are specified in this role."
# "There is an optional task execution IAM role that you can specify with Fargate to allow your Fargate tasks to make API calls to Amazon ECR."
ExecutionRoleArn: !Ref ExecutionRole
# "The Amazon Resource Name (ARN) of an AWS Identity and Access Management (IAM) role that grants containers in the task permission to call AWS APIs on your behalf."
TaskRoleArn: !Ref TaskRole
ContainerDefinitions:
- Name: !Ref ServiceName
Image: !Ref Image
PortMappings:
- ContainerPort: !Ref ContainerPort
User: !Join ['', [!Ref PosixUserIdentifier, ':', !Ref PosixGroupIdentifier]]
Environment:
- Name: PHOTOPRISM_ADMIN_PASSWORD
Value: !Ref PhotoPrismAdminPassword # Your initial admin password (min 4 characters)
- Name: PHOTOPRISM_HTTP_PORT
Value: !Ref ContainerPort # Built-in Web server port
- Name: PHOTOPRISM_HTTP_COMPRESSION
Value: gzip # Improves transfer speed and bandwidth utilization (none or gzip)
- Name: PHOTOPRISM_DEBUG
Value: false # Run in debug mode (shows additional log messages)
- Name: PHOTOPRISM_PUBLIC
Value: false # No authentication required (disables password protection)
- Name: PHOTOPRISM_READONLY
Value: false # Don't modify originals directory (reduced functionality)
- Name: PHOTOPRISM_EXPERIMENTAL
Value: false # Enables experimental features
- Name: PHOTOPRISM_DISABLE_WEBDAV
Value: false # Disables built-in WebDAV server
- Name: PHOTOPRISM_DISABLE_SETTINGS
Value: false # Disables Settings in Web UI
- Name: PHOTOPRISM_DISABLE_TENSORFLOW
Value: false # Disables using TensorFlow for image classification
- Name: PHOTOPRISM_DARKTABLE_PRESETS
Value: false # Enables Darktable presets and disables concurrent RAW conversion
- Name: PHOTOPRISM_DETECT_NSFW
Value: false # Flag photos as private that MAY be offensive (requires TensorFlow)
- Name: PHOTOPRISM_UPLOAD_NSFW
Value: true # Allow uploads that MAY be offensive
# - Name: PHOTOPRISM_DATABASE_DRIVER
# Value: sqlite # SQLite is an embedded database that doesn't require a server
- Name: PHOTOPRISM_DATABASE_DRIVER
Value: mysql # Use MariaDB (or MySQL) instead of SQLite for improved performance
- Name: PHOTOPRISM_DATABASE_SERVER
Value: !Join [ '', [ !GetAtt [ PhotoprismDatabase, Endpoint.Address ], ':', !GetAtt [PhotoprismDatabase, Endpoint.Port ] ] ] # MariaDB database server (hostname:port)
- Name: PHOTOPRISM_DATABASE_NAME
Value: !Ref DatabaseName # MariaDB database schema name
- Name: PHOTOPRISM_DATABASE_USER
Value: !Ref DatabaseUsername # MariaDB database user name
- Name: PHOTOPRISM_DATABASE_PASSWORD
Value: !Ref DatabasePassword # MariaDB database user password
#- Name: PHOTOPRISM_SITE_URL
# Value: "http://localhost:2342/" # Public PhotoPrism URL
- Name: PHOTOPRISM_SITE_TITLE
Value: !Ref PhotoPrismSiteTitle
- Name: PHOTOPRISM_SITE_CAPTION
Value: !Ref PhotoPrismSiteCaption
- Name: PHOTOPRISM_SITE_DESCRIPTION
Value: !Ref PhotoPrismSiteDescription
- Name: PHOTOPRISM_SITE_AUTHOR
Value: !Ref PhotoPrismSiteAuthor
MountPoints:
- SourceVolume: photoprism-settings-index-sidecar
ContainerPath: '/photoprism/storage'
ReadOnly: false
- SourceVolume: photoprism-photo-video-originals
ContainerPath: '/photoprism/originals'
ReadOnly: false
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: ecs
Volumes:
- Name: photoprism-settings-index-sidecar
EFSVolumeConfiguration:
FilesystemId: !Ref PhotoprismEFSVolume
TransitEncryption: ENABLED
AuthorizationConfig:
AccessPointId: !Ref PhotoprismEFSAccessPointSettingsIndexSidecar
- Name: photoprism-photo-video-originals
EFSVolumeConfiguration:
FilesystemId: !Ref PhotoprismEFSVolume
TransitEncryption: ENABLED
AuthorizationConfig:
AccessPointId: !Ref PhotoprismEFSAccessPointOriginals
ExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join ['', [!Ref ServiceName, ExecutionRole]]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'
TaskRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join ['', [!Ref ServiceName, TaskRole]]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
# ManagedPolicyArns:
# -
# Policies:
# -
# A role needed for auto scaling
AutoScalingRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join ['', [!Ref ServiceName, AutoScalingRole]]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceAutoscaleRole'
ContainerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref ServiceName, ContainerSecurityGroup]]
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: !Ref ContainerPort
ToPort: !Ref ContainerPort
SourceSecurityGroupId: !Ref LoadBalancerSecurityGroup
LoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref ServiceName, LoadBalancerSecurityGroup]]
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: !Ref LoadBalancerPort
ToPort: !Ref LoadBalancerPort
CidrIp: 0.0.0.0/0
Service:
Type: AWS::ECS::Service
DependsOn:
- ListenerHTTP
Properties:
ServiceName: !Ref ServiceName
Cluster: !Ref Cluster
TaskDefinition: !Ref TaskDefinition
DeploymentConfiguration:
MinimumHealthyPercent: 100
MaximumPercent: 200
DesiredCount: 1
HealthCheckGracePeriodSeconds: 300
LaunchType: FARGATE
# requires additional ssmmessages policy, see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-enabling-and-using
EnableExecuteCommand: true
NetworkConfiguration:
AwsvpcConfiguration:
# can be changed to DISABLED if using private subnets that have access to a NAT gateway
AssignPublicIp: ENABLED
Subnets:
- !Ref Subnet1
- !Ref Subnet2
SecurityGroups:
- !Ref ContainerSecurityGroup
LoadBalancers:
- ContainerName: !Ref ServiceName
ContainerPort: !Ref ContainerPort
TargetGroupArn: !Ref TargetGroup
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 10
HealthCheckPath: !Ref HealthCheckPath
HealthCheckTimeoutSeconds: 5
UnhealthyThresholdCount: 2
HealthyThresholdCount: 2
Name: !Join ['', [!Ref ServiceName, TargetGroup]]
Port: !Ref ContainerPort
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60 # default = 300
- Key: stickiness.enabled
Value: true
TargetType: ip
VpcId: !Ref VPC
ListenerHTTP:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- TargetGroupArn: !Ref TargetGroup
Type: forward
LoadBalancerArn: !Ref LoadBalancer
Port: !Ref LoadBalancerPort
Protocol: HTTP
# Protocol: HTTPS
# Certificates:
# - CertificateArn: !Ref Certificate
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
LoadBalancerAttributes:
# default
- Key: idle_timeout.timeout_seconds
Value: 60
Name: !Join ['', [!Ref ServiceName, LoadBalancer]]
Scheme: internet-facing
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
Subnets:
- !Ref Subnet1
- !Ref Subnet2
# DNSRecord:
# Type: AWS::Route53::RecordSet
# Properties:
# HostedZoneName: !Join ['', [!Ref HostedZoneName, .]]
# Name: !Join ['', [!Ref Subdomain, ., !Ref HostedZoneName, .]]
# Type: A
# AliasTarget:
# DNSName: !GetAtt LoadBalancer.DNSName
# HostedZoneId: !GetAtt LoadBalancer.CanonicalHostedZoneID
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Join ['', [!Ref ServiceName, TaskDefinition]]
AutoScalingTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MinCapacity: !Ref MinContainers
MaxCapacity: !Ref MaxContainers
ResourceId: !Join ['/', [service, !Ref Cluster, !GetAtt Service.Name]]
ScalableDimension: ecs:service:DesiredCount
ServiceNamespace: ecs
RoleARN: !GetAtt AutoScalingRole.Arn
AutoScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: !Join ['', [!Ref ServiceName, AutoScalingPolicy]]
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref AutoScalingTarget
TargetTrackingScalingPolicyConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ECSServiceAverageCPUUtilization
ScaleInCooldown: 10
ScaleOutCooldown: 10
# e.g. keep things at or lower than x% CPU utilization
TargetValue: !Ref AutoScalingTargetValue
PhotoprismEFSVolume:
Type: AWS::EFS::FileSystem
Properties:
Encrypted: true
FileSystemTags:
- Key: Name
Value: !Sub "${AWS::StackName}-efs-vol"
PhotoprismEFSAccessPointSettingsIndexSidecar:
Type: AWS::EFS::AccessPoint
Properties:
FileSystemId: !Ref PhotoprismEFSVolume
PosixUser:
Uid: !Ref PosixUserIdentifier
Gid: !Ref PosixGroupIdentifier
RootDirectory:
CreationInfo:
OwnerGid: !Ref PosixGroupIdentifier
OwnerUid: !Ref PosixUserIdentifier
Permissions: "0700"
Path: "/settings-index-sidecar"
PhotoprismEFSAccessPointOriginals:
Type: AWS::EFS::AccessPoint
Properties:
FileSystemId: !Ref PhotoprismEFSVolume
PosixUser:
Uid: !Ref PosixUserIdentifier
Gid: !Ref PosixGroupIdentifier
RootDirectory:
CreationInfo:
OwnerGid: !Ref PosixGroupIdentifier
OwnerUid: !Ref PosixUserIdentifier
Permissions: "0755"
Path: "/originals"
PhotoprismEFSServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "${AWS::StackName}-efs-server-endpoints"
GroupDescription: Which client ip addrs are allowed to access EFS server endpoints for photoprism mount
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !Ref ContainerSecurityGroup
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-efs-server"
PhotoprismEFSMountTargetA:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref PhotoprismEFSVolume
SecurityGroups:
- !Ref PhotoprismEFSServerSecurityGroup
SubnetId: !Ref Subnet1
PhotoprismEFSMountTargetB:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref PhotoprismEFSVolume
SecurityGroups:
- !Ref PhotoprismEFSServerSecurityGroup
SubnetId: !Ref Subnet2
PhotoprismDatabase:
Type: AWS::RDS::DBInstance
Properties:
DBSubnetGroupName: !Ref PhotoprismDatabaseSubnetGroup
DBName: !Ref DatabaseName
VPCSecurityGroups:
- Ref: PhotoprismDatabaseSecurityGroup
AllocatedStorage: '5'
DBInstanceClass: db.t3.micro
Port: !Ref DatabasePort
Engine: mariadb
EngineVersion: 10.5
MasterUsername: !Ref DatabaseUsername
MasterUserPassword: !Ref DatabasePassword
DBParameterGroupName: !Ref PhotoprismDatabaseParamGroup
DeletionPolicy: Snapshot
PhotoprismDatabaseParamGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Family: mariadb10.5
Description: PhotoPrism database parameter group
Parameters:
tx_isolation: 'READ-COMMITTED'
character_set_server: 'utf8mb4'
collation_server: 'utf8mb4_unicode_ci'
max_connections: '512'
innodb_rollback_on_timeout: 'OFF'
innodb_lock_wait_timeout: '50'
PhotoprismDatabaseSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: PhotoPrism database subnet group
SubnetIds:
- !Ref Subnet1
- !Ref Subnet2
PhotoprismDatabaseSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Ingress for PhotoPrism database
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: !Ref DatabasePort
ToPort: !Ref DatabasePort
SourceSecurityGroupId: !Ref ContainerSecurityGroup
Outputs:
LoadBalancerUrl:
Description: The URL of the loadbalancer
Value: !GetAtt LoadBalancer.DNSName
# Endpoint:
# Description: Endpoint
# Value: !Join ['', ['https://', !Ref DNSRecord]]