Python Machine

Introduction

As part of my goal of improving my knowledge and skills in data science and machine learning I require a python development machine; where I can complete learning assignments and projects. To leverage the power of my home server I will be deploying this into a LXC container using Proxmox. The container will be deployed as a stateless service. This means that python and any installed dependencies are separated from the data; for example, python or configuration files. This is a similar concept to other container software, such as docker.

To set this up I will create an Alpine Linux LXC container and install the required base packages. Using snapshot functionality it is then possible to take a snapshot of this initial setup and then rollback to this as required. To provide data persistence Git will be used to push any data that needs to be stored to a Git server.

Setting up the container

Setting up containers is made easy by the Proxmox web GUI. LXC templates can be downloaded by selecting an appropriate storage from the view panel and clicking on Templates. I will be using the alpine-3.11-default template. Then by clicking on Create CT in the top right of the web GUI a series of dialog boxes guides the container setup.

I configured the container to:

  • be unprivileged (increases security)
  • use the above Alpine Linux template
  • have these resources (see note below)
    • 4 core cpu
    • 4 gb ram
    • 10 gb root disk


Note: A benefit of using containers is that the resources the container is using, e.g. cpu cores/ ram, can be changed whilst it is running. Allowing easy up-resourcing when a more intensive task is required to run.

Setting up the base system

The container’s root terminal can be accessed either by the Proxmox web GUI (console tab) or by accessing the Proxmox machine’s terminal and entering:

# pct enter <vmid>

Once at the container’s terminal the repositories are updated and the packages upgraded with:

# apk update
# apk upgrade

User Management

First create a new user:

# adduser <user>

Install sudo and grant sudo access to the user:

# apk add sudo
# addgroup sudo
# addgroup <user> sudo

Use visudo to allow sudo group members access to sudo:

# visudo

# visudo

... ## Uncomment to allow members of group sudo to execute any command %sudo ALL=(ALL) ALL ...

Now login into the machine using the newly created user.

Adding SSH

To provide SSH access to the machine. Install openssh and set it to start a boot:

$ sudo apk add openssh
$ sudo service sshd start
$ sudo rc-update add sshd default

Adding Git

To provide data persistence Git will be used. Install with:

$ sudo apk add git

I access my Git server with ssh keys. These can be generated with:

$ ssh-keygen -t ed25519 -C "[email protected]"

Then copy the generated public key’s content (by default found at ~/.ssh/id_ed25519.pub) to the Git server’s allowed ssh keys.

Update the Git global username and email with:

$ git config --global user.name "user"
$ git config --global user.email "[email protected]"

Python

Install python3 with:

$ sudo apk add python3

Any other required python dependencies or tools will be installed after the base snapshot. Rolling back to the base snapshot will returned to a ‘clean’ python install.

Taking a snapshot

A snapshot can be created either from the Proxmox web GUI (Snapshots tab) or on the Proxmox machine’s terminal using:

# pct snapshot <vmid> <snapname>

Conclusion

At any point we can now rollback the container to the base install we have just set up. Any data requiring persistence can be pushed and pulled from the Git server as required. Now onto python development…


June 2020