Skip to content

Commit f82c157

Browse files
authored
Support a read-only root container filesystem (#73)
Declare writable locations with `VOLUME` instructions in the container build file so that bind mounts can be used in ECS to make those locations writable when deployed, with some configuration[1]. [1] navapbc/template-infra@60934c7 Related to #58
1 parent 662e9ba commit f82c157

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

template-only-docs/Deployment.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ While following the [infrastructure template installation instructions](https://
2222
1. In `/infra/<APP_NAME>/app-config/<ENVIRONMENT>.tf`:
2323
1. Set the `domain_name`.
2424
2. Set `enable_https` to `true`.
25-
3. Set `enable_command_execution` to `true`: This is necessary temporarily until a temporary file system can be enabled. Otherwise, ECS will run with read-only root filesystem, which will cause rails to error.
25+
1. In `/infra/<APP_NAME>/app-config/env-config/outputs.tf`:
26+
1. Configure the service's `ephemeral_write_volumes`:
27+
```terraform
28+
ephemeral_write_volumes = [
29+
"/rails/tmp"
30+
]
31+
```
2632
1. In `/infra/<APP_NAME>/app-config/env-config/environment-variables.tf`:
2733
1. Add an entry to `secrets`:
2834
```terraform

template/{{app_name}}/Dockerfile.jinja

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ENV RAILS_ENV="production" \
2020
# Start the server by default, this can be overwritten at runtime
2121
EXPOSE {{ app_local_port }}
2222

23+
# In production, this should be the only filesystem location with writes
24+
VOLUME /rails/tmp
2325

2426
##########################################################################################
2527
# BUILD: Throw-away build stage
@@ -74,6 +76,10 @@ RUN gem install debug -v 1.10.0
7476
# Copy application code
7577
COPY . .
7678

79+
# During local development, app is configured to write to more places
80+
VOLUME /rails/log
81+
VOLUME /rails/storage
82+
7783
CMD ["./bin/dev"]
7884

7985

template/{{app_name}}/docker-compose.mock-production.yml.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
# Rails app
1616
# Configured for "production" RAILS_ENV
1717
{{app_name}}:
18+
# the container root filesystem is read-only in production, so mirror that
19+
read_only: true
1820
build:
1921
context: .
2022
target: release

0 commit comments

Comments
 (0)