Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

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

License

NotificationsYou must be signed in to change notification settings

matootie/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

Disclaimer

I originally wrote this when GitHub Actions was very new, and the setup you had to use to push images using Docker's provided actions was not very clean. I wanted to make a one-click tool. This tool still works, however GitHub Actions has been around for a while now and Docker has really improved their provided actions. My honest recommendation to you is that you try usingDocker Build-Push Action. It's what I use now. It has plenty more features, and uses Buildx. This repository will always have a place in my heart as the project that really got me into GitHub Actions.

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

GitHub Release

For help updating, view thechange logs. If you need additional help feel free to submit an issue.

Table of Contents

Inputs

NameRequirementDescription
accessTokenRequiredGitHub Access 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 }}.
imageNameOptionalThe desired name for the image. Defaults to current repository name.
tagOptionalThe desired tag for the image. Defaults tolatest. Optionally accepts multiple tags separated by newline.Seeexample below.
buildArgsOptionalAny additional build arguments to use when building the image, separated by newline.Seeexample below.
contextOptionalWhere should GitHub Docker find the Dockerfile? This is a path relative to the repository root. Defaults to., meaning it will look for aDockerfile in the root of the repository.Seeexample below.
contextNameOptionalWhat Dockerfile should GitHub Docker be using when building. Defaults to traditionalDockerfile name.Seeexample below.
containerRegistryOptionalWhether or not to push to GitHub Container Registry instead of GitHub Package Registry.When using GitHub Container Registry there are a few important differences to keep in mind. Seeexplanation below.
repositoryOptionalThe repository to push the image to. Defaults to the current repository. Must be specified in formatuser/repo.Note: Using an external repository requires elevated permissions. The provided GitHub token for the repository running the action willnot suffice. You must use custom secret containing aPersonal Access Token that has package write permissions on the given repository. Seeexample below.

Outputs

With ParameterDescription
imageURLThe URL of the image,without the tag.

GitHub Package Registry usage

Simple, minimal usage...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with: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, tagged withlatest. 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, seethis example.

Publishing using custom tag...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with: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. Seethis example for more details.

Publishing using several tags...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with: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 Imageuses:matootie/github-docker@v3.1.0with: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 Imageuses:matootie/github-docker@v3.1.0id:publishwith:accessToken:${{ github.token }}-name:Print Image URLrun: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 Imageuses:matootie/github-docker@v3.1.0id:publishwith:accessToken:${{ github.token }}tag:${{ github.sha }}-name:Print Full Image URLrun:echo ${{ steps.publish.outputs.imageURL }}:${{ github.sha }}

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

Publishing using custom context...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with: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, andcontextName is used if the name of the Dockerfile is something that different than whatdocker build . would find.

Publishing to a different repository.

-name:Publish Imageuses:matootie/github-docker@v3.1.0with: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 }} willnot work as it only has the necessary permissions for its own repository. You need to save a GitHubPersonal Access Token with write permissions to packages as a secret, and use that.

GitHub Container Registry usage

Using GitHub Docker with the GitHub Container Registry is just about the same as using it with the Package Registry, but there are a few things to remember.

  1. TheaccessToken input must be aPersonal Access Token withwrite:packages scope.
  2. TherepositoryName input is entirely useless as the container will be pushed to the owner of the current repository instead.

The following are a copy of the same examples listed above, using GitHub Container Registry instead of GitHub Package Registry.Note the differences in input.

Simple, minimal usage...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with:accessToken:${{ secrets.PAT }}containerRegistry:true

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 owner, tagged withlatest. 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, seethis example.

Publishing using custom tag...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with:accessToken:${{ secrets.PAT }}tag:latestcontainerRegistry:true

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. Seethis example for more details.

Publishing using several tags...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with:accessToken:${{ secrets.PAT }}tag:|      latest      ${{ github.sha }}containerRegistry:true

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

Publishing using build arguments...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with:accessToken:${{ secrets.PAT }}buildArgs:|      ENVIRONMENT=test      SOME_OTHER_ARG=yescontainerRegistry:true

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 Imageuses:matootie/github-docker@v3.1.0id:publishwith:accessToken:${{ secrets.PAT }}containerRegistry:true-name:Print Image URLrun: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 Imageuses:matootie/github-docker@v3.1.0id:publishwith:accessToken:${{ secrets.PAT }}tag:${{ github.sha }}containerRegistry:true-name:Print Full Image URLrun:echo ${{ steps.publish.outputs.imageURL }}:${{ github.sha }}

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

Publishing using custom context...

-name:Publish Imageuses:matootie/github-docker@v3.1.0with:accessToken:${{ secrets.PAT }}context:custom/context/dir/contextName:custom.DockerfilecontainerRegistry:true

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, andcontextName is used if the name of the Dockerfile is something that different than whatdocker build . would find.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2026 Movatter.jp