Install Docker and Devstep, read and do step 1) and 2) of http://www.akretion.com.br/blog/run-locomotivecms-website-locally-in-minutes-using-wagon-and-devstep-docker
1) running MongoDB in a dedicated container
First download the official MongoDB image with (you can do the next steps in an other terminal while it’s downloading):
docker pull dockerfile/mongodb
Now we will create a workspace folder where we will later create our Rails app and where we will leave the persistent data directory of our MongoDB container, let’s call it loco-devstep:
Start Mongodb. We will here expose MongoDB to the host, but as I already had a running MongoDB, I will shift the port so that from the host I can access that Dockerised MongoDB but using the 27018 port. If you don’t have a local MongoDB like me, you can keep 27017:27017 so you will use the default port and you won’t need to specify the port when doing commands from the host.
docker run -d -p 27018:27017 -v path_to_loco-devstep/db:/data/db --name mongodb dockerfile/mongodb
2) Install a LocomotiveCMS Engine in a dedicated Docker container
Here we will be roughly following the official Linux installation guide but with some simplifications and changes for our dockerized environment.
Here we assume we will create a new LocomotiveCMS Rails application called acme_cms (where you can push websites with Wagon for instance). But you could also very much instead clone an existing LocomotiveCMS Rails app instead of acme_cms and skip that section 2) - app initialization process - and instead do git clone some_repo_url acme_cms and continue at section 3).
In fact we will cheat Devstep in order to have a first pass to install the proper Ruby runtime and proper Rails version with a temporary Gemfile. Then we will use that proper Rails environment to generate a new LocomotiveCMS Engine application and we will finally launch Devstep again in that new application to install all the applications gems and run it.
echo "source 'https://rubygems.org'" > Gemfile echo "gem 'rails', '3.2.20'" >> Gemfile # note the 2 >> this time!
Now let’s start Devstep to install Rails 3.2.20 and then use it:
This will install rails 3.2.30 in the container so we can use it to generate a new Locomotive CMS Rails app with:
Now exit from that container using CRTL+D or the exit command and enter in the newly created folder acme_cms with
We will now edit the Gemfile; you can use your favorite editor to edit the file as we are outside of the container. Now add the following line to require the locomotive_cms gem from the 2.5.x branch after rails in the Gemfile
gem 'locomotive_cms', require: 'locomotive/engine', git: 'https://github.com/locomotivecms/engine.git', ref: 'v2.5.x'
Add the following line under the assets group:
gem 'compass', '~> 0.12.7' gem 'compass-rails', '~> 2.0.0'
Uncomment the following line under the assets group.
gem 'therubyracer', :platforms => :ruby
add the puma webserver gem at the end of the Gemfile with:
Finally your Gemfile should now look like:
source 'https://rubygems.org' gem 'rails', '3.2.20' gem 'locomotive_cms', require: 'locomotive/engine', git: 'https://github.com/locomotivecms/engine.git', ref: 'v2.5.x' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'compass', '~> 0.12.7' gem 'compass-rails', '~> 2.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end gem 'puma'
3) Launching our dockerized LocomotiveCMS container
ensure you are inside the Rails app directory, in our case acme_cms. Then launch a Devstep Docker container with the following command:
devstep hack -p 9292:9292 --link mongodb:mongodb
This will install all the gems required to run our app…
Now we will just tell LocomotiveCMS to inject some configuration files in our new Rails app in the case it has not been done already (it’s done already if you checked out a Rails app instead of creating one or if you already). So do:
exec rails g locomotive:install
Edit (you can do that from outside the container using your favorite editor) the generated config/mongoid.yml and replace the 3 occurrences of localhost by mongodb which is an host that Docker will know about because we used the –link mongodb:mongodb option when we started Devstep/Docker.
When this is done, just start the Rails app with:
bundle exec puma
In case you have the following error:
/workspace/config/initializers/devise.rb:4:in `block in <top (required)>': undefined method `secret_key=' for Devise:Module (NoMethodError)
This is because there is a discrepancy with the version of the Devise authentication gem and the confirguration file that has been generated by LocomotiveCMS for it. We could fork the LocomotiveCMS engine and change its Gemfile to depend on a newer Devise version, but as for now, a simple solution is just to edit /workspace/config/initializers/devise.rb and comment out the two lines with config.secret_key =… Then start again with bundle exec puma. This should work.
Now you can browse the http://localhost:9292 with your browser and set up a brand new site in this Mongodb database!
Here are the steps:
Note the API key in step 3/3 as we will need it later to push a website in the Engine.
From there we could create the new site by editing the templates and data from the LocomotiveCMS backoffice. But this isn’t the most productive way to do it. LocomotiveCMS is a revolution because of its site development workflow with Wagon.
So instead we will push a site developed with Wagon to this engine!
4) Pushing a Wagon website to our brand new engine
So Let’s assume you have some existing wagon website, for instance the one we built in that other Devstep tutorial: http://www.akretion.com.br/blog/run-locomotivecms-website-locally-in-minutes-using-wagon-and-devstep-docker
Assuming we want to push the website structure and content created in the container of the Wagon tutorial to our new Engine container and that both are running locally, we need to start the wagon container in a way it can connect to the Engine. For a production engine, it will typically run on some server with some IP or domain, but here this is not the case so we need to start the Wagon container telling about the Engine container.
I Assume here that you still have the Engine container running. We need to find out the name of that container, as it has automatically been set, we can find its name with the following command:
docker ps | grep 9292 2178931ceae0 fgrehm/devstep:v0.2.0 "/.devstep/bin/entry 6 hours ago Up 6 hours 0.0.0.0:9292->9292/tcp focused_ritchie
So here my Engine container is called focused_ritchie
In your host computer (not in a container), you will open a terminal and go inside the repository of the Wagon website (wisdom-for-wanderers in our other tutorial). You will now start the Wagon container a bit like in the Wagon tutorial, but this time with this command:
devstep hack -p 3333:3333 --link focused_ritchie:engine
Inside the wagon container we could now do wagon commands to display the local website on port 3333 or we could push it to the engine and this is what we will do this time. For that we need to set up the deployment website to target. in the wagon repo (), create a file called config/deploy.yml with this content:
development: host: engine:9292 email: the_email_you_used_in_the_engine password: the_password_you_used_in_the_engine api_key: the_api_key_display_at_state_3_of_the_site_setup
We will now push the website to our Engine. This local website has a Japanese translation that won’t match our Engine website setup possibly, so we will use the -f flag to force pushing that website with Japanese too:
bundle exec wagon push development -f
This will typically produced the following output:
You can now browse again http://localost:9292/locomotive and ensure the structure and the content have been pushed to our Dockerized Engine:
You can now hack the Wagon site again (from outside the container with your favorite editor) and push it again to the Engine. You’ll do the same to push to some production Engine or the Locomotive hosting offer, eventually specifying an other section than development (production) in the config/deploy.yml file and in the push command.