Skip to content

Commit b275120

Browse files
committed
Updates to allow IP based EFS mount
1 parent cb1f3d0 commit b275120

File tree

3 files changed

+195
-4
lines changed

3 files changed

+195
-4
lines changed

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ RUN apt-get update && apt-get install -y \
3636
sqlite3 \
3737
python3 \
3838
python3-pip \
39+
nfs-common \
40+
gosu \
3941
&& rm -rf /var/lib/apt/lists/*
4042

4143
# Install Terraform
@@ -74,11 +76,15 @@ WORKDIR /app
7476
COPY --from=backend-builder /app/management-console ./
7577
COPY --from=frontend-builder /app/build ./build
7678

77-
# Set ownership
78-
RUN chown -R unity:unity /app
79+
# Copy entrypoint script
80+
COPY docker-entrypoint.sh /usr/local/bin/
7981

80-
# Switch to non-root user
81-
USER unity
82+
# Set ownership and permissions
83+
RUN chown -R unity:unity /app && \
84+
chmod +x /usr/local/bin/docker-entrypoint.sh
85+
86+
# Note: We don't switch to unity user here because we need root for NFS mounting
87+
# The entrypoint script will handle proper permissions
8288

8389
# Create Unity config directory in container
8490
RUN mkdir -p /home/unity/.unity
@@ -95,5 +101,8 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
95101
# Expose port
96102
EXPOSE 8080
97103

104+
# Set entrypoint
105+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
106+
98107
# Default command
99108
CMD ["./management-console", "webapp"]

docker-entrypoint.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Function to mount EFS with IP address
5+
mount_efs_with_ip() {
6+
local efs_ip="$1"
7+
local efs_id="$2"
8+
local access_point="$3"
9+
local mount_path="$4"
10+
11+
echo "Mounting EFS with IP address: $efs_ip"
12+
13+
# Create mount options
14+
MOUNT_OPTIONS="nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport"
15+
16+
# Add access point if provided
17+
if [ -n "$access_point" ]; then
18+
MOUNT_OPTIONS="${MOUNT_OPTIONS},accesspoint=${access_point}"
19+
fi
20+
21+
# Ensure mount path exists
22+
mkdir -p "$mount_path"
23+
24+
# Mount using IP address
25+
mount -t nfs4 -o "$MOUNT_OPTIONS" "${efs_ip}:/" "$mount_path"
26+
27+
echo "EFS mounted successfully at $mount_path"
28+
}
29+
30+
# Check if EFS mounting is needed
31+
if [ -n "$EFS_IP_ADDRESS" ] && [ -n "$EFS_FILE_SYSTEM_ID" ]; then
32+
echo "EFS IP address provided, attempting to mount..."
33+
34+
# Default mount path
35+
MOUNT_PATH="${EFS_MOUNT_PATH:-/data}"
36+
37+
# Mount EFS using IP address
38+
mount_efs_with_ip "$EFS_IP_ADDRESS" "$EFS_FILE_SYSTEM_ID" "$EFS_ACCESS_POINT_ID" "$MOUNT_PATH"
39+
40+
# Verify mount
41+
if mountpoint -q "$MOUNT_PATH"; then
42+
echo "EFS mount verified at $MOUNT_PATH"
43+
44+
# Create required directories with proper permissions
45+
mkdir -p "$MOUNT_PATH/workdir" "$MOUNT_PATH/database" "$MOUNT_PATH/config"
46+
chown -R unity:unity "$MOUNT_PATH"
47+
else
48+
echo "ERROR: EFS mount failed"
49+
exit 1
50+
fi
51+
else
52+
echo "No EFS_IP_ADDRESS provided, skipping EFS mount"
53+
fi
54+
55+
# Drop privileges and execute the main command as unity user
56+
exec gosu unity:unity "$@"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"family": "unity-management-console",
3+
"networkMode": "awsvpc",
4+
"requiresCompatibilities": ["FARGATE"],
5+
"cpu": "512",
6+
"memory": "1024",
7+
"executionRoleArn": "arn:aws:iam::<ACCOUNT_ID>:role/unity-dev-ecs-task-execution",
8+
"taskRoleArn": "arn:aws:iam::<ACCOUNT_ID>:role/unity-dev-ecs-task",
9+
"containerDefinitions": [
10+
{
11+
"name": "unity-console",
12+
"image": "<ACCOUNT_ID>.dkr.ecr.us-west-2.amazonaws.com/unity-dev-console:latest",
13+
"essential": true,
14+
"portMappings": [
15+
{
16+
"containerPort": 8080,
17+
"hostPort": 8080,
18+
"protocol": "tcp"
19+
}
20+
],
21+
"environment": [
22+
{
23+
"name": "UNITY_WORKDIR",
24+
"value": "/data/workdir"
25+
},
26+
{
27+
"name": "UNITY_DATABASE_PATH",
28+
"value": "/data/database"
29+
},
30+
{
31+
"name": "UNITY_CONFIG_PATH",
32+
"value": "/data/config/unity.yaml"
33+
},
34+
{
35+
"name": "UNITY_AWSREGION",
36+
"value": "us-west-2"
37+
},
38+
{
39+
"name": "UNITY_PROJECT",
40+
"value": "myproject"
41+
},
42+
{
43+
"name": "UNITY_VENUE",
44+
"value": "dev"
45+
},
46+
{
47+
"name": "UNITY_INSTALLPREFIX",
48+
"value": "unity"
49+
},
50+
{
51+
"name": "UNITY_BUCKETNAME",
52+
"value": "unity-myproject-dev-terraform-state"
53+
},
54+
{
55+
"name": "UNITY_MARKETPLACEOWNER",
56+
"value": "unity-sds"
57+
},
58+
{
59+
"name": "UNITY_MARKETPLACEREPO",
60+
"value": "unity-marketplace"
61+
},
62+
{
63+
"name": "EFS_IP_ADDRESS",
64+
"value": "<EFS_MOUNT_TARGET_IP>"
65+
},
66+
{
67+
"name": "EFS_FILE_SYSTEM_ID",
68+
"value": "<EFS_FILE_SYSTEM_ID>"
69+
},
70+
{
71+
"name": "EFS_ACCESS_POINT_ID",
72+
"value": "<EFS_ACCESS_POINT_ID>"
73+
},
74+
{
75+
"name": "EFS_MOUNT_PATH",
76+
"value": "/data"
77+
}
78+
],
79+
"logConfiguration": {
80+
"logDriver": "awslogs",
81+
"options": {
82+
"awslogs-group": "/ecs/unity-management-console",
83+
"awslogs-region": "us-west-2",
84+
"awslogs-stream-prefix": "ecs"
85+
}
86+
},
87+
"healthCheck": {
88+
"command": [
89+
"CMD-SHELL",
90+
"curl -f http://localhost:8080/health || exit 1"
91+
],
92+
"interval": 30,
93+
"timeout": 5,
94+
"retries": 3,
95+
"startPeriod": 60
96+
},
97+
"stopTimeout": 30,
98+
"startTimeout": 120,
99+
"linuxParameters": {
100+
"capabilities": {
101+
"add": ["SYS_ADMIN"]
102+
}
103+
},
104+
"privileged": false
105+
}
106+
],
107+
"placementConstraints": [],
108+
"tags": [
109+
{
110+
"key": "Project",
111+
"value": "unity"
112+
},
113+
{
114+
"key": "Environment",
115+
"value": "dev"
116+
},
117+
{
118+
"key": "ManagedBy",
119+
"value": "terraform"
120+
},
121+
{
122+
"key": "Application",
123+
"value": "unity-management-console"
124+
}
125+
]
126+
}

0 commit comments

Comments
 (0)