Skip to content

Staging Server Setup Walkthrough

Sam Joseph edited this page Mar 8, 2018 · 12 revisions

🚧 UNDER CONSTRUCTION 🚧

start by connecting to dokkuVM

and then check the current apps we have

agileventures@DokkuVM:~$ dokku apps:list
=====> My Apps
agileventures-react-front-end-production
asyncvoter-api-production
asyncvoter-api-test
asyncvoter-production
asyncvoter-staging
charity-commission-api-production
greeterbot-production
metplus-cruncher
metplus-pets-production
paironauts-develop
projectgreeterbot-production
agileventures@DokkuVM:~$ dokku apps:create metplus-pets-staging

then make a staging server

Creating metplus-pets-staging... done

we can also run commands over ssh like so:

ssh [email protected] apps:list

now we need to push the github repo of the main metplus rails app up to the staging server, so let's look at the different remotes we have set up:

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (development)]$ 
→ git remote -v
erika	https://github.com/Erika-Barr/MetPlus_PETS (fetch)
erika	https://github.com/Erika-Barr/MetPlus_PETS (push)
heroku	https://git.heroku.com/pets-master.git (fetch)
heroku	https://git.heroku.com/pets-master.git (push)
origin	https://github.com/AgileVentures/MetPlus_PETS (fetch)
origin	https://github.com/AgileVentures/MetPlus_PETS (push)

which it makes it look like I am not set up to deploy the rails app to dokku (I think Joao must have done this). I do have the relevant set up for the resumeCruncher:

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/resumeCruncher (master)]$ 
→ git remote -v
azure	[email protected]:metplus-cruncher (fetch)
azure	[email protected]:metplus-cruncher (push)
origin	https://github.com/AgileVentures/MetPlus_resumeCruncher.git (fetch)
origin	https://github.com/AgileVentures/MetPlus_resumeCruncher.git (push)

but so I set up connections for the main Rails app to both staging and production instances:

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (development)]$ 
→ git remote add production [email protected]:metplus-pets-production
[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (development)]$ 
→ git remote add staging [email protected]:metplus-pets-staging

Use this technique to work out what version is running in production:

commit 79fdeccf150948fd8b45af85811af3d57b162453
Author: Sam Joseph <[email protected]>
Date:   Fri Feb 2 12:57:00 2018 +0000

    make GA id dynamic fixes #698

Pulling that out locally I see that this is the latest commit on the master branch. Maybe we should create a staging branch but will need to coordinate with Joao on that. For the time being let's just push the master branch to the staging instance ...

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (master)]$ 
→ git push staging master
Counting objects: 16013, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4270/4270), done.
Writing objects: 100% (16013/16013), 3.93 MiB | 2.66 MiB/s, done.
Total 16013 (delta 11597), reused 15931 (delta 11534)
-----> Cleaning up...
-----> Building metplus-pets-staging from herokuish...
-----> Adding BUILD_ENV to build environment...
...

and that will take a little while. In the meantime we can take a look at the config on production. We'll need to replicate some of that on staging in order to have the app run effectively, and safely, so that it doesn't confuse the production set up. We'll also need to set up a staging URL as an endpoint ...

the deploy has failed since we need to set an airbrake project id:

Airbrake::Error: :project_id is required
       /tmp/build/vendor/bundle/ruby/2.3.0/gems/airbrake-ruby-2.6.2/lib/airbrake-ruby/notifier.rb:33:in `initialize'
       /tmp/build/vendor/bundle/ruby/2.3.0/gems/airbrake-ruby-2.6.2/lib/airbrake-ruby.rb:136:in `new'
       /tmp/build/vendor/bundle/ruby/2.3.0/gems/airbrake-ruby-2.6.2/lib/airbrake-ruby.rb:136:in `configure'
       /tmp/build/config/initializers/airbrake.rb:10:in `<top (required)>'
       /tmp/build/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
       /tmp/build/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `block in load'

To be continued ...

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (master)]$ 
→ ssh [email protected] config:set metplus-pets-staging AIRBRAKE_PROJECT_ID=128385
-----> Setting config vars
       AIRBRAKE_PROJECT_ID: 128385

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (master)]$ 
→ ssh [email protected] config:set metplus-pets-staging AIRBRAKE_API_KEY=1e93528e8f7e815eca75402a16c695cd
-----> Setting config vars
       AIRBRAKE_API_KEY: 1e93528e8f7e815eca75402a16c695cd
-----> Restarting app metplus-pets-staging
App metplus-pets-staging has not been deployed

that brings us on to this error

       rake aborted!
       PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

so we need to set up a database for this to run against

[tansaku@Samuels-MBP:~/Documents/Github/AgileVentures/MetPlus_PETS (master)]$ 
→ ssh [email protected] postgres:create metplus-pets-staging
       Waiting for container to be ready
       Creating container database
       Securing connection to database
=====> Postgres container created: metplus-pets-staging