How to automate a deploy in Apache?

Asked

Viewed 268 times

5

I have some systems based in Django that often need to be deployed (Deployed) on different servers. This involves, among other things, installing all the dependencies, downloading the project files, putting them in a standardized folder, etc., all of which can be done through a simple script.

However, a part of this process I have always done manually, since I don’t know a good way to automate/semi-automate:

  1. Make basic Apache configuration (if it’s your first installation as well);
  2. Create a virtual host for my application; in general it is just a file more or less with this format:

    <VirtualHost X.X.X.X:443>
        SSLEngine On
        ServerName <<nome do servidor>>
        ServerAlias <<nome alternativo>>
        ServerAdmin <<e-mail do administrador>>
    
        DocumentRoot /opt/<<pasta da aplicação>>
        Alias /media/ /opt/<<pasta da aplicação>>/media/
        Alias /static/ /opt/<<pasta da aplicação>>/static/
    
        WSGIDaemonProcess <<processo wsgi>> user=<<usuario>> group=<<grupo>> threads=1
        WSGIProcessGroup <<grupo wsgi>>
        WSGIScriptAlias / /opt/<<pasta da aplicação>>/aplicacao.wsgi
    </VirtualHost>
    

    to be placed in the sites-available linked to sites-enabled. This is the easiest: in the last case, I can generate the data file the desired parameters. But if there is a simpler way, better.

There are tools - from Apache itself or third parties (preferably open-source) - to simplify this configuration, without needing to edit the httpd.conf and its various referenced files? Or, if the answer is no, what is the best way to programmatically edit these files? Unlike popular formats like XML, JSON and YAML, I don’t know any reader/writer for their format.

P.S. I am assuming a Linux/Unix environment, and the programming language doesn’t matter (but if there is a solution in Python, so much the better).

  • I am going to jabá the company of a friend of mine who works with configuration only: https://configr.com/

1 answer

1

You can configure the entire server using the Fabric.

Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application Deployment or systems Administration tasks.

With it it is possible to create a file (fabfile.py) within your Django project, and in this file put the commands to connect to the server via SSH and perform all the necessary settings.

In this Apache case, it would be something like:

# -*- encoding:utf-8 -*-
from fabric.api import *
from fabric.colors import green, red, yellow

env.host_string = 'ip do seu servidor'
env.user = 'ubuntu'
env.key_filename = ''

def configurar_servidor():
    ...
    print(green(u'Instalando apache...'))
    ...
    print(green(u'Configurando...'))
    run('sudo cp /home/ubuntu/seuprojeto/config/apache/arquivo diretoriodoapache/sites-available/arquivo')
    ...

I just put an idea, after installing Fabric in the virtual environment of your project, locally you would enter the command to perform the tasks of this file. With it you can configure everything from scratch, from creating instances on Amazon, to downloading your git project, installing virtualenv, database, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.