December, 2018
18
Here’s the third article of this series dedicated to our new Marketplace. We introduced it a few weeks ago, and we added many frameworks for dev learning and quick prototyping.
So, in this last post, enjoy…
… custom scripts for editors, DevOps, and everyone!
Among the reasons we had to rebuild our marketplace, is the ability to create and distribute install scripts efficiently. What we had in mind was use-cases where you’re developing a Web service or application, and you need to deploy it regularly1) or you want to distribute it in a 1‑click install2).
To help you through this process, we built this new platform that powers our marketplace. As we said earlier, we now rely on simple scripts to provision a new instance. You choose your preferred language3), and we run it.
Specify your environment
Each script creates a new Sites type instance to host your app. You sometimes need to configure it a bit, especially regarding URL rewriting and all. To specify common settings, you must declare a YFM4) with the regarding options and values.
1 2 3 4 5 6 7 8 9 | #!/bin/bash # site: # type: php # path: '{INSTALL_PATH_RELATIVE}' # php_version: '7.2' # database: # type: mysql |
Here we declare a PHP site, stick to PHP 7.25), with a MySQL database. If you run the script right now, it will do nothing more than creating a new Sites and a MySQL database.
Then, clear the environment6), and execute your install process, like downloading the last release, extract it, install and configure stuff, etc.
1 2 3 4 5 | set -e # https://wp-cli.org wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
Collect user informations
You sometimes need to grab some user information, like the locale, admin password, and username, to preset the instance accurately.
You can declare a list of form fields you want the user to fill-in before provisioning the instance. Rely on the YMF part to add the fields definitions, with validation rules:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # form: # language: # type: choices # label: Language # initial: en_US # choices: # de_DE: German # en_US: English # es_ES: Spanish # fr_FR: French # it_IT: Italian # email: # type: email # label: Email # admin_username: # label: Administrator username # regex: ^[ a-zA-Z0-9.@_-]+$ # max_length: 255 # admin_password: # type: password # label: Administrator password # max_length: 255 |
That’s all! You can now use them in your script as they are sourced by the platform when running it:
1 2 3 4 5 6 7 8 9 10 | php wp-cli.phar core download \ --locale="$FORM_LANGUAGE" \ --path="$INSTALL_PATH" php wp-cli.phar core install \ --url="$INSTALL_URL" --admin_user="$FORM_ADMIN_USERNAME" \ --admin_password="$FORM_ADMIN_PASSWORD" \ --admin_email="$FORM_EMAIL" \ --path="$INSTALL_PATH" |
Distribute your code
If you write a script to install an open source software or your solution, why not to distribute it through our platform? That’s precisely why we built this new marketplace: for the community!
Just go to the add an application script view in your administration interface, fill in the form, and check the Public application checkbox. It registers your app for a review, and we’ll publish it quickly on the marketplace.
You’ve got a new way to increase the quality of the alwaysdata’s community, and we hope you will contribute by releasing scripts for your own solutions.
Take a look at the official documentation (it includes the whole script used in this blog post), and let us know which scripts you want to add!
Notes
↑1 | i.e., if you’re agency and this is your homemade solution |
---|---|
↑2 | i.e., you’re editing an open source software and want it available to everyone easily |
↑3 | from Bash to Python or Ruby |
↑4 | which is a simple YAML dataset in comments |
↑5 | it automatically takes the last minor release of the 7.2 branch |
↑6 | always better to avoid conditions |
no comments