A bash
script to create and manage development environments using privileged LXC linux containers.
- LXC >= 2.1
- Network bridge called
lxcbr0
Notes:
- devenv has been also tested with LXC version 2.0.7 with Debian Stretch. In order to work, one needs to adapt the network configuration using the old keys.
- In Ubuntu and Debian lxc gets installed along a systemd unit called
lxc-net
, configurable at/etc/default/lxc-net
.
See the Debian lxc how-to for both requirements.
Run make install
with root privileges to install the script in your system.
It will copy the executable script to /usr/sbin/devenv
and its config to /etc/devenv
If you are keeping a copy of this repo, do: git pull && sudo make install
.
If you have deleted, clone again this repo and then do sudo make install
.
Run make uninstall
with root privileges to remove both the config and executable from your system.
Beware that if you have substituted any of those files by anything else, they will be removed regardless.
Please give a look at Filesystem Hierarchy.
To run the devenv
script you need to create a .devenv
configuration file in your project directory. You can run the init
command to generate it containing the following variables:
# <PROJECT_PATH>/.devenv file
NAME="<container name>"
DISTRIBUTION="<SO distribution>"
RELEASE="<SO release>"
ARCH="<SO arch>"
HOST="local.$NAME.coop"
# Optional -- To create a new user and group
DEVENV_USER="<user that will own the project>"
DEVENV_GROUP="<group that will own the project>"
# Optional -- To mount a project.
# Make sure that the directory "../$PROJECT_NAME" exists
# in the host machine before executing this script.
PROJECT_NAME="<project name>"
PROJECT_PATH="${PWD%/*}/$PROJECT_NAME"
BASE_PATH="<base project path>"
PROJECT_POST_PATH="<post project path>"
# Select the python interpeter python2.7 or python3
PYTHON_INTERPRETER=python3
Then run devenv
in your project directory.
The script will:
- Create a container
- Mount your project directory into container in
/<BASE_PATH>/<PROJECT_NAME>/<PROJECT_POST_PATH>
- Add container IP to
/etc/hosts
- Create a group with same
gid
of project directory and named$DEVENV_GROUP
ifDEVENV_GROUP
andDEVENV_USER
are defined. - Create a user with same
uid
andgid
of project directory and named$DEVENV_USER
ifDEVENV_GROUP
andDEVENV_USER
are defined. - Add system user's SSH public key to user
- Install python in container
When the execution ends, you'll have a container ready to provision and deploy your project.