Divshot Ember app not reading production environment variable - ruby-on-rails

I have an ember-cli application that I'm deploying to Divshot using the ember-cli-divshot addon. In my config/environment.js file I want to have a different api between development and production.
Inside var ENV = {} I have:
api: 'http://localhost:3000'
And the I have this for production:
if (environment === 'production')
ENV.api = '<my production api>'
}
However when I do divshot push production, my Ember app is trying to hit the localhost endpoint for the api.

After some work I realized that I need to make sure the I'm building and deploying the production version of my Ember app, which is actually built into the ember-cli-divshot addon by prepending the deploy command with ember like this:
ember divshot push production

Related

Google App Engine + Ruby on rails + Redis + actioncable

How we should configure action cable in Rails to work in Google App Engine?
I have a Rails application which is using action cable for its messenger.
On my local-host the action cable working well in development and production environments but its not working on Google App Engine.
I have created a Computer Engine instance and installed Redis on it.
Firewall allows all traffic to Redis VM.
Redis has bind 0.0.0.0
When I deploy the app on Google App Engine I get the error:
Firefox can’t establish a connection to the server at wss://mydomain.com/cable.
here is my current configuration:
config/environments/production.rb
config.action_cable.url = 'wss://[MYDOMAIN].com/cable'
config.action_cable.disable_request_forgery_protection = true
config.force_ssl = true
...
config/cable.yml
production:
adapter: redis
url: redis://[IP_OF_REDIS_SERVER]:6379/
app.yaml
entrypoint: bundle exec rackup --port $PORT
env: flex
runtime: ruby
env_variables:
REDIS_PROVIDER: REDIS_URL
REDIS_URL: redis://[IP_OF_REDIS_SERVER]:6379/
SECRET_KEY_BASE: [My_Secret_Key]
I couldn't find anything about actioncable setting in Google documentation of App Engine. I hope this question can help me and everyone with same issue.
You must set create a VPC between your Redis instance and you App Engine instance. This is documented here:
https://cloud.google.com/appengine/docs/standard/python/connecting-vpc
Once you've done this, you'll have:
app.yaml
...
vpc_access_connector:
name: projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME
...
Secondly, the Google managed Redis server does not allow you to set a client id. I tried forcing it to be nil, but the ActionCable subscription adapter will try to set one for you:
https://github.com/rails/rails/blob/6-0-stable/actioncable/lib/action_cable/subscription_adapter/redis.rb#L18
In order to get it working properly, I had to override this behavior.
I added the following file into my rails app:
config/initializers/decorators/redis.rb
require 'action_cable/subscription_adapter/redis'
ActionCable::SubscriptionAdapter::Redis.class_eval do
cattr_accessor :redis_connector, default: ->(config) do
::Redis.new(config.except(:id, :adapter, :channel_prefix))
end
end
Now everything is working fine. My only concern now is that the client id is somehow required and I'm going to end up with some nasty bug due to it.
Hope this works for you if you try it out!

Is redis essential to use actioncable in heroku?

I made live chat using actioncable. This works perfectly locally. However, heroku's view / page does not render.
Is redis essential for heroku to work?
I also wrote the code in product.rb
config.action_cable.allowed_request_origins = ['https://my-url-45158.herokuapp.com', 'http://my-url-45158.herokuapp.com']
config.web_socket_server_url = "wss://my-url-45158.herokuapp.com/cable"
afaik yes it is, see this,
https://blog.heroku.com/real_time_rails_implementing_websockets_in_rails_5_with_action_cable
and this
http://edgeguides.rubyonrails.org/action_cable_overview.html#configuration
when in production mode rails use redis for its subscription adapter.
as written in the documentation
by default redis for production and async for development and test environments
beside that there is PostgreSQL Adapter and Async Adapter(but should not be used for production)

Remove ember-cli-mirage from ember

I am using ember-cli-mirage to serve for requests. As I have my rails api to serve those request, how i shd remove or uninstall ember-cli-mirage from my ember ?
If am removing mirage folder, am getting build error !!
You should leave Mirage installed (and the folder on disk) but disable the server whenever you want to use your actual backend API. This will let you use Mirage in selective environments, for example in testing.
By default, Mirage is disabled in production, and also in development when using the -proxy option.
To disable Mirage explicitly, you can set the enabled config option to false. For example, to always disable in development:
// config/environment.js
...
if (environment === 'development') {
ENV['ember-cli-mirage'] = {
enabled: false
};
}
Leave mirage installed, if you want to use your backend api just launch ember with
ember s --proxy http://localhost:8000
if api's are running on your machine on port 8000.
More info on mirage official site: http://www.ember-cli-mirage.com/docs/v0.3.x/configuration/#enabled

What is the best way to check the correct work of subdirectory rails production application before update in the production server?

I have the production application in the server in a subdirectory like www.server.cl/myapp.
But when I am in the development enviroment (running rails server) the application run on localhost:3000 and I can not check if the routes are 100% correct in the production enviroment (subdirectory) especially the assets paths.
Create staging environment (similar or identical to production environment) and deploy and test in this environment before deploy to production environment.
Here is more detail description.

Set custom RAILS_ENV for OpsWorks

I cannot for the life of me figure out how to get OpsWorks to use my rails staging environment. I have development, staging and production. Development for local machine and staging and production for two different stacks on OpsWoks. I am just trying to get my staging environment working, but it keeps deploying as production. Staging is basically a duplication of my development environment, but it's able to send email externally and has a different database host instead of localhost.
I am setting this custom json so far in my stack settings:
{
"deploy": {
"my_app_name": {
"rails_env": "staging",
"database": {
"adapter": "mysql2"
}
}
}
}
I kept having database connection issues with RDS until I added this database adapter key/pair. I just can't get it to start my rails app in staging.
When creating the App and specifying the git source and RDS it asks for "Rails environment". I set this to staging thinking that is all I needed to do to define what rails environment to use.
Any experts with OpsWorks that can help, it is greatly appreciated. I just started setting this up today. I wish the docs had a little better examples.
OpsWorks will start the app with the rails_env you specify in the custom json for the application. A caveat is that if you shell in to the server and do a rails console, you will see Rails.env is not equal to what you set in the JSON. This is because OpsWorks starts the application with the setting you entered, but it doesn't save that setting as an environment variable. So when you are on the cli, it doesn't know which environment to use.
For more information, refer to this excellent answer:
https://stackoverflow.com/a/21949946/973810

Resources