Skip to main content

Crude Ruby Script to ask for a Password to use for Private git Repo

The Intro

Good 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 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 Gemfile 

source ''
gem 'highline'
The 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

require 'highline/import'

pass = ask("Enter your Password : "){ |q| q.echo = "*" }
file ="dock_temp", "r")
text =
out ="Dockerfile", "w")
out.puts text.gsub("$PASS", pass)

`docker build -t yourtag .`
`rm Dockerfile`

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 Dockerfile

FROM ubuntu:14.10
RUN apt-get update
RUN apt-get install -y git

RUN git clone https://username:$
WORKDIR /your_repo
The 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


Popular posts from this blog

JSON Schema testing with Postman

Postman is becoming quite the popular tool for accessing and testing REST api services. One of the cool features is that you can write some Javascript tests on your responses. Built into Postman is also the Tiny Validator v4 and Cheerio. Cheerio is a small core JQuery like implementation. The problem I have is that there is no way to import a schema file from a remote place or a file. This will be about how I get around that issue.Pre-request Script var uri=''; $.get(uri + '/someFolder/schema.json', function(schema) { postman.setEnvironmentVariable('schema', JSON.stringify(schema)); }); This Pre-request script is what saves the day. There are a couple of timing issues that are present due to async processing. If you were to put this in your test script your chances of it not completing in time are very high and you would get inconsistent results. If you are familiar with JQuery the $.get should look familiar as a ajax call that d…

Mock HTTP calls with Angular and Protractor

One of the benefits using AngularJS is also using some test tools like Protractor. Protractor is a tool that was made for Angular testing. Many times when testing you will need to mock some data so that you can see if your application responds in the correct manner. Let us assume that we have the following HTML file running our application.
<!doctype html> <html ng-app="demo"> <head> <title>Hello</title> <script src=""></script> <script src=""></script> <script src="hello.js"></script> </head> <body> <div ng-controller="Hello"> <p>Hello <span id="gname">{{}}</span></p> </div> …

Remote API useful tricks for Docker on Mac OS X

Install SocatSocat allow you to forward ports to a variety of things. For Docker forwarding a port to the docker.sock file makes a quick way to get access to the Docker remote api. Docker also allow a way to open up that TCP port however on Mac it is temperamental and hard to usebrew install socat socat -d TCP-LISTEN:2375,reuseaddr,fork UNIX:/var/run/docker.sock & Create an IP aliasRunning Docker containers locally is a fairly common thing. Interconnectivity between containers works naturally. However, sometimes you may also want a container to connect back to the Docker Remote API. If you are constantly on the go changing networks you do not want to have to change that IP address every time. A great use case for this is running Jenkins and using docker slavessudo ifconfig lo0 alias Remote API There are also some interesting endpoints you can use for informationcurl http://localhost:2375 curl http://localhost:2375/containers/json curl http://localhost:2375/image…