Errno::EACCES: Permission denied @ rb_sysopen - /app/db/schema.rb

2/20/2020

I am getting the following error when I am trying to run rake db:migrate on my ec2 instance. I have a RDS postgres instance.

Errno::EACCES: Permission denied @ rb_sysopen - /app/db/schema.rb**

below are the relevant contents of my Dockerfile

FROM ubuntu:18.04

RUN apt-get update

RUN useradd -m deploy

WORKDIR /app

RUN mkdir -p vendor
COPY vendor/cache vendor/cache
RUN bundle install --deployment --local --without test development
COPY . .

RUN SECRET_KEY_BASE=111 RAILS_ENV=production bin/rake assets:precompile

RUN mkdir -p tmp/pids
RUN chown -R deploy tmp log

USER deploy
ENV RAILS_LOG_TO_STDOUT 1

EXPOSE 3000
CMD bin/rake db:migrate && bundle exec passenger start --address 0.0.0.0 --port 3000 --auto --disable-anonymous-telemetry -e production

here is my deployment yaml file

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: eks-learning-backend
spec:
  template:
    metadata:
      labels:
        name: eks-learning-backend
    spec:
      containers:
      - name: rails-app
        image: zzz.us-east-1.amazonaws.com/eks:16
        env:
        - name: EKS_DATABASE_NAME
          valueFrom:
            secretKeyRef:
              name: database-config
              key: database_name
        - name: EKS_DATABASE_HOST
          value: zzz.us-east-1.rds.amazonaws.com
        - name: EKS_DATABASE_USERNAME
          valueFrom:
            secretKeyRef:
              name: database-config
              key: username
        - name: EKS_DATABASE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: database-config
              key: password
        - name: RAILS_MASTER_KEY
          value: zzxx
        - name: RAILS_ENV
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace

Any help in this would be really great! Thanks.

-- opensource-developer
amazon-eks
docker
kubernetes
ruby-on-rails

1 Answer

2/21/2020

The problem is that the user has insufficient permissions. You only included RUN chown -R deploy tmp log while you also need to give it access to /app/db/ dir. Adding additional chown for the DB dir will solve the issue.

-- OhHiMark
Source: StackOverflow