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#!/bin/bash
# Equalify Reflow โ Floci S3 initialization script
#
# Run from a sidecar container (amazon/aws-cli) with:
# AWS_ACCESS_KEY_ID=test
# AWS_SECRET_ACCESS_KEY=test
# AWS_DEFAULT_REGION=us-east-1
# AWS_ENDPOINT_URL=http://floci:4566
#
# The awscli reads AWS_ENDPOINT_URL automatically, so every `aws` command
# below targets Floci instead of real AWS. The sidecar's compose
# `depends_on: floci (service_healthy)` gate replaces the old
# "wait for localstack ready.d" sleep pattern.
set -e
echo "=========================================="
echo "Initializing Floci for Equalify Reflow"
echo "=========================================="
TEMP_BUCKET="equalify-pdf-temp"
RESULTS_BUCKET="equalify-pdf-results"
REGION="us-east-1"
create_bucket() {
local bucket_name=$1
echo "Creating S3 bucket: ${bucket_name}"
if aws s3 mb "s3://${bucket_name}" --region "${REGION}" 2>/dev/null; then
echo "โ Bucket ${bucket_name} created successfully"
else
echo "โ Bucket ${bucket_name} already exists or creation failed"
fi
}
configure_cors() {
local bucket_name=$1
echo "Configuring CORS for bucket: ${bucket_name}"
aws s3api put-bucket-cors --bucket "${bucket_name}" --cors-configuration '{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedHeaders": ["*"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3000
}
]
}' 2>/dev/null || echo "โ CORS configuration failed for ${bucket_name}"
}
configure_public_read() {
local bucket_name=$1
echo "Configuring public read access for bucket: ${bucket_name}"
aws s3api put-bucket-policy --bucket "${bucket_name}" --policy "{
\"Version\": \"2012-10-17\",
\"Statement\": [
{
\"Sid\": \"PublicReadGetObject\",
\"Effect\": \"Allow\",
\"Principal\": \"*\",
\"Action\": \"s3:GetObject\",
\"Resource\": \"arn:aws:s3:::${bucket_name}/*\"
}
]
}" 2>/dev/null || echo "โ Public read policy configuration failed for ${bucket_name}"
}
enable_versioning() {
local bucket_name=$1
echo "Enabling versioning for bucket: ${bucket_name}"
aws s3api put-bucket-versioning \
--bucket "${bucket_name}" \
--versioning-configuration Status=Enabled 2>/dev/null || \
echo "โ Versioning configuration failed for ${bucket_name}"
}
echo ""
echo "Creating S3 buckets..."
create_bucket "${TEMP_BUCKET}"
create_bucket "${RESULTS_BUCKET}"
echo ""
echo "Configuring CORS..."
configure_cors "${TEMP_BUCKET}"
configure_cors "${RESULTS_BUCKET}"
echo ""
echo "Configuring bucket policies..."
configure_public_read "${RESULTS_BUCKET}"
echo ""
echo "Enabling versioning..."
enable_versioning "${RESULTS_BUCKET}"
echo ""
echo "Configuring lifecycle policies..."
aws s3api put-bucket-lifecycle-configuration \
--bucket "${TEMP_BUCKET}" \
--lifecycle-configuration '{
"Rules": [
{
"ID": "DeleteTempFilesAfter7Days",
"Status": "Enabled",
"Prefix": "",
"Expiration": {
"Days": 7
}
}
]
}' 2>/dev/null || echo "โ Lifecycle policy configuration failed for ${TEMP_BUCKET}"
echo ""
echo "Verifying bucket creation..."
if aws s3 ls | grep -q "${TEMP_BUCKET}"; then
echo "โ ${TEMP_BUCKET} verified"
else
echo "โ ${TEMP_BUCKET} verification failed"
fi
if aws s3 ls | grep -q "${RESULTS_BUCKET}"; then
echo "โ ${RESULTS_BUCKET} verified"
else
echo "โ ${RESULTS_BUCKET} verification failed"
fi
echo ""
echo "Testing S3 upload capability..."
echo "Test file created by Floci init script" > /tmp/test.txt
if aws s3 cp /tmp/test.txt "s3://${TEMP_BUCKET}/test.txt" 2>/dev/null; then
echo "โ S3 upload test successful"
aws s3 rm "s3://${TEMP_BUCKET}/test.txt" 2>/dev/null
rm /tmp/test.txt
else
echo "โ S3 upload test failed"
fi
echo ""
echo "=========================================="
echo "Floci initialization complete!"
echo "=========================================="
echo ""
echo "Available S3 buckets:"
aws s3 ls
echo ""
echo "S3 endpoint: ${AWS_ENDPOINT_URL:-http://floci:4566}"
echo "=========================================="