github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/docs/sources/docker-hub/builds.md (about)

     1  page_title: Automated Builds on Docker Hub
     2  page_description: Docker Hub Automated Builds
     3  page_keywords: Docker, docker, registry, accounts, plans, Dockerfile, Docker Hub, docs, documentation, trusted, builds, trusted builds, automated builds
     4  
     5  # Automated Builds on Docker Hub
     6  
     7  ## About Automated Builds
     8  
     9  *Automated Builds* are a special feature of Docker Hub which allow you to
    10  use [Docker Hub's](https://hub.docker.com) build clusters to automatically
    11  create images from a GitHub or Bitbucket repository containing a `Dockerfile`
    12  The system will clone your repository and build the image described by the
    13  `Dockerfile` using the directory the `Dockerfile` is in (and subdirectories)
    14  as the build context. The resulting automated image will then be uploaded
    15  to the Docker Hub registry and marked as an *Automated Build*.
    16  
    17  Automated Builds have several advantages:
    18  
    19  * Users of *your* Automated Build can trust that the resulting
    20  image was built exactly as specified.
    21  * The `Dockerfile` will be available to anyone with access to
    22  your repository on the Docker Hub registry.
    23  * Because the process is automated, Automated Builds help to
    24  make sure that your repository is always up to date.
    25  
    26  Automated Builds are supported for both public and private repositories
    27  on both [GitHub](http://github.com) and [Bitbucket](https://bitbucket.org/).
    28  
    29  To use Automated Builds, you must have an [account on Docker Hub](
    30  http://docs.docker.com/userguide/dockerhub/#creating-a-docker-hub-account)
    31  and on GitHub and/or Bitbucket. In either case, the account needs
    32  to be properly validated and activated before you can link to it.
    33  
    34  The first time you to set up an Automated Build, your
    35  [Docker Hub](https://hub.docker.com) account will need to be linked to
    36  a GitHub or Bitbucket account.
    37  This will allow the registry to see your repositories.
    38  
    39  If you have previously linked your Docker Hub account, and want to view or modify
    40  that link, click on the "Manage - Settings" link in the sidebar, and then
    41  "Linked Accounts" in your Settings sidebar.
    42  
    43  ## Automated Builds from GitHub
    44  
    45  If you've previously linked your Docker Hub account to your GitHub account,
    46  you'll be able to skip to the [Creating an Automated Build](#creating-an-automated-build).
    47  
    48  ### Linking your Docker Hub account to a GitHub account
    49  
    50  > *Note:*
    51  > Automated Builds currently require *read* and *write* access since
    52  > [Docker Hub](https://hub.docker.com) needs to setup a GitHub service
    53  > hook. We have no choice here, this is how GitHub manages permissions, sorry!
    54  > We do guarantee nothing else will be touched in your account.
    55  
    56  To get started, log into your Docker Hub account and click the
    57  "+ Add Repository" button at the upper right of the screen. Then select
    58  [Automated Build](https://registry.hub.docker.com/builds/add/).
    59  
    60  Select the [GitHub service](https://registry.hub.docker.com/associate/github/).
    61  
    62  When linking to GitHub, you'll need to select either "Public and Private",
    63  or "Limited" linking.
    64  
    65  The "Public and Private" option is the easiest to use,
    66  as it grants the Docker Hub full access to all of your repositories. GitHub
    67  also allows you to grant access to repositories belonging to your GitHub
    68  organizations.
    69  
    70  By choosing the "Limited" linking, your Docker Hub account only gets permission
    71  to access your public data and public repositories.
    72  
    73  Follow the onscreen instructions to authorize and link your
    74  GitHub account to Docker Hub. Once it is linked, you'll be able to
    75  choose a source repository from which to create the Automatic Build.
    76  
    77  You will be able to review and revoke Docker Hub's access by visiting the
    78  [GitHub User's Applications settings](https://github.com/settings/applications).
    79  
    80  > **Note**: If you delete the GitHub account linkage that is used for one of your
    81  > automated build repositories, the previously built images will still be available.
    82  > If you re-link to that GitHub account later, the automated build can be started
    83  > using the "Start Build" button on the Hub, or if the webhook on the GitHub repository
    84  > still exists, will be triggered by any subsequent commits.
    85  
    86  ### Auto builds and limited linked GitHub accounts.
    87  
    88  If you selected to link your GitHub account with only a "Limited" link, then
    89  after creating your automated build, you will need to either manually trigger a
    90  Docker Hub build using the "Start a Build" button, or add the GitHub webhook
    91  manually, as described in [GitHub Service Hooks](#github-service-hooks).
    92  
    93  ### Changing the GitHub user link
    94  
    95  If you want to remove, or change the level of linking between your GitHub account
    96  and the Docker Hub, you need to do this in two places.
    97  
    98  First, remove the "Linked Account" from your Docker Hub "Settings".
    99  Then go to your GitHub account's Personal settings, and in the "Applications"
   100  section, "Revoke access".
   101  
   102  You can now re-link your account at any time.
   103  
   104  ### GitHub organizations
   105  
   106  GitHub organizations and private repositories forked from organizations will be
   107  made available to auto build using the "Docker Hub Registry" application, which
   108  needs to be added to the organization - and then will apply to all users.
   109  
   110  To check, or request access, go to your GitHub user's "Setting" page, select the
   111  "Applications" section from the left side bar, then click the "View" button for
   112  "Docker Hub Registry".
   113  
   114  ![Check User access to GitHub](/docker-hub/hub-images/gh-check-user-org-dh-app-access.png)
   115  
   116  The organization's administrators may need to go to the Organization's "Third
   117  party access" screen in "Settings" to Grant or Deny access to the Docker Hub
   118  Registry application. This change will apply to all organization members.
   119  
   120  ![Check Docker Hub application access to Organization](/docker-hub/hub-images/gh-check-admin-org-dh-app-access.png)
   121  
   122  More detailed access controls to specific users and GitHub repositories would be
   123  managed using the GitHub People and Teams interfaces.
   124  
   125  ### Creating an Automated Build
   126  
   127  You can [create an Automated Build](
   128  https://registry.hub.docker.com/builds/github/select/) from any of your
   129  public or private GitHub repositories that have a `Dockerfile`.
   130  
   131  Once you've selected the source repository, you can then configure:
   132  
   133  - The Hub user/org the repository is built to - either your Hub account name,
   134  or the name of any Hub organizations your account is in
   135  - The Docker repository name the image is built to
   136  - If the Docker repository should be "Public" or "Private"
   137    You can change the accessibility options after the repository has been created.
   138    If you add a Private repository to a Hub user, then you can only add other users
   139    as collaborators, and those users will be able to view and pull all images in that 
   140    repository. To configure more granular access permissions, such as using groups of 
   141    users or allow different users access to different image tags, then you need
   142    to add the Private repository to a Hub organization that your user has Administrator
   143    privilege on.
   144  - If you want the GitHub to notify the Docker Hub when a commit is made, and thus trigger
   145    a rebuild of all the images in this automated build.
   146  
   147  You can also select one or more
   148  - The git branch/tag, which repository sub-directory to use as the context
   149  - The Docker image tag name
   150  
   151  You can set a description for the repository by clicking "Description" link in the righthand side bar after the automated build - note that the "Full Description" will be over-written next build from the README.md file.
   152  has been created.
   153  
   154  ### GitHub private submodules
   155  
   156  If your GitHub repository contains links to private submodules, you'll get an
   157  error message in your build.
   158  
   159  Normally, the Docker Hub sets up a deploy key in your GitHub repository.
   160  Unfortunately, GitHub only allows a repository deploy key to access a single repository.
   161  
   162  To work around this, you need to create a dedicated user account in GitHub and attach
   163  the automated build's deploy key that account. This dedicated build account
   164  can be limited to read-only access to just the repositories required to build.
   165  
   166  <table class="table table-bordered">
   167    <thead>
   168      <tr>
   169        <th>Step</th>
   170        <th>Screenshot</th>
   171        <th>Description</th>
   172      </tr>
   173    </thead>
   174    <tbody>
   175      <tr>
   176        <td>1.</td>
   177        <td><img src="/docker-hub/hub-images/gh_org_members.png"></td>
   178        <td>First, create the new account in GitHub. It should be given read-only
   179        access to the main repository and all submodules that are needed.</td>
   180      </tr>
   181      <tr>
   182        <td>2.</td>
   183        <td><img src="/docker-hub/hub-images/gh_team_members.png"></td>
   184        <td>This can be accomplished by adding the account to a read-only team in
   185        the organization(s) where the main GitHub repository and all submodule
   186        repositories are kept.</td>
   187      </tr>
   188      <tr>
   189        <td>3.</td>
   190        <td><img src="/docker-hub/hub-images/gh_repo_deploy_key.png"></td>
   191        <td>Next, remove the deploy key from the main GitHub repository. This can be done in the GitHub repository's "Deploy keys" Settings section.</td>
   192      </tr>
   193      <tr>
   194        <td>4.</td>
   195        <td><img src="/docker-hub/hub-images/deploy_key.png"></td>
   196        <td>Your automated build's deploy key is in the "Build Details" menu
   197        under "Deploy keys".</td>
   198      </tr>
   199      <tr>
   200        <td>5.</td>
   201        <td><img src="/docker-hub/hub-images/gh_add_ssh_user_key.png"></td>
   202        <td>In your dedicated GitHub User account, add the deploy key from your
   203        Docker Hub Automated Build.</td>
   204      </tr>
   205    </tbody>
   206  </table>
   207  
   208  ### GitHub service hooks
   209  
   210  The GitHub Service hook allows GitHub to notify the Docker Hub when something has
   211  been committed to that git repository. You will need to add the Service Hook manually
   212  if your GitHub account is "Limited" linked to the Docker Hub.
   213  
   214  Follow the steps below to configure the GitHub Service hooks for your Automated Build:
   215  
   216  <table class="table table-bordered">
   217    <thead>
   218      <tr>
   219        <th>Step</th>
   220        <th>Screenshot</th>
   221        <th>Description</th>
   222      </tr>
   223    </thead>
   224    <tbody>
   225      <tr>
   226        <td>1.</td>
   227        <td><img src="/docker-hub/hub-images/gh_settings.png"></td>
   228        <td>Log in to Github.com, and go to your Repository page. Click on "Settings" on
   229        the right side of the page. You must have admin privileges to the repository in order to do this.</td>
   230      </tr>
   231      <tr>
   232        <td>2.</td>
   233        <td><img src="/docker-hub/hub-images/gh_menu.png" alt="Webhooks & Services"></td>
   234        <td>Click on "Webhooks & Services" on the left side of the page.</td></tr>
   235        <tr><td>3.</td>
   236        <td><img src="/docker-hub/hub-images/gh_service_hook.png" alt="Find the service labeled Docker"></td>
   237        <td>Find the service labeled "Docker" (or click on "Add service") and click on it.</td></tr>
   238        <tr><td>4.</td>
   239        <td><img src="/docker-hub/hub-images/gh_docker-service.png" alt="Activate Service Hooks"></td>
   240        <td>Make sure the "Active" checkbox is selected and click the "Update service" button to save your changes.</td>
   241      </tr>
   242    </tbody>
   243  </table>
   244  
   245  ## Automated Builds with Bitbucket
   246  
   247  In order to setup an Automated Build, you need to first link your
   248  [Docker Hub](https://hub.docker.com) account with a Bitbucket account.
   249  This will allow the registry to see your repositories.
   250  
   251  To get started, log into your Docker Hub account and click the
   252  "+ Add Repository" button at the upper right of the screen. Then
   253  select [Automated Build](https://registry.hub.docker.com/builds/add/).
   254  
   255  Select the [Bitbucket source](
   256  https://registry.hub.docker.com/associate/bitbucket/).
   257  
   258  Then follow the onscreen instructions to authorize and link your
   259  Bitbucket account to Docker Hub. Once it is linked, you'll be able
   260  to choose a repository from which to create the Automatic Build.
   261  
   262  ### Creating an Automated Build
   263  
   264  You can [create an Automated Build](
   265  https://registry.hub.docker.com/builds/bitbucket/select/) from any of your
   266  public or private Bitbucket repositories with a `Dockerfile`.
   267  
   268  ### Adding a Hook
   269  
   270  When you link your Docker Hub account, a `POST` hook should get automatically
   271  added to your Bitbucket repository. Follow the steps below to confirm or modify the
   272  Bitbucket hooks for your Automated Build:
   273  
   274  <table class="table table-bordered">
   275    <thead>
   276      <tr>
   277        <th>Step</th>
   278        <th>Screenshot</th>
   279        <th>Description</th>
   280      </tr>
   281    </thead>
   282    <tbody>
   283      <tr>
   284        <td>1.</td>
   285        <td><img src="/docker-hub/hub-images/bb_menu.png" alt="Settings" width="180"></td>
   286        <td>Log in to Bitbucket.org and go to your Repository page. Click on "Settings" on
   287        the far left side of the page, under "Navigation". You must have admin privileges
   288        to the repository in order to do this.</td>
   289      </tr>
   290      <tr>
   291        <td>2.</td>
   292        <td><img src="/docker-hub/hub-images/bb_hooks.png" alt="Hooks" width="180"></td>
   293        <td>Click on "Hooks" on the near left side of the page, under "Settings".</td></tr>
   294      <tr>
   295        <td>3.</td>
   296        <td><img src="/docker-hub/hub-images/bb_post-hook.png" alt="Docker Post Hook"></td><td>You should now see a list of hooks associated with the repo, including a <code>POST</code> hook that points at
   297        registry.hub.docker.com/hooks/bitbucket.</td>
   298      </tr>
   299    </tbody>
   300  </table>
   301  
   302  
   303  ## The Dockerfile and Automated Builds
   304  
   305  During the build process, Docker will copy the contents of your `Dockerfile`.
   306  It will also add it to the [Docker Hub](https://hub.docker.com) for the Docker
   307  community (for public repositories) or approved team members/orgs (for private
   308  repositories) to see on the repository page.
   309  
   310  ### README.md
   311  
   312  If you have a `README.md` file in your repository, it will be used as the
   313  repository's full description.The build process will look for a
   314  `README.md` in the same directory as your `Dockerfile`.
   315  
   316  > **Warning:**
   317  > If you change the full description after a build, it will be
   318  > rewritten the next time the Automated Build has been built. To make changes,
   319  > modify the `README.md` from the Git repository.
   320  
   321  ## Remote Build triggers
   322  
   323  If you need a way to trigger Automated Builds outside of GitHub or Bitbucket,
   324  you can set up a build trigger. When you turn on the build trigger for an
   325  Automated Build, it will give you a URL to which you can send POST requests.
   326  This will trigger the Automated Build, much as with a GitHub webhook.
   327  
   328  Build triggers are available under the Settings menu of each Automated Build
   329  repository on the Docker Hub.
   330  
   331  ![Build trigger screen](/docker-hub/hub-images/build-trigger.png)
   332  
   333  You can use `curl` to trigger a build:
   334  
   335  ```
   336  $ curl --data "build=true" -X POST https://registry.hub.docker.com/u/svendowideit/testhook/trigger/be579c
   337  82-7c0e-11e4-81c4-0242ac110020/
   338  OK
   339  ```
   340  
   341  > **Note:**
   342  > You can only trigger one build at a time and no more than one
   343  > every five minutes. If you already have a build pending, or if you
   344  > recently submitted a build request, those requests *will be ignored*.
   345  > To verify everything is working correctly, check the logs of last
   346  > ten triggers on the settings page .
   347  
   348  ## Webhooks
   349  
   350  Automated Builds also include a Webhooks feature. Webhooks can be called
   351  after a successful repository push is made. This includes when a new tag is added
   352  to an existing image.
   353  
   354  The webhook call will generate a HTTP POST with the following JSON
   355  payload:
   356  
   357  ```
   358  {
   359    "callback_url": "https://registry.hub.docker.com/u/svendowideit/testhook/hook/2141b5bi5i5b02bec211i4eeih0242eg11000a/",
   360    "push_data": {
   361      "images": [
   362          "27d47432a69bca5f2700e4dff7de0388ed65f9d3fb1ec645e2bc24c223dc1cc3",
   363          "51a9c7c1f8bb2fa19bcd09789a34e63f35abb80044bc10196e304f6634cc582c",
   364          ...
   365      ],
   366      "pushed_at": 1.417566161e+09,
   367      "pusher": "trustedbuilder"
   368    },
   369    "repository": {
   370      "comment_count": 0,
   371      "date_created": 1.417494799e+09,
   372      "description": "",
   373      "dockerfile": "#\n# BUILD\u0009\u0009docker build -t svendowideit/apt-cacher .\n# RUN\u0009\u0009docker run -d -p 3142:3142 -name apt-cacher-run apt-cacher\n#\n# and then you can run containers with:\n# \u0009\u0009docker run -t -i -rm -e http_proxy http://192.168.1.2:3142/ debian bash\n#\nFROM\u0009\u0009ubuntu\nMAINTAINER\u0009SvenDowideit@home.org.au\n\n\nVOLUME\u0009\u0009[\"/var/cache/apt-cacher-ng\"]\nRUN\u0009\u0009apt-get update ; apt-get install -yq apt-cacher-ng\n\nEXPOSE \u0009\u00093142\nCMD\u0009\u0009chmod 777 /var/cache/apt-cacher-ng ; /etc/init.d/apt-cacher-ng start ; tail -f /var/log/apt-cacher-ng/*\n",
   374      "full_description": "Docker Hub based automated build from a GitHub repo",
   375      "is_official": false,
   376      "is_private": true,
   377      "is_trusted": true,
   378      "name": "testhook",
   379      "namespace": "svendowideit",
   380      "owner": "svendowideit",
   381      "repo_name": "svendowideit/testhook",
   382      "repo_url": "https://registry.hub.docker.com/u/svendowideit/testhook/",
   383      "star_count": 0,
   384      "status": "Active"
   385    }
   386  }
   387  ```
   388  
   389  Webhooks are available under the Settings menu of each Repository.
   390  
   391  > **Note:** If you want to test your webhook out we recommend using
   392  > a tool like [requestb.in](http://requestb.in/).
   393  
   394  > **Note**: The Docker Hub servers are currently in the IP range
   395  > `162.242.195.64 - 162.242.195.127`, so you can restrict your webhooks to
   396  > accept webhook requests from that set of IP addresses.
   397  
   398  ### Webhook chains
   399  
   400  Webhook chains allow you to chain calls to multiple services. For example,
   401  you can use this to trigger a deployment of your container only after
   402  it has been successfully tested, then update a separate Changelog once the
   403  deployment is complete.
   404  After clicking the "Add webhook" button, simply add as many URLs as necessary
   405  in your chain.
   406  
   407  The first webhook in a chain will be called after a successful push. Subsequent
   408  URLs will be contacted after the callback has been validated.
   409  
   410  ### Validating a callback
   411  
   412  In order to validate a callback in a webhook chain, you need to
   413  
   414  1. Retrieve the `callback_url` value in the request's JSON payload.
   415  1. Send a POST request to this URL containing a valid JSON body.
   416  
   417  > **Note**: A chain request will only be considered complete once the last
   418  > callback has been validated.
   419  
   420  To help you debug or simply view the results of your webhook(s),
   421  view the "History" of the webhook available on its settings page.
   422  
   423  ### Callback JSON data
   424  
   425  The following parameters are recognized in callback data:
   426  
   427  * `state` (required): Accepted values are `success`, `failure` and `error`.
   428    If the state isn't `success`, the webhook chain will be interrupted.
   429  * `description`: A string containing miscellaneous information that will be
   430    available on the Docker Hub. Maximum 255 characters.
   431  * `context`: A string containing the context of the operation. Can be retrieved
   432    from the Docker Hub. Maximum 100 characters.
   433  * `target_url`: The URL where the results of the operation can be found. Can be
   434    retrieved on the Docker Hub.
   435  
   436  *Example callback payload:*
   437  
   438      {
   439        "state": "success",
   440        "description": "387 tests PASSED",
   441        "context": "Continuous integration by Acme CI",
   442        "target_url": "http://ci.acme.com/results/afd339c1c3d27"
   443      }
   444  
   445  ## Repository links
   446  
   447  Repository links are a way to associate one Automated Build with
   448  another. If one gets updated,the linking system triggers a rebuild
   449  for the other Automated Build. This makes it easy to keep all your
   450  Automated Builds up to date.
   451  
   452  To add a link, go to the repository for the Automated Build you want to
   453  link to and click on *Repository Links* under the Settings menu at
   454  right. Then, enter the name of the repository that you want have linked.
   455  
   456  > **Warning:**
   457  > You can add more than one repository link, however, you should
   458  > do so very carefully. Creating a two way relationship between Automated Builds will
   459  > cause an endless build loop.