Back to top
2 minute read

Personal token support for Nginx Containers

Easier git integration added to ngineered's nginx containers

If you've ever used our PHP container to test or host your code you may have taken advantage of the git integration which allows you to dynamically pull and push code into the container from your own private git repository, which turns it into an incredibly quick development and deployment environment.

Previously there was a fairly complex setup procedure which involved creating SSH keys, adding them to your github account and using base64 tools to make this a variable that the container then used to access your repository. We wanted to make that easier and quicker, that's why we now support Personal Access Tokens.

You can pass the container your personal access token from your git account using the GIT_PERSONAL_TOKEN flag. This token must be setup with the correct permissions in git in order to push and pull code, we'll explain how in a moment.

Since the access token acts as a password, the git push/pull scripts can operate as normal but they use HTTPS to authenticate to github, instead of SSH.

You will need to specify your GIT_USERNAME and GIT_PERSONAL_TOKEN variables when starting the container as well as the GIT_EMAILGIT_NAME and GIT_REPO common variables, you may also choose to have GIT_BRANCH defined. Here is a brief descriptions of the flags:

Common Variables

  • GIT_REPO : URL to the repository containing your source code. If you are using a personal token, this is the https URL without https://, e.g (required)
  • GIT_BRANCH : Select a specific branch to use (optional)
  • GIT_EMAIL : Set your email for code pushing (required)
  • GIT_NAME : Set your name for code pushing (required)

New Personal Token Variables

  • GIT_PERSONAL_TOKEN : The personal access token for your git account (required)
  • GIT_USERNAME : The git username for use with the personal token specified above (required)

Getting your Personal Access Token

Creating a personal access token on github is very simple and this guide to help you get going:

It's definitely much less involved than the previous SSH_KEY method, and we strongly recommend you use this from now on. Please note that a Personal Access Token is effectively a password and you should treat it the same way, one nice thing about these tokens though is you can revoke them if you think one has been compromised.

Running your container

Once you have your key the following docker line will help you get started:

docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e '' -e 'GIT_PERSONAL_TOKEN=<token_here>' richarvey/nginx-php-fpm:latest

Your container will now start and you can use it to sync your code to and from the container dynamically using the push and pull scripts:

To pull code run the following:

docker exec -t -i <CONTAINER_NAME> /usr/bin/pull

To push code you can run this very similar command:

docker exec -t -i <CONTAINER_NAME> /usr/bin/push

Get Involved

As ever please get involved with the project and suggest new features or enhancements, the code can be found here:

Ric Harvey

Ric leads engineering and technical architecture for Ngineered. He has a vast amount of experience in cloud computing, having been responsible for the delivery of large-scale cloud migration projects at companies like Ticketmaster and Channel 4.