{"_id":"554587d435b2240d00838954","__v":0,"initVersion":{"_id":"54d5635532d98b0d00384afb","version":"0.1"},"project":"54d53c7b23010a0d001aca0c","user":{"_id":"54cfa8e1a8a4fd0d00b7fd1d","username":"","name":"Ruben Daniels"},"tags":[],"createdAt":"2015-05-03T02:28:36.332Z","changelog":[],"body":"The [Cloud9 Installer](doc:adding-an-installer) installs packages from various package managers into a workspace. The prime use case for the installer is to bundle an installation script with a plugin to install it's dependencies. For instance the collaboration feature of Cloud9 requires sqlite3 and [installs that](https://github.com/c9/c9.ide.collab/blob/master/install.js#L6) into an SSH workspace using the installer.\n\nA new use case that we recently discovered is using the installer to configure the workspace for frameworks, web servers, databases and other such packages that don't necessarily come with a plugin, but *simply want to configure the workspace.*\n\nRecently Cloud9 was [featured](http://getgrav.org/blog/cloud-ide-zero-to-code) on the blog of [grav](http://getgrav.org/) a php based CMS that works with flat files as its data source. In the blog article the writer outlined the steps needed to get the grav cms running in a Cloud9 workspace:\n\n```\n$ sudo apt-get update\n$ sudo apt-get install php5-curl\n$ sudo service apache2 restart\n# Enter Y when prompted to install the required packages.\n\n# Download and install the Grav Blog skeleton\n$ wget https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip\n$ unzip grav-skeleton-blog-site-v1.0.1.zip\n$ mv grav-skeleton-blog-site blog-site\n$ cd blog-site\n```\n\nThese are all easy steps that fit very well within the domain of the Cloud9 Installer, and so this blog article will take you through the steps to create an installer that automates these steps.\n\n# Install.js\n\nThe first thing we should do is create the install script which I'll store in a new directory. I call the file `install.js` and start with the basic skeleton:\n\n```\ndefine(function(require, exports, module) {\n\nmodule.exports = function(session, options){\n\n    session.start();\n};\n\n});\n```\n\nNext we'll create a single package that will execute all the steps outlined above.\n\n```\n    session.install({\n        \"name\": \"Grav\",\n        \"description\": \"A Modern Flat-File CMS\"\n    }, [\n        \n    ]);\n```\n\nThe package will break down in 3 tasks:\n- Installing the php5-curl package\n- Restarting apache\n- Downloading and unpacking the zip file\n\nLets start with the php5-curl package. Because Cloud9 runs on any POSIX platform we'll create several options for installing the package to support a multitude of environments.\n\n```\n        {\n            \"ubuntu\": [\"php5-curl\"],\n            \"centos\": [\"php-curl\"],\n            \"darwin\": [\"php-curl\"]\n        },\n```\n\nRestarting apache is as simple as executing the restart command via `bash`. Because this command might not be available on all platforms I added some code to make sure it will never fail.\n\n```\n        {\n            \"bash\": \"sudo service apache2 restart &> /dev/null || true\"\n        },\n```\n\nAnd lastly the following task definition downloads and unpacks the zip file.\n\n```\n        {\n            \"zip\": {\n                \"url\": \"https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip\",\n                \"target\": \"~/workspace/blog-site\",\n                \"dir\": \"grav-skeleton-blog-site\"\n            }\n        },\n```\n\nThis is all it takes. Check out the full implementation [here](https://github.com/c9/grav/blob/master/install.js).\n\n# Package.json\n\nNext up is the `package.json` file that will inform Cloud9 how to package and run the installer. Set the `installer` field to `install.js` and you're all set.\n\n```\n{\n    \"name\": \"grav\",\n    \"description\": \"Installs the Grav CMS - A Modern Flat-File CMS.\",\n    \"version\": \"0.1.0\",\n    \"author\": \"Cloud9\",\n    \"website\": \"http://getgrav.org\",\n    \"contributors\": [],\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"https://github.com/c9/grav.git\"\n    },\n    \"plugins\": {},\n    \"installer\": \"install.js\",\n    \"categories\": [\n        \"cms\"\n    ],\n    \"screenshots\": [\n        \"http://cdn.getgrav.org/user/pages/02.blog/cloud-ide-zero-to-code/cloud9-term.png?a75a9344\"\n    ],\n    \"licenses\": [\n        \"MIT\"\n    ]\n}\n```\n\n# Test\n\nBefore publishing you'll want to test the package. The updated [Cloud9 CLI](doc:the-cloud9-cli) facilitates this. Run `c9 install .` while in your package root directory.\n\n```\n~/grav$ c9 install .\nInstalling Dependencies... [Done]\nSuccessfully installed grav@test\n```\n\nTo see what it is actually doing add the `--verbose` flag.\n\n```\n~/grav$ c9 install . --verbose\nInstalling package locally\nInstallation Started\n\nPackage grav 1\n--------------\nInstalling Grav\n\nSelecting previously unselected package php5-curl.\n(Reading database ... 127410 files and directories currently installed.)\nPreparing to unpack .../php5-curl_5.6.7+dfsg-1_amd64.deb ...\nUnpacking php5-curl (5.6.7+dfsg-1) ...\nSetting up php5-curl (5.6.7+dfsg-1) ...\n\nDownloading... https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip\n2015-05-03 04:35:08 URL:https://s3.amazonaws.com/github-cloud/releases/22577202/4fe5e0a2-eaa8-11e4-8eeb-b67b00e8e705.zip?response-content-disposition=attachment%3B%20filename%3Dgrav-skeleton-blog-site-v1.0.1.zip&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1430627767&Signature=znV7k93mHXWQqFN4DeRTAKQappU%3D [4316383/4316383] -> \"grav-skeleton-blog-site-v1.0.1.zip\" [1]\nUnpacking... /home/ubuntu/workspace/blog-site/grav-skeleton-blog-site-v1.0.1.zip\nMerging... /home/ubuntu/workspace/blog-site/grav-skeleton-blog-site in /home/ubuntu/workspace/blog-site\n\nStart Apache by clicking the [Run Project] button in the toolbar\n\nInstallation Completed.\nSuccessfully installed grav@test\n```\n\nSo, everything seems in order. We can now publish our package.\n\n# Publish\n\nPublishing is done simply using the following command:\n\n```\nc9 publish patch\n```\n\nAdding the optional `patch` indicates that the cli should increment the final digit of the version by 1. You can use the `c9 list` command to check if the package is now available.\n\n```\n$ c9 list\nc9.ide.language.cpp  Cloud9 C/C++ language plugin\nactivecollab         ActiveCollab Integration for Cloud9\nmoz.xliff            XLIFF language tooling\ntresamigos.pumlc9    Puml viewer plugin\nsfdeploy             deploy to sf\nplugin.luarun        Lets you run lua in GMOD\ngrav                 Installs the Grav CMS - A Modern Flat-File CMS\nsnippets             Code snippets for C9 - Idea by Marshall Bean\n```\n\n# Install\n\nNow that the package is published anyone can install the package using `c9 install grav` to install the grav cms to their workspace.\n\n```\n$ c9 install grav\nInstalling Dependencies... [Done]\nSuccessfully installed grav@0.1.3\n```\n\n# Conclusion\n\nI hope that this short tutorial shows the power of using the installer to configure workspaces on a multitude of platforms. I hope you'll find this useful and I am looking forward to the packages you'll create.\n\nHappy Coding!","slug":"the-grav-installer","title":"Using the installer to configure a workspace"}

Using the installer to configure a workspace


The [Cloud9 Installer](doc:adding-an-installer) installs packages from various package managers into a workspace. The prime use case for the installer is to bundle an installation script with a plugin to install it's dependencies. For instance the collaboration feature of Cloud9 requires sqlite3 and [installs that](https://github.com/c9/c9.ide.collab/blob/master/install.js#L6) into an SSH workspace using the installer. A new use case that we recently discovered is using the installer to configure the workspace for frameworks, web servers, databases and other such packages that don't necessarily come with a plugin, but *simply want to configure the workspace.* Recently Cloud9 was [featured](http://getgrav.org/blog/cloud-ide-zero-to-code) on the blog of [grav](http://getgrav.org/) a php based CMS that works with flat files as its data source. In the blog article the writer outlined the steps needed to get the grav cms running in a Cloud9 workspace: ``` $ sudo apt-get update $ sudo apt-get install php5-curl $ sudo service apache2 restart # Enter Y when prompted to install the required packages. # Download and install the Grav Blog skeleton $ wget https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip $ unzip grav-skeleton-blog-site-v1.0.1.zip $ mv grav-skeleton-blog-site blog-site $ cd blog-site ``` These are all easy steps that fit very well within the domain of the Cloud9 Installer, and so this blog article will take you through the steps to create an installer that automates these steps. # Install.js The first thing we should do is create the install script which I'll store in a new directory. I call the file `install.js` and start with the basic skeleton: ``` define(function(require, exports, module) { module.exports = function(session, options){ session.start(); }; }); ``` Next we'll create a single package that will execute all the steps outlined above. ``` session.install({ "name": "Grav", "description": "A Modern Flat-File CMS" }, [ ]); ``` The package will break down in 3 tasks: - Installing the php5-curl package - Restarting apache - Downloading and unpacking the zip file Lets start with the php5-curl package. Because Cloud9 runs on any POSIX platform we'll create several options for installing the package to support a multitude of environments. ``` { "ubuntu": ["php5-curl"], "centos": ["php-curl"], "darwin": ["php-curl"] }, ``` Restarting apache is as simple as executing the restart command via `bash`. Because this command might not be available on all platforms I added some code to make sure it will never fail. ``` { "bash": "sudo service apache2 restart &> /dev/null || true" }, ``` And lastly the following task definition downloads and unpacks the zip file. ``` { "zip": { "url": "https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip", "target": "~/workspace/blog-site", "dir": "grav-skeleton-blog-site" } }, ``` This is all it takes. Check out the full implementation [here](https://github.com/c9/grav/blob/master/install.js). # Package.json Next up is the `package.json` file that will inform Cloud9 how to package and run the installer. Set the `installer` field to `install.js` and you're all set. ``` { "name": "grav", "description": "Installs the Grav CMS - A Modern Flat-File CMS.", "version": "0.1.0", "author": "Cloud9", "website": "http://getgrav.org", "contributors": [], "repository": { "type": "git", "url": "https://github.com/c9/grav.git" }, "plugins": {}, "installer": "install.js", "categories": [ "cms" ], "screenshots": [ "http://cdn.getgrav.org/user/pages/02.blog/cloud-ide-zero-to-code/cloud9-term.png?a75a9344" ], "licenses": [ "MIT" ] } ``` # Test Before publishing you'll want to test the package. The updated [Cloud9 CLI](doc:the-cloud9-cli) facilitates this. Run `c9 install .` while in your package root directory. ``` ~/grav$ c9 install . Installing Dependencies... [Done] Successfully installed grav@test ``` To see what it is actually doing add the `--verbose` flag. ``` ~/grav$ c9 install . --verbose Installing package locally Installation Started Package grav 1 -------------- Installing Grav Selecting previously unselected package php5-curl. (Reading database ... 127410 files and directories currently installed.) Preparing to unpack .../php5-curl_5.6.7+dfsg-1_amd64.deb ... Unpacking php5-curl (5.6.7+dfsg-1) ... Setting up php5-curl (5.6.7+dfsg-1) ... Downloading... https://github.com/getgrav/grav-skeleton-blog-site/releases/download/1.0.1/grav-skeleton-blog-site-v1.0.1.zip 2015-05-03 04:35:08 URL:https://s3.amazonaws.com/github-cloud/releases/22577202/4fe5e0a2-eaa8-11e4-8eeb-b67b00e8e705.zip?response-content-disposition=attachment%3B%20filename%3Dgrav-skeleton-blog-site-v1.0.1.zip&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1430627767&Signature=znV7k93mHXWQqFN4DeRTAKQappU%3D [4316383/4316383] -> "grav-skeleton-blog-site-v1.0.1.zip" [1] Unpacking... /home/ubuntu/workspace/blog-site/grav-skeleton-blog-site-v1.0.1.zip Merging... /home/ubuntu/workspace/blog-site/grav-skeleton-blog-site in /home/ubuntu/workspace/blog-site Start Apache by clicking the [Run Project] button in the toolbar Installation Completed. Successfully installed grav@test ``` So, everything seems in order. We can now publish our package. # Publish Publishing is done simply using the following command: ``` c9 publish patch ``` Adding the optional `patch` indicates that the cli should increment the final digit of the version by 1. You can use the `c9 list` command to check if the package is now available. ``` $ c9 list c9.ide.language.cpp Cloud9 C/C++ language plugin activecollab ActiveCollab Integration for Cloud9 moz.xliff XLIFF language tooling tresamigos.pumlc9 Puml viewer plugin sfdeploy deploy to sf plugin.luarun Lets you run lua in GMOD grav Installs the Grav CMS - A Modern Flat-File CMS snippets Code snippets for C9 - Idea by Marshall Bean ``` # Install Now that the package is published anyone can install the package using `c9 install grav` to install the grav cms to their workspace. ``` $ c9 install grav Installing Dependencies... [Done] Successfully installed grav@0.1.3 ``` # Conclusion I hope that this short tutorial shows the power of using the installer to configure workspaces on a multitude of platforms. I hope you'll find this useful and I am looking forward to the packages you'll create. Happy Coding!