Skip to content

Latest commit

 

History

History
executable file
·
40 lines (29 loc) · 2.79 KB

git_auth.md

File metadata and controls

executable file
·
40 lines (29 loc) · 2.79 KB

Git Auth

There are two methods of pulling code from git, you can either use a Personal Token (recommended method) or an SSH key.

Note: We would recommend using a git personal token over an SSH key as it simplifies the set up process. To create a personal access token on Github follow this guide. If your repository is on BitBucket, you can create an "app password" and use it as the personnal access token. To get an app password for BitBucket, follow this guide.

Personal Access token

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.

Since the access token acts as a password with limited access, the git push/pull uses HTTPS to authenticate. You will need to specify your GIT_USERNAME and GIT_PERSONAL_TOKEN variables to push and pull. You'll need to also have the GIT_EMAIL, GIT_NAME and GIT_REPO common variables defined.

docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' jcsofts/alpine-nginx-php7:latest

To pull a repository and specify a branch add the GIT_BRANCH environment variable:

docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' -e 'GIT_BRANCH=stage' jcsofts/alpine-nginx-php7:latest

SSH keys

Preparing your SSH key

The container has the option for you to pass it the SSH_KEY variable with a base64 encoded private key. First generate your key and then make sure to add it to github and give it write permissions if you want to be able to push code from the container. Then run:

base64 -w 0 /path_to_your_private_key

Note: Copy the output, but be careful not to copy your prompt

Running with SSH Keys

To run the container and pull code simply specify the GIT_REPO URL including git@ and then make sure you have also supplied your base64 version of your ssh deploy key:

sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' jcsofts/alpine-nginx-php7:latest

To pull a repository and specify a branch add the GIT_BRANCH environment variable:

sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' -e 'GIT_BRANCH=stage' jcsofts/alpine-nginx-php7:latest