Tom
Tom

Reputation: 9643

Rails - Can't create directory/files in Heroku's tmp folder?

I'm trying to create a directory named 'servers' using FileUtils in Heroku's tmp folder:

# create servers folder is it doesn't exist
dir = File.dirname("#{Rails.root}/tmp/servers")
FileUtils.mkdir(dir) unless File.directory?(dir)

I'm also trying to create with mkdir using Heroku's console but it doesn't seem to be created:

sudo heroku run 'mkdir /app/tmp/servers'
Running mkdir /app/tmp/servers on someapp... up, run.8611

sudo heroku run 'ls /app/tmp/.'
Running ls /app/tmp/. on someapp... up, run.3195
cache  heroku-buildpack-release-step.yml

What am I doing wrong?

Upvotes: 0

Views: 3119

Answers (1)

John Beynon
John Beynon

Reputation: 37507

You can write to the file system but when you do heroku run it's a one off dyno so entirely seperate to your web dynos, or even a second one off dyno. It takes a fresh copy of the slug (from your last deployment) - they don't share the same filesystem and nothing is persisted when the session is disconnected or terminated.

▶ heroku run bash
Running bash on xxx... up, run.5673
~ $ cd tmp
~/tmp $ mkdir foo
~/tmp $ cd foo
~/tmp/foo $ touch bah.txt
~/tmp/foo $ ls
bah.txt
~/tmp/foo $

and if you exit and open a new session

▶ heroku run bash
Running bash on xxx... up, run.6709
~ $ cd tmp
~/tmp $ ls
cache  heroku-buildpack-release-step.yml
~/tmp $

Upvotes: 6

Related Questions