Tuesday, September 8, 2015
Wednesday, August 19, 2015
Friday, December 19, 2014
The IntroGood ole Docker. It is a powerful tool to setup your environments whether in production, dev or test. Plowing through and building a new container I discovered I had the need or want to pass an argument to the Dockerfile and let it log me into a private repo.
The Environment Variable.Looking through the Dockerfile documentation on
the docker.io website I saw this wonderful looking thing called an environment variable. When I first looked at it I thought that meant that we could pass them in from the host cli running the docker command. I was dead wrong. The environment variable does create a variable but its only for the container's environment. So what does that mean for us. Well if you think about the reason for Docker is for an unattended setup of an environment. Now if I were going to do this completely automated then I would probably create a ssh key and copy it over using Dockerfile. This is not what I wanted. I really wanted a seperation where I didn't store my password or ssh key within the environment. Below is my crude way of getting around this.
The GemfileThe Gemfile in this instance is very simple. You really could skip using highline all together, however I thought it would be cool to mask the password as you type.
The Ruby script will ask you for a password. Once input it will open the "dock_temp" file within the directory. Then we do a simple replacement of the $PASS variable to be the actual password that was input by the user. Once that is complete we write it to a file called Dockerfile.
The Docker file is the file used when you run "docker build". The Ruby script then makes a system call and it will build your environment. Lastly we want to get rid of the password just laying around so we delete the Dockerfile
The Temp DockerfileThe Dockerfile template is very simple. It grabs a copy of ubuntu, updates the repo, installs git. At this point all you have to do is run the git clone and you have you code