Skip to content

⚓ Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step.

License

Notifications You must be signed in to change notification settings

trentjones21/github-docker

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Docker Action

Build and publish your repository as a Docker image and push it to GitHub Container Registry in one easy step.

GitHub Release

For help updating, view the change logs.

Inputs

Name Requirement Description
accessToken Required GitHub Repository Token to log in using. Must have write permissions for packages. Recommended set up would be to use the provided GitHub Token for your repository; ${{ github.token }}.
imageName Optional The desired name for the image. Defaults to current repository name.
tag Optional The desired tag for the image. Defaults to latest. Optionally accepts multiple tags separated by newline. See example below.
buildArgs Optional Any additional build arguments to use when building the image, separated by newline. See example below.
context Optional Where should GitHub Docker find the Dockerfile? This is a path relative to the repository root. Defaults to ., meaning it will look for a Dockerfile in the root of the repository. See example below.
contextName Optional What Dockerfile should GitHub Docker be using when building. Defaults to traditional Dockerfile name. See example below.
repository Optional The repository to push the image to. Defaults to the current repository. Must be specified in format user/repo. Note: Using an external repository requires elevated permissions. The provided GitHub token for the repository running the action will not suffice. You must use custom secret containing a Personal Access Token that has package write permissions on the given repository. See example below.

Outputs

With Parameter Description
imageURL The URL of the image, without the tag.

Example usage

Simple, minimal usage...

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ github.token }}

That's right this is all you need to get started with GitHub Docker, simply provide the GitHub token and the defaults will go to work. An image following the repository name will be pushed to the repository, with a tag corresponding to the commit SHA that triggered the workflow. The resulting URL is set as output for easy use in future steps!

For additional customizations, see further examples below. For more information on the output URL, see this example.

Publishing using custom tag...

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ github.token }}
    tag: latest

In this example we specify a custom tag for the image. Remember to append the tag when using the outputted image URL in the workflow. See this example for more details.

Publishing using several tags...

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ github.token }}
    tag: |
      latest
      ${{ github.sha }}

In this example we publish the same image under two different tags.

Publishing using build arguments...

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ github.token }}
    buildArgs: |
      ENVIRONMENT=test
      SOME_OTHER_ARG=yes

Using build arguments is easy, just set each one on its own individual line, similarly to how you would in a .env file.

Publishing and using output...

- name: Publish Image
  uses: matootie/[email protected]
  id: publish
  with:
    accessToken: ${{ github.token }}

- name: Print Image URL
  run: echo ${{ steps.publish.outputs.imageURL }}    

In this example you can see how easy it is to reference the image URL after publishing. If you are using a custom tag, you most likely are going to need to append the tag to the URL when using it in the workflow...

- name: Publish Image
  uses: matootie/[email protected]
  id: publish
  with:
    accessToken: ${{ github.token }}
    tag: ${{ github.sha }}

- name: Print Full Image URL
  run: echo ${{ stets.publish.outputs.imageURL }}:${{ github.sha }}

Otherwise, future steps will end up using the literal tag latest for the image and not the customized tag.

Publishing using custom context...

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ github.token }}  
    context: custom/context/dir/
    contextName: custom.Dockerfile

Here we see an example where GitHub Docker is given additional context on how to find the right Dockerfile. context is used to specify the directory of the Dockerfile, and contextName is used if the name of the Dockerfile is something that different than what docker build . would find.

Publishing to a different repository.

- name: Publish Image
  uses: matootie/[email protected]
  with:
    accessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
    repository: my-user/my-repo

In this example we're pushing the resulting image to be listed under a separate repository, different from the one that this action is running on. Remember, in this case the provided ${{ github.token }} will not work as it only has the necessary permissions for its own repository. You need to save a GitHub Personal Access Token with write permissions to packages as a secret, and use that.

About

⚓ Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 90.6%
  • Dockerfile 9.4%