softasap.sa-container-bootstrap
sa-container-bootstrap
This is a helper tool that you can use with ansible-container or Hashicorp's packer to set up a guest operating system for creating better images. The Ubuntu section is inspired by Phusion BaseImage. Please check the original license for more information.
Third Party Resources Used
| Distribution | BASE IMAGE | SSHD | CRON | syslog ng |
|---|---|---|---|---|
| Alpine 3.4 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry: |
| Alpine 3.5 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry: |
| Alpine 3.6 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry: |
| Alpine 3.7 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry: |
| debian-jessie | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| debian-stretch | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| ubuntu-xenial | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Configuration Variables
You can set up this role with the following options:
# GENERAL CONFIGURATION
# Choose the init system you want
container_init: "phusion-init" # Alternatives: "dumb-init", "tini-init"
container_svc: "runit" # You can also use "supervisord"
# Directory for executable files to run at startup
container_init_directory: /etc/my_init.d
# Extra services to install in the container
option_container_cron: true
option_container_sshd: true
option_container_sshd_enabled: true
# SSH key pair for connecting to the instance
container_ssh_private_key: "{{role_dir}}/files/keys/insecure_key"
container_ssh_public_key: "{{role_dir}}/files/keys/insecure_key.pub"
option_container_syslog_ng: true
# Python interpreter location for phusion-init
container_python_interpeter: "/usr/bin/python3"
# dumb-init version
dumb_init_version: "1.2.0"
Service Management
This container uses runit, which functions similarly to traditional init systems. It's designed to work on most services commonly used in base Docker images.
Starting Services with Runit
To start a service, create a .runit file under /etc/service/SERVICE_NAME/run. Here are a few examples:
#!/bin/sh
set -e
. /etc/memcached.conf
exec chpst -u memcache /usr/bin/memcached $MEMCACHED_OPTS >>/var/log/memcached.log 2>&1
#!/bin/bash
set -e
exec nginx -c /etc/nginx/nginx.conf
#!/bin/sh
set -e
RUNDIR=/var/run/redis
PIDFILE=$RUNDIR/redis.pid
mkdir -p $RUNDIR
touch $PIDFILE
chown redis:redis $RUNDIR $PIDFILE
chmod 755 $RUNDIR
exec chpst -u redis /usr/bin/redis-server /etc/redis/redis.conf
Running Processes at Startup
To run scripts at startup, place them under the container_init_directory (default is /etc/my_init.d). If you choose not to install runit, this is the main way to execute commands on boot.
Setting Environment Variables
You can add environment files to /etc/container_environment, naming the files after the variables you want to set (e.g., ENVVARNAME) with the value of the variable inside the file.
Initialization Options
This role supports three types of initialization: phusion-init, dumb-init, and supervisor-init. While phusion-init works like the Phusion docker image, dumb-init and supervisor-init are simpler and heavier options, respectively.
- dumb-init: A lightweight init system. Learn more here.
- supervisor-init: A more resource-heavy init system, often used with Python applications.
Example Code
Check out the box-example for a working setup. It will configure an application image that responds with 'OK' on connection:
For more troubleshooting tips related to ansible container, visit this link.
License Information
The code is available under both the BSD 3 Clause and the MIT License. Choose the license that best fits your needs.
Connect With Us
- Get updates about roles on our Facebook page.
- Join our discussion channel on Gitter.
- Explore more roles at SoftAsap.
- Visit our blog at SoftAsap Blog.
Experimental "base image" role for ansible-container based projects. Phusion base image inspired.
ansible-galaxy install softasap.sa-container-bootstrap
