Skip to content

Commit 0b9933e

Browse files
committed
Use volume instead of priv in prod
1 parent c57919e commit 0b9933e

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ ENV LC_ALL en_US.UTF-8
8383
WORKDIR "/app"
8484
RUN chown nobody /app
8585

86+
# Create uploads directory
87+
RUN mkdir -p /app/priv/static/uploads && chown nobody:root /app/priv/static/uploads
88+
8689
# set runner ENV
8790
ENV MIX_ENV="prod"
8891

config/dev.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ config :phoenix_live_view,
8383

8484
# Disable swoosh api client as it is only required for production adapters.
8585
config :swoosh, :api_client, false
86+
87+
# Configure uploads path for development
88+
config :uploads, :uploads_path, nil

config/runtime.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ if config_env() == :prod do
5252
port = String.to_integer(System.get_env("PORT") || "4000")
5353

5454
config :uploads, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
55+
56+
config :uploads, :uploads_path, "/app/uploads"
5557

5658
config :uploads, UploadsWeb.Endpoint,
5759
url: [host: host, port: 443, scheme: "https"],

k8s.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ spec:
3131
resources:
3232
requests:
3333
memory: "256Mi"
34+
volumeMounts:
35+
- name: uploads-storage
36+
mountPath: /app/uploads
3437
livenessProbe:
3538
httpGet:
3639
path: /
@@ -43,6 +46,9 @@ spec:
4346
port: 8080
4447
initialDelaySeconds: 5
4548
periodSeconds: 5
49+
volumes:
50+
- name: uploads-storage
51+
emptyDir: {}
4652
---
4753
apiVersion: v1
4854
kind: Service

lib/uploads_web/live/upload_live.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ defmodule UploadsWeb.UploadLive do
55
@accept ~w(.zip .jpg .jpeg .png)
66

77
def root do
8-
Application.app_dir(:uploads, "priv/static/uploads")
8+
case Application.get_env(:uploads, :uploads_path) do
9+
nil -> Application.app_dir(:uploads, "priv/static/uploads")
10+
path -> path
11+
end
912
end
1013

1114
@impl true

0 commit comments

Comments
 (0)