Thursday, October 27, 2016

The Much Awaited Windows Dockerfile

I have been waiting for Windows containers with Docker ever since I started using Docker period.
What a joy it is, that now I might be able to manage Windows with the same grace and efficiency as Linux all of the sudden?

So here are my initial thoughts, and reactions.

First, there appears to be no support for cross-platform containers as of yet, so Windows containers need to run on WS2016WC or WS2016Nano with Containers support installed via PowerShell.

Very easy to get started once Docker is installed:

docker run microsoft/sample-dotnet
..which produces the following cute ASCIIArt:
  Welcome to .NET Core! __________________ \ \ .... ....' .... .......... .............'..'.. ................'..'..... .......'..........'..'..'.... ........'..........'..'..'..... .'....'..'..........'..'.......'. .'..................'... ...... . ......'......... ..... . ...... .. . .. ...... .... . ....... ...... ....... ............ ................ ...................... ........................'................ ......................'..'...... ....... .........................'..'..... ....... ........ ..'.............'..'.... .......... ..'..'... ...............'....... .......... ...'...... ...... .......... ...... ....... ........... ....... ........ ...... ....... '...'.'. '.'.'.' .... ....... .....'.. ..'..... .. .......... ..'........ ............ .............. ............. '.............. ...........'.. .'.'............ ............... .'.'............. .............'.. ..'..'........... ............... .'.............. ......... .............. .....

Pretty neat.

As cool as that is, I have specific application scopes I'd like to isolate, which is what Docker is really good for; separation of concerns, and codifying infrastructure as code.

So I create a nice simple Dockerfile that looks like this:
FROM microsoft/windowsservercore
ARG PATH
# Lets install Python 2.7
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://www.python.org/ftp/python/2.7.12/python-2.7.12.msi', 'c:\python-2.7.12.msi')
RUN msiexec /qn /i C:\python-2.7.12.msi
RUN del C:\python-2.7.12.msi
ENV Path C:\Python27;C:\Python27\Scripts;$PATH
ENV PYTHONPATH C:\Python27
ENV PYTHONIOENCODING utf-8
RUN assoc .py=Python.File
RUN ftype Python.File=C:\Python27\python.exe "%1" %*
At this point, we can create a new image from this Dockerfile with:
docker build --build-arg PATH=$env:Path -t my_image .
 And run it:
docker run -it my_image powershell
PS C:\
More to come as I go, have a great day.

Wednesday, October 12, 2016

Adding paths to the PYTHONPATH in a Jenkins Python Build Step

Append a path (Linux specific; use os.pathsep to make it OS agnostic) to $PATH.
I can never remember how to do this, so here is my little reminder.
import os,sys 
cwd=os.getcwd()+"/some_module_directory" 
sys.path+=[cwd]