Skip to content

Instantly share code, notes, and snippets.

@erikvw
Last active March 24, 2024 20:04
Show Gist options
  • Save erikvw/397eee3e446f759f07f97d34d1101af9 to your computer and use it in GitHub Desktop.
Save erikvw/397eee3e446f759f07f97d34d1101af9 to your computer and use it in GitHub Desktop.
Multipass on Apple M1: Python 3.12 venv
# Running multipass on a mac (M1)
# minconda won't work since the conda does not support a linux os on M1
# use pyenv to get the python version need (3.12 here)
# use python venv to creat a virtual environment
# install pyenv
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec "$SHELL"
# select python version using pyenv
pyenv install 3.12.2
pyenv global 3.12.2
# create and activate a virtual environment with python venv
python -m venv edc
source ~/venv/edc/activate
# setup an edc
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config libcups2-dev
git clone https://github.com/meta-trial/meta-edc.git app # for example
cd app
pip install -U .
# your machine running multipass is the `host` and on it you are running a `multipass instance`
# create some entries on the `host` in the host file
# assuming the IP of your `multipass instance` is 192.168.65.5 (replace with what you have)
# /etc/hosts
192.168.65.5 meta3.multipass.org
192.168.65.5 amana.uat.tz.meta3.multipass.org
192.168.65.5 hindu_mandal.uat.tz.meta3.multipass.org
192.168.65.5 temeke.uat.tz.meta3.multipass.org
# on a mac
# sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
ping meta3.multipass.org
PING meta3.multipass.org (192.168.65.5): 56 data bytes
64 bytes from 192.168.65.5: icmp_seq=0 ttl=64 time=16.810 ms
...
# create a uat account
ssh [email protected]
ubuntu@primary:~$ adduser uat
ubuntu@primary:~$ usermod -aG sudo uat
ubuntu@primary:~$ su - uat
uat@primary:~$ mkdir .ssh
uat@primary:~$ exit
ubuntu@primary:~$ exit
# get you key onto uat account authorized keys
# transfer a file from the `host` to multipass using `multipass transfer`
~/ multipass transfer ~/.ssh/id_rsa.pub primary:
# you can do the rest ....
# this should work now
ssh [email protected]
# this should also work
ssh [email protected]
uat@primary:~$ ping 192.168.86.155
PING 192.168.86.155 (192.168.86.155) 56(84) bytes of data.
64 bytes from 192.168.86.155: icmp_seq=1 ttl=64 time=1.40 ms
...
# MYSQL
# you will point your multipass instance (primary) to the host mysql server (your machine)
# setup mysql assume user is uat with uat1234@UAT
# on multipass host mysql (your machine)
CREATE USER 'uat'@'meta3.multipass.org' identified by 'uat1234@UAT'; flush privileges;
GRANT ALL PRIVILEGES ON meta3_uat.* to 'uat'@'mutlipass.primary';
# open the host firewall to accept connections from 192.168.65.5:3306
# if you want to check access mysql from the CLI on the multipass instance
# this is not necessay for the edc connection below
# install mysql client
sudo apt install mysql-client-core-8.0
# create a .my.cnf
# .my.cnf
[client]
user=uat
password=uat1234@UAT
default-character-set=utf8
host=192.168.86.155
port=3306
uat@primary:~$ mysql
uat@primary:~$ mysql>
# edc folders and keys
mkdir ~/log
touch ~/log/edc.log
mkdir -p ~/.etc/meta/crypto_fields
# if this is a test of a real uat, get the encryption keys
# that match the DB you are accessing
# copy them to the instance
# navigate to the key folder
multipass transfer user-* primary:
# log in and move files to uat account
ssh [email protected]
ubuntu@primary: sudo mv user-* /home/uat/.etc/meta/crypto_fields
# try running python manage.py check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment