Monday, August 31, 2020

Pyenv Commands Quick Reference

 Recently, I've been spending more time learning Python as it's the core language used in the framework that we'll be building on. Similar to using docker to containerize apps or vm's to isolate the app env from messing up the local m/c, python provide's various options to isolate the development environment. One such tool is pyenv. It's such an effective tool that makes life much easier, especially when you're working with multiple python projects that may require different dependencies and different versions of one or more python modules. 

Here, I've listed out most of the pyenv commands I used to work around different projects in my development env: 


- To list versions that match a pattern

$ pyenv install --list | grep " 3\.[678]"


- To install a specific version

$ pyenv install 3.8.2


- To uninstall a specific version

$ pyenv uninstall 3.8.2


- Installation Location

$ ls ~/.pyenv/versions


- To list all available python versions

$ pyenv versions


- To list all pyenv commands

$ pyenv commands


- To set a python version globally

$ pyenv global 3.8.2


- To set a python version locally

$ pyenv local 3.8.2


- To set a python version current shell

$ pyenv shell 3.8.2


- Creating virtual environments

$ pyenv virtualenv 3.8.2 <env_name>


- Activating pyenv env (if necessary)

$ pyenv activate <env_name>

$ pyenv deactivate


Monday, March 9, 2020

Running Jenkins docker image with local file system mapped

Step 1: Pull down the Jenkins Docker Image from DockerHub: 


       docker pull jenkins/jenkins:latest

Note: You'll get the latest Jenkins image from jenkins/jenkins tag and not the official jenkins repo. Official one at the time when I downloaded was still referring to 2.60.3 version, whereas the jenkins/jenkins one was using 2.224. If you use the older version, certain plugins may not load properly.

Step 2: Create a local volume


       docker volume create jenkins-data

Step 3: Run Jenkins docker image with this local volume mapped to the jenkin container's path. 


      docker run --name jenkins \
           --d \
           -p 49001:8080 \
           -v jenkins-data:/var/jenkins_home \
           jenkins/jenkins:latest

Note: If you run into the following error:

/usr/local/bin/jenkins.sh: line 25: /var/jenkins_home/copy_reference_file.log: Permission denied

You will then need to give the correct permissions to the local directory which will be mapped to the containers path.

      sudo chown 1000 jenkins-data

Finally, when the container starts, you can access Jenkins Home by going to http://localhost:49001
When you access it for the first time, it'll ask for the admin password to be entered, which can be found from the logs or from $JENKINS_HOME/secrets/initialAdminPassword file.

      docker exec jenkins bash -c 'cat $JENKINS_HOME/secrets/initialAdminPassword'