'Ruby on Rails app in kubernetes with ingress-nginx isn't serving static files
I have Ruby on Rails app with admin dashboard hosting on Kubernetes.
I already have bundle exec rake assets:precompile and ENV RAILS_SERVE_STATIC_FILES true in Dockerfile. I see assets on the server but they are empty : 
My ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
meta.helm.sh/release-name: dev-api
meta.helm.sh/release-namespace: dev
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-Authentication-Chain,Source,X-Owner
nginx.ingress.kubernetes.io/cors-allow-methods: GET, POST, PUT, DELETE, OPTIONS
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
nginx.ingress.kubernetes.io/cors-max-age: "3600"
nginx.ingress.kubernetes.io/enable-cors: "true"
generation: 6
labels:
app: dev-api
app.kubernetes.io/managed-by: Helm
chart: api-1.0.0
heritage: Helm
release: api
name: dev-api
namespace: dev-space
spec:
rules:
- host: dev.example.com
http:
paths:
- backend:
service:
name: dev-api
port:
number: 8080
path: /api/v1
pathType: Prefix
- backend:
service:
name: dev-api
port:
number: 8080
path: /admin
pathType: Prefix
upd:
FROM ruby:3.0.3
RUN mkdir /backend
WORKDIR /backend
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true
COPY Gemfile /backend/Gemfile
COPY Gemfile.lock /backend/Gemfile.lock
RUN gem install bundler -v 2.2.32
RUN bundle install
COPY . ./
EXPOSE 3001
# Start the puma server
RUN bundle exec rake assets:precompile
CMD bundle exec puma -p 3001
I think it's the wrong nginx configuration, but various manipulations with it did not bring results. Maybe you should try to take assets from some storage?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
