softasap.sa-nginx-container

sa-nginx-container

Build Status License: MIT Ansible-Container friendly

This is a helper role you can use with ansible-container to build a service based on nginx for your application. The role is built on the sa-nginx role, and your Docker image can be based on Ubuntu (14.04 LTS / 16.04 LTS), CentOS 7+, Fedora 25+, or Alpine (3.4, 3.5+).

It's best to use this role along with the prior role called sa-container-bootstrap. Please check sa-container-bootstrap for more options.

You can also use this role on its own. It comes with support for dumb-init right away.

Variables

User within the container for running processes.

container_user: nginx

User ID for the nginx user in the container.

container_uid: 1000

The init system used in your base image. It can be left empty if you are controlling it yourself.

container_init: "dumb-init" # phusion-init

dumb_init_version: "1.2.0"

Directory for the nginx process ID (pid) file.

nginx_pid_dir: /run/nginx

Compatibility with other containers - where to store static files and which directories need to be copied inside the container.

nginx_static_dir: /static

# Directories to copy inside the Docker container
nginx_asset_dirs: []

# Directories already mapped inside the Docker container during build
nginx_container_asset_dirs: []

If you don't provide your own nginx configuration, the container will use the default sa-nginx setup. Site configurations will be placed in /etc/nginx/sites-enabled, and you can adjust the default nginx.conf by specifying modifications in nginx_conf_properties.

Example modifications:

nginx_conf_properties:
  - {
      regexp: "^daemon *",
      line: "daemon off;",
      insertbefore: "BOF"
    }
  - {
      regexp: "^worker_processes *",
      line: "worker_processes auto;",
      insertbefore: "BOF"
    }
  - {
      regexp: "^pid *",
      line: "pid {{nginx_pid_dir}}/nginx.pid;",
      insertbefore: "BOF"
    }

Code in action

container.yml

Here, we install the nginx container role and configure our application with a specific role related to our project for nginx optimization.

version: "2"
settings:
  conductor_base: ubuntu:16.04
  volumes:
   - temp-space:/tmp  # Used for static content sharing between containers

services:
   www:
     from: ubuntu:16.04
     container_name: www
     roles:
       - {
           role: "softasap.sa-nginx-container"
         }
       - {
           role: "../standalone-fallback"
         }

volumes:
  temp-space:
    docker: {}

Check the box-example for a working standalone instance. It will show 'OK' when you connect - take a look:

Usage with sa-container-bootstrap

Temporary hints

(1)

Currently, ansible-container is still being developed. You might find some bugs that are only fixed in the development branch. In this case, you may need to install ansible-container from the source like this:

git clone https://github.com/ansible/ansible-container.git
cd ansible-container
git checkout develop
pip install -e .[docker,openshift]

If the installation is not working properly due to updates or removals, use pip with --ignore-installed.

Later, when a fix is released, to uninstall the package that was installed from source: Go to {virtualenv}/lib/python2.7/site-packages/ (or {system_dir, like /usr/local}/lib/python2.7/dist-packages/ if not using virtualenv) and remove the egg file (like ansible-container.egg-link) if it exists; then edit the easy-install.pth file to remove the corresponding line.

(2)

When using the box-example, pay special attention to container.yml. Ensure that conductor_base is from the same OS distribution as the one you're building the target containers with. Check the list of currently supported base systems.

(3)

If your system services come from different OS base images, check for compatibility issues.

The code is licensed under the BSD 3 clause or the MIT License.

Stay updated on roles by following us on Facebook.

Join the discussion on Gitter at Gitter.

Informazioni sul progetto

Experimental nginx container

Installa
ansible-galaxy install softasap.sa-nginx-container
Licenza
Unknown
Download
92
Proprietario
Get your application deployed in a robust way