This GitHub Action will build, tag, and publish your docker image. The logic has been designed for our use case, but can be modifed for yours.
The image name will default to be the same as the GitHub Repo.
The tagging logic works as follows:
- If you have a value for
image_tag
then we will use that value. - If you set
sha
totrue
then we will use the SHA - If this is the default branch, then the tag will be
latest
- if this is a pull request, the the tag will be
pr-branch
where branch is the branch name. - Otherwise, we'll use the branch name or tag value.
graph LR
A{value provided for image_tag} -->|Yes| B[image_tag]
A --> |No| C{SHA set to True} --> |Yes| D[Use SHA]
C --> |No| E{Default Branch} --> |Yes| F[Latest]
E --> |No| G{Pull Request} --> |Yes| H[pr-branch where branch is the branch name]
G --> |No| I[Use branch name]
The following can be used as step.with
keys. T/F types expect true or false. Req is required.
Name | Type | Req | Description | Default |
---|---|---|---|---|
docker_username |
string | Yes | Dockerhub username | N/A |
docker_password |
string | Yes | Dockerhub Password | N/A |
checkout |
T/F | No | Determines if we should checkout the repository. Set to false if this is being done in an eariler step |
true |
image_tag |
string | No | Use this tag instead of the tagging logic. | See tagging logic |
use_latest |
T/F | No | The default branch gets a latest tag | true |
sha |
T/F | No | Set to true to use the SHA for the tag. |
false |
org_name |
string | No | Docker org name. | GitHub Org Name |
repo_name |
string | No | The name of the Docker Repository. | GitHub repo name. |
build_args |
string | No | Add arbitrary build arguments | N/A |
working-directory |
string | No | Specifies the working directory for the Docker Build step | N/A |
This will checkout the code, build, tag and push using the default tags.
- id: docker-publish
uses: bitovi/github-actions-docker-publish@main
with:
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
docker_password: ${{ secrets.DOCKERHUB_PASSWORD }}
Here we check the code out since we make a change before the build / publish step. We also show how to get the image and tag for later use in the same job.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: do something to the code
run: echo "Changed code" > text.txt
- id: docker-publish
name: Build image
uses: bitovi/github-actions-docker-publish@v1.0.3
with:
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
docker_password: ${{ secrets.DOCKERHUB_PASSWORD }}
checkout: 'false'
image_tag: it
sha: 'true' # won't do anything since image_tag is set
org_name: bitovi
repo_name: deploy-eks-helm
build_args: --build-arg git_personal_token=PAT_token
working-directory: ./app/inner-folder
- run: |
echo "Image Created: ${{ env.image }}"
echo "Tag Created: ${{ env.tag }}"
The scripts and documentation in this project are released under the MIT License.
Bitovi is a proud supporter of Open Source software.
Please feel free to copy and customize this action for your specific use case, just give some credit to Bitovi as the orignal authors.
You can get help or ask questions on Discord channel! Come hangout with us!
Or, you can hire us for training, consulting, or development. Set up a free consultation.