Comments (18)
Thank you for reporting this issue.
When using Heroku with a Cloudinary account that was created using the Heroku add-on, the configuration variables (e.g., cloud_name) are defined automatically. The CLOUDINARY_URL environment variable contains the required configuration.
You can manually define this variable for your Heroku existing application:
heroku config:add CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
Do you have a config initializer or a cloudinary.yml file? Maybe the asset precompiling process does not fully initializes the Rails application?
from cloudinary_gem.
I have already set that ENV variable.. but it is not working.
I'm deploying on heroku without the actual "cloudinary addon", but with manual setup. Is the presence of addon required to make things work?
I have cloudinary.yml file.. it looks like this:
default: &default
enhance_image_tag: true
static_image_support: true
cdn_subdomain: true
secure_distribution: false
private_cdn: false
staging:
<<: *default
from cloudinary_gem.
In addition, having something like this:
background: #eac891 image_url('purty_wood.png') repeat 50% 0;
Serves assets from cloudinary in development, but from /assets folder in production env.
from cloudinary_gem.
It seems that running 'rake assets:precompile' is using 'production' Rails environment in default (instead of development or staging).
Does your cloudinary.yml has a 'production' section?
from cloudinary_gem.
I've added the production section in yml file and now it fails during push:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Must supply cloud_name in tag or in configuration
from cloudinary_gem.
Btw, my heroku app is in staging env. I have these two as my heroku env vars:
RACK_ENV => staging
RAILS_ENV => staging
from cloudinary_gem.
From Heroku's documentation: https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar
"The most common cause of failures in assets:precompile is an app that relies on having its environment present to boot. Your app’s config vars are not present in the environment during slug compilation, so you should take steps to handle the nil case for config vars (and add-on resources) in your initializers."
You can specifically define the cloud_name parameter (only) either in a cloudinary.yml file or in a Rails initializer.
from cloudinary_gem.
I added cloud_name parameter to cloudinary.yml in production section and now it works!
Thanks @nadavs!
from cloudinary_gem.
Now it doesn't work again on heroku. It just fails silently and doesnt serve static assets from cloudinary
from cloudinary_gem.
and in development, some of assets are served from cloudinary and some from local /assets folder even though all are synced and references in .cloudinary.static files are fine
from cloudinary_gem.
Hi Milovan,
It worked fine when we tried it. Can you please share some more details regarding the specific problem and environment so we can try finding the cause for the problem?
from cloudinary_gem.
I have '.cloudinary.static' file ignored by git. After deploying to heroku I run: heroku run rake cloudinary:sync_static
. It seems to be working, but I checked from console and it does not create .cloudinary.static
file.
from cloudinary_gem.
.cloudinary.static
should be included in your git repository (not listed in .gitignore
).
We believe that the following happened: you deploy a version to Heroku which precompiles assets. While compiling sass files, .cloudinary.static
is not available. Therefore, all URLs of images in generated CSS files are local asset files.
Running cloudinary:sync_static
at Heroku would try uploading all images to Cloudinary. However, CSS files were already generated.
The way we planned it is that the developer runs cloudinary:sync_static
in a local development environment and commits the generated .cloudinary.static
file.
Please check if it works for you.
In addition, please tell us what do you think should be improved in this flow or its documentation. Thanks!
from cloudinary_gem.
There are two things I don't like about this approach:
- Developer needs to know API_KEY and API_SECRET for ALL environments (development, staging and production) in order to run that rake task. It is probably going to end up hard-coded into yml file and stored in repo which is a really bad thing.
- If I run
rake cloudinary:sync_static RAILS_ENV=staging
and thenrake cloudinary:sync_static RAILS_ENV=production
, both of them are going to write to same file, and thus overwrite each other. I'd need to keep these files on different git branches and it is going to be complex and confusing.
I don't think we can even write to file (.cloudinary.static) from rake task on heroku. I think that heroku doesn't allow that..? When I run that task on heroku it kinda completes, but this File.exists? Rails.root.join(".cloudinary.static")
returns false in heroku console.
Is there any way to have some kind of deploy hook that will sync static assets BEFORE precompiling assets?
from cloudinary_gem.
If heroku could write to .cloudinary.static
file would mean that if i run 2 successive deployments, second one would read from .cloudinary.static
file and precompile assets correctly.. but it is not
from cloudinary_gem.
Thank you for sharing your thoughts about this approach.
Regarding your comments: the public IDs generated for uploaded static images include an MD5 hash based on the image's content. Therefore, you can run the sync_static command in any environment (development, staging, production). No conflicts or override problems should occur between environments even if they share the same image file names (whether the files are identical or different).
That's why we think it's easiest to run this command from your development environment and commit the .cloudinary.static file. You can set the API Key & Secret locally using the environment variable fetched form Heroku (heroku config -s).
Regarding writing to .cloudinary.static in Heroku: which Heroku stack do you use? In new stacks it should work: https://devcenter.heroku.com/articles/dynos#isolation_and_security
from cloudinary_gem.
For any one else facing issues have a look at: https://devcenter.heroku.com/articles/labs-user-env-compile
from cloudinary_gem.
+1 with Carrierwave and Cloudinary in Rails application.
from cloudinary_gem.
Related Issues (20)
- Question: How to conditionally override `resource_type`? HOT 1
- Spaces in Font's name are not escaped HOT 6
- Incorrect documentation for ActiveStorage integration (Rails 6.1.4) HOT 2
- I'm using ActiveStorage and I would like to upload ttf font HOT 2
- Test the library with Ruby 3.0
- How to pass options to ActiveStorage upload? HOT 3
- Cant direct upload raw files HOT 17
- Some kind of overlay texts generate urls which cause `400 Bad Request` HOT 7
- Support Dynamic Folder upload parameters HOT 2
- How to get value txt file? HOT 3
- Update API is missing metadata support HOT 3
- Conditional metadata rules support HOT 6
- Broken urls - Unsafe characters in public_id are not properly escaped by Cloudinary::Utils.cloudinary_url HOT 2
- Photo metadata is nil until after AR callbacks have run HOT 7
- Unable to upload multiple images to cloudinary HOT 1
- ActiveStorage: Non-image file is not deleted when its blob is destroyed HOT 4
- ActiveStorage support for upload_large HOT 2
- Update sample projects dependencies HOT 4
- preview:duration effect was shortened to preview:du when uploading a video HOT 1
- Access token url generation returns 404 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudinary_gem.