I created an aws-rails-provisioner project following the guidelines on the GitHub page and copied their default yaml file for a single application. When I ran
aws-rails-provisioner build --profile FargateSandboxAdmin --with-cicd -f ./aws-rails-provisioner.yml
it appeared to accept the profile parameter with no issues, however when I went to deploy it using
aws-rails-provisioner deploy --profile FargateSandboxAdmin
I received an error that --profile was not valid:
/Users/todd/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/aws-rails-provisioner-0.0.1.rc2/bin/aws-rails-provisioner:128:in '<top (required)>': undefined local variable or method 'profile' for main:Object (NameError)
from /Users/todd/.rbenv/versions/2.4.5/bin/aws-rails-provisioner:23:in 'load'
from /Users/todd/.rbenv/versions/2.4.5/bin/aws-rails-provisioner:23:in '<main>'
The same is true when using the -p flag instead of --profile. After running a "regular" deploy with aws-rails-provisioner deploy it created all the objects under my parent account and not the sandbox I set up for it.
Is there any way to use profiles with aws-rails-provisioner or is it not supported at this time?
Related
I have a Rails 6.0.0.rc1 application (with the appengine gem install) that I deployed to GCP. Is there a way to log into a remote rails console on the instance that runs the application? I tried this:
bundle exec rake appengine:exec -- bundle exec rails c
which gives the following output:
...
---------- EXECUTE COMMAND ----------
bundle exec rails c
Loading production environment (Rails 6.0.0.rc1)
Switch to inspect mode.
...
so apparently it executed the command, but closes the connection right after.
Is there an easy way to do this?
As reference: On Heroku this would simply be:
heroku run rails c --app my-application
There's a few steps involved:
https://gist.github.com/kyptin/e5da270a54abafac2fbfcd9b52cafb61
If you're running a Rails app in Google App Engine's flexible environment, it takes a bit of setup to get to a rails console attached to your deployed environment. I wanted to document the steps for my own reference and also as an aid to others.
Open the Google App Engine -> instances section of the Google Cloud Platform (GCP) console.
Select the "SSH" drop-down for a running instance. (Which instance? Both of my instances are in the same cluster, and both are running Rails, so it didn't matter for me. YMMV.) You have a choice about how to connect via ssh.
Choose "Open in browser window" to open a web-based SSH session, which is convenient but potentially awkward.
Choose "View gcloud command" to view and copy a gcloud command that you can use from a terminal, which lets you use your favorite terminal app but may require the extra steps of installing the gcloud command and authenticating the gcloud command with GCP.
When you're in the SSH session of your choice, run sudo docker ps to see what docker containers are presently running.
Identify the container of your app. Here's what my output looked like (abbreviated for easier reading). My app's container was the first one.
jeff#aef-default-425eaf...hvj:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND NAMES
38e......552 us.gcr.io/my-project/appengine/default... "/bin/sh -c 'exec bun" gaeapp
8c0......0ab gcr.io/google_appengine/cloud-sql-proxy "/cloud_sql_proxy -di" focused_lalande
855......f92 gcr.io/google_appengine/api-proxy "/proxy" api
7ce......0ce gcr.io/google_appengine/nginx-proxy "/var/lib/nginx/bin/s" nginx_proxy
25f......bb8 gcr.io/google_appengine/fluentd-logger "/opt/google-fluentd/" fluentd_logger
Note the container name of your app (gaeapp in my case), and run container_exec bash.
Add ruby and node to your environment: export PATH=$PATH:/rbenv/versions/2.3.4/bin:/rbenv/bin:/nodejs/bin
cd /app to get to your application code.
Add any necessary environment variables that your Rails application expects to your environment. For example: export DATABASE_URL='...'
If you don't know what your app needs, you can view the full environment of the app with cat app.yaml.
bin/rails console production to start a Rails console in the Rails production environment.
I'm an OpenShift newbie and just a while ago I managed to deploy a basic Rails app with the Next Gen console.
I did a few tweaks to the app, namely created a home controller with
`rails g controller home index`
and updated the config/routes.rb file by setting the root route to root 'home#index' instead of get 'home/index'.
Now the local rails server points correctly to the index page when running in development environment, so there is no problem at all.
But when I pushed the updated content to the git remote repository and and started a new build with
oc start-build <app>
and reloaded the page with the OpenShift production environment, nothing is shown but
An unhandled lowlevel error occurred. The application logs may have details.
Edit: the command oc logs dc/<app> returned me this as "root error":
#<RuntimeError: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`>
Then my config/secrets.yml in the production section reads:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Now I guess this has to do with setting up environment variables in an OpenShift environment. I found out the command
oc env dc/<app> <ENV_VARIABLE>=<value>
from this guide. Is it the correct one? If yes, how to generate a proper SECRET_KEY_BASE value?
Any help is of course highly appreciated, thank you
Solved. I found out eventually the rake secret command generates a hash for you, then used oc env dc/<app> SECRET_KEY_BASE=<hash> and rebuilt the app with oc start-build <app>
I am struggling to trouble shoot my app. I am new to AWS EC2 and come from Heroku. Generally I would use my "heroku logs --tail" console command to see why my app is erroring but on AWS I do not have that luxury (or at least know how).
To enter my production environment in the command line I...
...go to the folder where my example.pem is
...type ssh -i example.pem ubuntu#55.555.55.555
...type cd /etc/
...type cd /etc/projects/myapp
and from there I can
..."git pull origin master" to do my github pulls
..."sudo service apache2 reload" to restart my server after a change
...run "rails s" to see the logs on the local server.
The error does not happen when on "rails s" 55.555.55.555:3000 it only errors on live production 55.555.55.555.
How can I troubleshoot or at least see the production logs?
Use(inside Rails app directory):
tail -f log/production.log
We're trying to establish a block of gem-ready initialization code that runs exclusively in the context of a running Rails application, but it's proving mind-numbingly hard.
We want it to run when:
An app is started locally from the command line via rails server
An app is started on Heroku or other deployment environments
During testing
but NOT when:
A Rake task is being run
A generator is being run
Whatever is being run during the deploy process to Heroku
The last instance, especially, is tripping us up. Whenever we push to Heroku via git push heroku master, our app executes in some strange context where it's in production but no Heroku config variables are available to initializers.. can't find any info on it anywhere..
We've seen this asked elsewhere, but passing ENV variables isn't an option because it'll be in a gem.
I don't know how you can detect that you're in the Heroku asset pre-comp phase and avoid running some code, but you can get the Heroku environment variable to be available during pre-comp by using the 'user-env-compile' feature from Heroku Labs.
https://devcenter.heroku.com/articles/labs-user-env-compile
heroku labs:enable user-env-compile -a myapp
I am trying to debug a script in my Rails project with RubyMine, but the script doesn't see classes that are defined under my lib dir.
The run/debug configuration is running the script in the context of bundle, but the visibility apparently isn't the same as if I had run "rails r script/foo.rb" from command line.
I have tried configuring the debug session to use Ruby script: rails, and then give r script/foo.rb as the script arguments. RubyMine does not accept this as a valid configuration.
Suggestions? My goal is to be able to interactively debug my rails context scripts as I already can do with code running in the rails server.
Here's the Console output RubyMine:
/home/michael/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/michael/.rvm/gems/ruby-1.9.3-p194/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide --dispatcher-port 52376 --port 55139 -- /home/michael/work/myapp/script/foo.rb
Fast Debugger (ruby-debug-ide 0.4.17.beta14, ruby-debug-base 0.11.30.pre10) listens on 127.0.0.1:55139
Uncaught exception: uninitialized constant Foo::XLogger
/home/michael/work/myapp/script/foo.rb:17:in `go'
/home/michael/work/myapp/script/foo.rb:46:in `<top (required)>'
Process finished with exit code 0
XLogger is defined in /home/michael/work/myapp/lib/x_logger.rb.
I believe I have discovered my own answer/solution, but I offer it for anyone else having this same challenge.
In the Run/Debug Configurations
on the Configuration Tab
the Ruby script: field should be /path/to/rails/app/script/rails
the Script arguments: field should be r /path/to/rails/app/script/foo.rb