Task:
Set-up a Rocky Linux utility workstation w/a venv and Git authentication.
Optionally, install django, or ansible and vsphere integration, for example.
Note:
If running Ubuntu, use apt-get install. The package names will be the same or similar.
If running CentOS Stream, the installation should be identical.
Steps:
1. Login to the host/VM:
Sudo or pbrun bash to install software:
$ sudo <command> -
or
$ pbrun bash
2. Install/update python:
$ sudo dnf install python3-pip python3-wheel python3-setuptools
<review, and y to proceed>
If you wish a global pip3 being installed:
$ sudo python -m pip install --upgrade pip
<review, and y to proceed>
3. Install the Github CLI:
$ sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
<review, and y to proceed>
$ sudo dnf install gh
<review, and y to proceed>
Note: If dnf returns that the config-manager is not installed, install with the command below, and then repeat the commands above.
$ sudo dnf install 'dnf-command(config-manager)'
4. Create the virtual environment/venv:
It is recommended to use a virtual environment for portability and pseudo-isolation. Each venv allows a different versions of packages to be tested and used w/in each venv. Each venv can have different users owning the venv and allow them to install packages w/in the venv that are not global.
$ sudo su
# cd /opt/
# python -m venv .GitScripts_venv
Install pip packages needed:
# cd .GitScripts_venv/
# source ./bin/activate
(.GitScripts_venv) # ./bin pip install --upgrade pip
(.GitScripts_venv) # ./bin pip install wheel
(.GitScripts_venv) # ./bin pip install requests
(.GitScripts_venv) # ./bin pip install psutils
. . .
(.GitScripts_venv) # deactivate
Update venv permissions for other users to use venv:
# pwd
/opt/.GitScripts_venv
# chmod o+x ./bin
# chmod o+rx ./include
# chmod o+rx ./lib
# chmod o+r ./pip-selfcheck.json
# chmod o+r ./pyvenv.cfg
Exit root:
# exit
Activate the venv and make the script folder in the current user home folder:
$ cd /opt/.GitScripts_venv/
$ source ./bin/activate
$ cd ~
$ pwd
/home/users/myadminid
$ mkdir -p ~/git/github.mindwatering.net/mwscripts
$ cd ~/git/github.mindwatering.net/mwscripts
$ pwd
/home/users/myadminid/git/github.mindwatering.net/mwscripts/
5. Configure Git:
If you have not create a Git app token yet:
Git site --> Profile (top right corner) -> Settings (bottom of dropdown list)
On the Settings page --> Developer settings (bottom left link) --> Personal access tokens
On the Personal access tokens page --> Click Generate new token
Notes:
Ensure that you have the appropriate repo modification role.
Ensure that you have the org read:org role, or the login won't work.
Warning:
Once you generate a token, it won't show the token to you again. Make sure you keep it in a safe place. If you loose the token, you'll have to delete the current and create a new one.
Create a token file in your personal home folder, and limit who can see it (just the myadminid user)
$ cd ~
$ pwd
/home/users/myadminid
$ touch .gittoken
$ vi .gittoken
<i>, to insert text
<paste in the token>
<:wq>, to save
Remove the group read/read-write rights:
$ chmod g-rw .gittoken
Login:
$ gh auth login --hostname github.mindwatering.net --with-token < .gittoken
If successful, nothing is printed out. If an error, the reason will be displayed. We can add the token to the environmental git file.
Configuration Notes:
git stores in ~/.gitconfig
gh stores in ~/.config/gh in two files: config.yml and hosts.yml
In both cases they have a config command for populating so that manual editing doesn't have to occur.
Setup git global name/email git config:
$ git config --global user.name = "myadminid"
$ git config --global user.email = "myadminid@mindwatering.net"
$ git config --global github.user = "myadminid"
Setup any gh configs:
$ gh config set <variable>...
To store LOCALLY on the file system, the git username and token:
$ git config --global credential.helper store
Notes:
The credentials are stored in ~/.git-credentials. Make sure only the current user can see this file.
After this command, the next command (e.g. git pull) will prompt from the username and password, but afterwards, use the stored credentials.
$ cd ~/git/github.mindwatering.net/mwscripts
$ pwd
/home/users/myadminid/git/github.mindwatering.net/mwscripts/
$ git pull
6. Post Options:
Additional Packages/Software:
- Ansible and/or vSphere packages for an "utility server" can be added. See "Ansible vSphere Set-up Notes" for more information.
- Django
If installing Django:
Option 1 - Use pip:
Activate the venv if not already activated:
$ cd /opt/.GitScripts_venv/
$ source ./bin/activate
In the venv, install Django:
(.GitScripts_venv) # ./bin pip install --upgrade pip
(.GitScripts_venv) # ./bin pip install Django
Alternately:
$ python -m pip install Django
Note:
The -m indicates the module to call/use (pip) that will perform the verb (install) and target object (Django).
Option 2 - Use Git
To Install via Git:
$ cd /home/myadminid/
$ mkdir djangoclone
$ cd djangoclone
$ pwd
/home/myadmin/djangoclone
$ git clone https://github.com/YourGitHubName/django.git
$ cd /opt/.GitScripts_venv/
(.GitScripts_venv) # python -m pip install -e /home/myadminid/djangoclone/django/
Confirm installed okay:
(.GitScripts_venv) # python -m django --version
- or -
(.GitScripts_venv) # python
>>> import django
>>> print(django.get.version())
6.x
previous page
|