Skip to content

Commit

Permalink
develop
Browse files Browse the repository at this point in the history
- Prepare v1.0.
- Clean up code.
- Improve docs.
  • Loading branch information
saint-hilaire committed May 1, 2024
1 parent 27b8e89 commit b72bbf8
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 378 deletions.
92 changes: 36 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

## About

Lampsible - LAMP stacks with Ansible and a super simple CLI. You can use this tool to set up a
LAMP stack with Ansible. That is, on a given Linux server, install Apache, MySQL, PHP,
and some web application of your choice. Under the hood, it utilizes Ansible, a
powerful server automation tool, but you don't have to worry about writing
Ansible Playbooks or configuring inventories and hosts, because Lampsible
does all of that for you. You just use the CLI to tell Lampsible where your server is,
what you want to install on it, and Lampsible does everything for you.
Lampsible - LAMP stacks with Ansible and a super simple CLI. This tool can automate anything from
a production ready WordPress site on your VPS to a custom Apache setup on a virtual machine
in your local network.
.

## Installing

Expand All @@ -21,73 +18,56 @@ cd lampsible
python3 -m pip install .
```

You can also run the Python code directly, but this option is geared more towards
developers (also, it's not really necessary, because you can install from source
and pass the `--editable` flag): `python3 src/lampsible/lampsible.py --help`

## Sample usage

## Usage
Lampsible is designed to be very simple to use. If you forget some important
parameter, Lampsible will prompt you for it, or pick some sensible defaults.

General usage looks like this:

Install Apache on your server:

```
lampsible REMOTE_USER REMOTE_HOST DESIRED_ACTION [OPTIONAL_FLAGS]
lampsible someuser@somehost.com apache
```

Currently supported actions are:

* `lamp-stack`
* `apache`
* `mysql`
* `php`
* `wordpress`
* `dump-ansible-facts`

Some flags which you'll likely also want to use:

* `--apache-vhost-name`
* `--database-username`
* `--php-version` (You'll need this on older Ubuntu versions, because they don't support PHP 8 out of the box)
* `--wordpress-version`
* `--ssl-certbot`
* `--ssl-selfsigned`

Run `lampsible --help` for a full list of options.

### Sample usage
Install a production ready WordPress site:

```
lampsible sampleuser your.server.com lamp-stack \
--apache-vhost-name my-site \
--apache-document-root /var/www/html/my-site/public \
--database-username dbuser \
--database-name my_database
lampsible someuser@somehost.com wordpress \
--ssl-certbot \
--email-for-ssl you@yourdomain.com
```
(This installs Apache, MySQL and PHP. Because a database user and name are provided,
they are created as well - otherwise they won't be created. You don't need to enter a database
password, as it's generally insecure to do so over the CLI. Lampsible will prompt you for a password.)

<br>
Install a Laravel app on a test server:

```
lampsible sampleuser your.server.com wordpress \
lampsible someuser@somehost.com laravel \
--ssl-certbot \
--email-for-ssl you@yourdomain.com
--test-cert \
--apache-server-admin you@yourdomain.com \
--app-name cool-laravel-app \
--app-build-path /path/to/your/local/cool-laravel-app-0.7rc.tar.gz \
--laravel-artisan-commands key:generate,migrate
```
(Along with the underlying LAMP stack, this installs WordPress on your server,
and also sets up SSL via Certbot. You don't have to provide any database
or Apache configurations - they will either be generated automatically,
or you will be prompted to enter them.)

Set up a LAMP with various custom configuration and a self signed SSL certificate on some local VM:

**WARNING!** Never set up a WordPress site without immediately navigating to that site
in your browser and finishing the "famous 5 minute WordPress installation",
in which you enter the credentials for the admin user!
Otherwise, someone else will do that for you, and use your server to host malicious content!
```
lampsible someuser@192.168.123.123 lamp-stack \
--ask-remote-sudo \
--ssl-selfsigned \
--database-username dbuser \
--database-name testdb \
--php-version 8.1 \
--apache-vhost-name some-legacy-app \
--apache-document-root /var/www/html/some-legacy-app/some-dir/public \
--php-extensions mysql,xml,mbstring,xdebug,gd
```

## Contributing

This tool is very much still in beta stage. If you want to help me improve this,
I'll be very happy, just shoot me a message :-)
Run `lampsible --help` for a full list of options.

## Contributing

PLease do! I'd be more than happy to see Issues, Pull Requests and any other kind of feedback ;-)
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "lampsible"
version = "0.12.0dev"
version = "1.0.0"
authors = [
{name="Brian St. Hilaire", email="brian.st-hilaire@sanctus-tech.com"}
]
Expand All @@ -32,14 +32,12 @@ classifiers = [
]

[project.scripts]
# TODO: Improve this.
lampsible = "lampsible:lampsible.main"

[project.urls]
Homepage = "https://github.com/saint-hilaire/lampsible"
Issues = "https://github.com/saint-hilaire/lampsible/issues"

# TODO: It may be possible without the following 2 tables.
[tool.setuptools.packages.find]
where = ["src"]

Expand Down
2 changes: 1 addition & 1 deletion src/lampsible/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.12.0dev'
__version__ = '1.0.0'
16 changes: 3 additions & 13 deletions src/lampsible/arg_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ def get_apache_document_root(self):
return self.apache_document_root


# TODO: I don't find this very elegant.
def get_apache_custom_conf_name(self):
try:
return self.apache_custom_conf_name
except AttributeError:
return ''


# TODO: Improve/remove this when we fix Certbot.
def get_wordpress_url(self):
try:
return self.wordpress_url
Expand Down Expand Up @@ -108,7 +106,7 @@ def get_extravars_dict(self):
'apache_custom_conf_name': self.get_apache_custom_conf_name(),
'database_username': self.args.database_username,
'database_password': self.args.database_password,
'database_host': self.args.database_host,
'database_host': DEFAULT_DATABASE_HOST,
'database_name': self.args.database_name,
'database_table_prefix': self.args.database_table_prefix,
'php_version': self.args.php_version,
Expand Down Expand Up @@ -249,11 +247,11 @@ def get_pass_and_check(self, prompt, min_length=0, confirm=False):


def validate_ansible_runner_args(self):
user_at_host = self.args.user_at_host.split('@')
try:
user_at_host = self.args.user_at_host.split('@')
self.web_host_user = user_at_host[0]
self.web_host = user_at_host[1]
except IndexError:
except (IndexError, AttributeError):
print('FATAL! First positional argument must be in the format of \'user@host\'')
return 1

Expand Down Expand Up @@ -309,14 +307,6 @@ def validate_apache_args(self):

def validate_database_args(self):

# TODO: Sanity check database username and database name.

if self.args.database_engine != DEFAULT_DATABASE_ENGINE \
or self.args.database_host != DEFAULT_DATABASE_HOST \
or self.args.php_my_admin:

raise NotImplementedError()

if self.args.database_password \
and not self.args.insecure_cli_password:

Expand Down
41 changes: 19 additions & 22 deletions src/lampsible/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from . import __version__

# LAMPSIBLE
# Lampsible
# ---------
LAMPSIBLE_BANNER = """\
_ _ _ _
| | (_) | | |
Expand All @@ -23,58 +24,54 @@
'php',
# PHP CMS
'wordpress',
'typo3', # TODO
'joomla', # TODO
'drupal', # TODO
# PHP frameworks
'laravel', # TODO
'symfony', # TODO
'zend', # TODO
'laravel',
# Local debugging
'dump-ansible-facts',
# Non-PHP frameworks. Should we even support these?
'django', # TODO
'rails', # TODO
'springboot', # TODO
# Misc. PHP
'magento', # TODO
'woocommerce', # TODO
'composer', # TODO
'xdebug', # TODO
]

# SCRIPT PATHS
# Script paths
# ------------
USER_HOME_DIR = os.path.expanduser('~')
DEFAULT_PRIVATE_DATA_DIR = os.path.join(USER_HOME_DIR, '.lampsible')
# If the user does not supply a value, this will be overwritten by a path
# inside the package installation, which we detect later on.
DEFAULT_PROJECT_DIR = ''

# APACHE
# Apache
# ------
DEFAULT_APACHE_VHOST_NAME = '000-default'
DEFAULT_APACHE_SERVER_NAME = 'localhost'
DEFAULT_APACHE_SERVER_ADMIN = 'webmaster@localhost'
DEFAULT_APACHE_DOCUMENT_ROOT = '/var/www/html'

# DATABASE
# Database
# --------
DEFAULT_DATABASE_ENGINE = 'mysql'
DEFAULT_DATABASE_USERNAME = 'db-username'
DEFAULT_DATABASE_HOST = 'localhost'
DEFAULT_DATABASE_TABLE_PREFIX = ''

# WORDPRESS
# PHP
# ---
DEFAULT_PHP_VERSION = '8.2'

# WordPress
# ---------
DEFAULT_WORDPRESS_VERSION = 'latest'
DEFAULT_WORDPRESS_LOCALE = 'en_US'
DEFAULT_WORDPRESS_SITE_TITLE = 'Sample Site'
DEFAULT_WORDPRESS_ADMIN_USERNAME = 'admin'
DEFAULT_WORDPRESS_ADMIN_EMAIL = 'admin@example.com'

# WEB APPLICATIONS
# Web applications
# ----------------
DEFAULT_LARAVEL_ARTISAN_COMMANDS = [
'key:generate',
'migrate',
'db:seed',
]

# MISC
# Misc
# ----
INSECURE_CLI_PASS_WARNING = 'It\'s insecure to pass passwords via CLI args! If you are sure that you want to do this, rerun this command with the --insecure-cli-password flag.'
Loading

0 comments on commit b72bbf8

Please sign in to comment.