Skip to content

Commit a7fe665

Browse files
Add new addTimestamp input (#71)
1 parent b74f266 commit a7fe665

File tree

10 files changed

+10770
-37074
lines changed

10 files changed

+10770
-37074
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ typings/
6969
# Allure
7070
allure-report
7171
allure-results
72+
73+
# husky
74+
.husky

README.md

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Docker Build & Push Action
2+
23
[![Unit Tests](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/ci.yml/badge.svg)](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/ci.yml)
34
[![e2e Tests](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/e2e.yml/badge.svg)](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/e2e.yml)
45
[![Maintainability](https://api.codeclimate.com/v1/badges/ac0bf06dc93ba3110cd3/maintainability)](https://codeclimate.com/github/mr-smithers-excellent/docker-build-push/maintainability)
@@ -8,19 +9,20 @@ Builds a Docker image and pushes it to the private registry of your choosing.
89

910
## Supported Docker registries
1011

11-
* Docker Hub
12-
* Google Container Registry (GCR)
13-
* AWS Elastic Container Registry (ECR)
14-
* GitHub Docker Registry
12+
- Docker Hub
13+
- Google Container Registry (GCR)
14+
- AWS Elastic Container Registry (ECR)
15+
- GitHub Docker Registry
1516

1617
## Breaking changes
1718

1819
If you're experiencing issues, be sure you are using the [latest stable release](https://github.com/mr-smithers-excellent/docker-build-push/releases/latest) (currently v5). The AWS ECR login command became deprecated between v4 and v5. Additionally, support for multiple tags was added between v4 and v5.
1920

2021
## Basic usage
2122

22-
* Ensure you run the [checkout action](https://github.com/actions/checkout) before using this action
23-
* Add the following to a workflow `.yml` file in the `/.github` directory of your repo
23+
- Ensure you run the [checkout action](https://github.com/actions/checkout) before using this action
24+
- Add the following to a workflow `.yml` file in the `/.github` directory of your repo
25+
2426
```yaml
2527
steps:
2628
- uses: actions/checkout@v2
@@ -39,35 +41,36 @@ steps:
3941
4042
## Inputs
4143
42-
| Name | Description | Required | Type |
43-
|------------|----------------------------------------------------------------------------------------------------------|----------|---------|
44-
| image | Docker image name | Yes | String |
45-
| tags | Comma separated docker image tags (see [Tagging the image with GitOps](#tagging-the-image-using-gitops)) | No | List |
46-
| addLatest | Adds the `latest` tag to the GitOps-generated tags | No | Boolean |
47-
| registry | Docker registry host | Yes | String |
48-
| dockerfile | Location of Dockerfile (defaults to `Dockerfile`) | No | String |
49-
| directory | Directory to pass to `docker build` command, if not project root | No | String |
50-
| buildArgs | Docker build arguments passed via `--build-arg` | No | List |
51-
| labels | Docker build labels passed via `--label` | No | List |
52-
| target | Docker build target passed via `--target` | No | String |
53-
| username | Docker registry username | No | String |
54-
| password | Docker registry password or token | No | String |
55-
| githubOrg | GitHub organization to push image to (if not current) | No | String |
44+
| Name | Description | Required | Type |
45+
| ------------ | -------------------------------------------------------------------------------------------------------- | -------- | ------- |
46+
| image | Docker image name | Yes | String |
47+
| tags | Comma separated docker image tags (see [Tagging the image with GitOps](#tagging-the-image-using-gitops)) | No | List |
48+
| addLatest | Adds the `latest` tag to the GitOps-generated tags | No | Boolean |
49+
| addTimestamp | Suffixes a build timestamp to the branch-based Docker tag | No | Boolean |
50+
| registry | Docker registry host | Yes | String |
51+
| dockerfile | Location of Dockerfile (defaults to `Dockerfile`) | No | String |
52+
| directory | Directory to pass to `docker build` command, if not project root | No | String |
53+
| buildArgs | Docker build arguments passed via `--build-arg` | No | List |
54+
| labels | Docker build labels passed via `--label` | No | List |
55+
| target | Docker build target passed via `--target` | No | String |
56+
| username | Docker registry username | No | String |
57+
| password | Docker registry password or token | No | String |
58+
| githubOrg | GitHub organization to push image to (if not current) | No | String |
5659

5760
## Outputs
5861

59-
| Name | Description | Format |
60-
|---------------|-------------------------------------------------------------------|----------------------------|
61-
| imageFullName | Full name of the Docker image with registry prefix | `registry/owner/image` |
62-
| imageName | Name of the Docker image with owner prefix | `owner/image` |
63-
| tags | Tags for the Docker image | `v1,latest` |
62+
| Name | Description | Format |
63+
| ------------- | -------------------------------------------------- | ---------------------- |
64+
| imageFullName | Full name of the Docker image with registry prefix | `registry/owner/image` |
65+
| imageName | Name of the Docker image with owner prefix | `owner/image` |
66+
| tags | Tags for the Docker image | `v1,latest` |
6467

6568
## Examples
6669

6770
### Docker Hub
6871

69-
* Save your Docker Hub username (`DOCKER_USERNAME`) and password (`DOCKER_PASSWORD`) as secrets in your GitHub repo
70-
* Modify sample below and include in your workflow `.github/workflows/*.yml` file
72+
- Save your Docker Hub username (`DOCKER_USERNAME`) and password (`DOCKER_PASSWORD`) as secrets in your GitHub repo
73+
- Modify sample below and include in your workflow `.github/workflows/*.yml` file
7174

7275
```yaml
7376
uses: mr-smithers-excellent/docker-build-push@v5
@@ -80,28 +83,28 @@ with:
8083

8184
### Google Container Registry (GCR)
8285

83-
* Create a service account with the ability to push to GCR (see [configuring access control](https://cloud.google.com/container-registry/docs/access-control))
84-
* Create and download JSON key for new service account
85-
* Save content of `.json` file as a secret called `DOCKER_PASSWORD` in your GitHub repo
86-
* Modify sample below and include in your workflow `.github/workflows/*.yml` file
87-
* Ensure you set the username to `_json_key`
86+
- Create a service account with the ability to push to GCR (see [configuring access control](https://cloud.google.com/container-registry/docs/access-control))
87+
- Create and download JSON key for new service account
88+
- Save content of `.json` file as a secret called `DOCKER_PASSWORD` in your GitHub repo
89+
- Modify sample below and include in your workflow `.github/workflows/*.yml` file
90+
- Ensure you set the username to `_json_key`
8891

8992
```yaml
9093
uses: mr-smithers-excellent/docker-build-push@v5
9194
with:
9295
image: gcp-project/image-name
9396
registry: gcr.io
94-
username: _json_key
95-
password: ${{ secrets.DOCKER_PASSWORD }}
97+
username: _json_key
98+
password: ${{ secrets.DOCKER_PASSWORD }}
9699
```
97100

98101
### AWS Elastic Container Registry (ECR)
99102

100-
* Create an IAM user with the ability to push to ECR (see [example policies](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr_managed_policies.html))
101-
* Create and download access keys
102-
* Save `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` as secrets in your GitHub repo
103-
* Ensure the repo you are trying to push to already exists, if not create with `aws ecr create-repository` before pushing
104-
* Modify sample below and include in your workflow `.github/workflows/*.yml` file
103+
- Create an IAM user with the ability to push to ECR (see [example policies](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr_managed_policies.html))
104+
- Create and download access keys
105+
- Save `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` as secrets in your GitHub repo
106+
- Ensure the repo you are trying to push to already exists, if not create with `aws ecr create-repository` before pushing
107+
- Modify sample below and include in your workflow `.github/workflows/*.yml` file
105108

106109
```yaml
107110
uses: mr-smithers-excellent/docker-build-push@v5
@@ -115,12 +118,12 @@ env:
115118

116119
### GitHub Container Registry
117120

118-
* GitHub recently [migrated their container registry](https://docs.github.com/en/packages/guides/migrating-to-github-container-registry-for-docker-images) from docker.pkg.github.com to ghcr.io
119-
* It is assumed you'll be pushing the image to a repo inside your GitHub organization, unless you set `githubOrg`
120-
* If using ghcr.io, provide the image name in `ghcr.io/OWNER/IMAGE_NAME` format
121-
* If using docker.pkg.github.com, provide the image name in `docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME` format
122-
* Provide either the `${{ github.actor }}` or an alternate username for Docker login (with associated token below)
123-
* Pass the default GitHub Actions token or custom secret with [proper push permissions](https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images#authenticating-to-github-container-registry)
121+
- GitHub recently [migrated their container registry](https://docs.github.com/en/packages/guides/migrating-to-github-container-registry-for-docker-images) from docker.pkg.github.com to ghcr.io
122+
- It is assumed you'll be pushing the image to a repo inside your GitHub organization, unless you set `githubOrg`
123+
- If using ghcr.io, provide the image name in `ghcr.io/OWNER/IMAGE_NAME` format
124+
- If using docker.pkg.github.com, provide the image name in `docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME` format
125+
- Provide either the `${{ github.actor }}` or an alternate username for Docker login (with associated token below)
126+
- Pass the default GitHub Actions token or custom secret with [proper push permissions](https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images#authenticating-to-github-container-registry)
124127

125128
#### New ghcr.io
126129

@@ -131,7 +134,7 @@ with:
131134
registry: ghcr.io
132135
githubOrg: override-org # optional
133136
username: ${{ secrets.GHCR_USERNAME }}
134-
password: ${{ secrets.GHCR_TOKEN }}
137+
password: ${{ secrets.GHCR_TOKEN }}
135138
```
136139

137140
#### Legacy docker.pkg.github.com
@@ -149,13 +152,13 @@ with:
149152

150153
By default, if you do not pass a `tags` input this action will use an algorithm based on the state of your git repo to determine the Docker image tag(s). This is designed to enable developers to more easily use [GitOps](https://www.weave.works/technologies/gitops/) in their CI/CD pipelines. Below is a table detailing how the GitHub trigger (branch or tag) determines the Docker tag(s).
151154

152-
| Trigger | Commit SHA | addLatest | Docker Tag(s) |
153-
|--------------------------|------------|-----------|-----------------------------|
154-
| /refs/tags/v1.0 | N/A | false | v1.0 |
155-
| /refs/tags/v1.0 | N/A | true | v1.0,latest |
156-
| /refs/heads/dev | 1234567 | false | dev-1234567 |
157-
| /refs/heads/dev | 1234567 | true | dev-1234567,latest |
158-
| /refs/heads/master | 1234567 | false | master-1234567 |
159-
| /refs/heads/master | 1234567 | true | master-1234567,latest |
160-
| /refs/heads/SOME-feature | 1234567 | false | some-feature-1234567 |
161-
| /refs/heads/SOME-feature | 1234567 | true | some-feature-1234567,latest |
155+
| Trigger | Commit SHA | addLatest | addTimestamp | Docker Tag(s) |
156+
| ------------------------ | ---------- | --------- | ------------ | -------------------------------------- |
157+
| /refs/tags/v1.0 | N/A | false | N/A | v1.0 |
158+
| /refs/tags/v1.0 | N/A | true | N/A | v1.0,latest |
159+
| /refs/heads/dev | 1234567 | false | true | dev-1234567-2021-09-01.195027 |
160+
| /refs/heads/dev | 1234567 | true | false | dev-1234567,latest |
161+
| /refs/heads/main | 1234567 | false | true | main-1234567-2021-09-01.195027 |
162+
| /refs/heads/main | 1234567 | true | false | main-1234567,latest |
163+
| /refs/heads/SOME-feature | 1234567 | false | true | some-feature-1234567-2021-09-01.195027 |
164+
| /refs/heads/SOME-feature | 1234567 | true | false | some-feature-1234567,latest |

action.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
name: 'Docker Build & Push Action'
2-
description: 'Builds a Docker image and pushes to a private registry with support for multiple tags'
3-
author: 'Sean Smith'
1+
name: "Docker Build & Push Action"
2+
description: "Builds a Docker image and pushes to a private registry with support for multiple tags"
3+
author: "Sean Smith"
44
inputs:
55
image:
6-
description: 'Name of the Docker image'
6+
description: "Name of the Docker image"
77
required: true
88
tags:
9-
description: 'Tags override for Docker image'
9+
description: "Tags override for Docker image"
1010
required: false
1111
registry:
12-
description: 'Target Docker registry'
12+
description: "Target Docker registry"
1313
required: true
1414
dockerfile:
15-
description: 'Location of Dockerfile, if not Dockerfile in root directory'
15+
description: "Location of Dockerfile, if not Dockerfile in root directory"
1616
required: false
17-
default: 'Dockerfile'
17+
default: "Dockerfile"
1818
directory:
19-
description: 'Directory to run `docker build` from, if not project root'
19+
description: "Directory to run `docker build` from, if not project root"
2020
required: false
2121
buildArgs:
22-
description: 'Docker build arguments passed via --build-arg'
22+
description: "Docker build arguments passed via --build-arg"
2323
required: false
2424
labels:
25-
description: 'Docker build labels passed via --label'
25+
description: "Docker build labels passed via --label"
2626
required: false
2727
target:
28-
description: 'Docker build target passed via --target'
28+
description: "Docker build target passed via --target"
2929
required: false
3030
username:
31-
description: 'Docker registry username'
31+
description: "Docker registry username"
3232
required: false
3333
password:
34-
description: 'Docker registry password'
34+
description: "Docker registry password"
3535
required: false
3636
gitHubOrg:
37-
description: 'GitHub organization to push image to (if not current)'
37+
description: "GitHub organization to push image to (if not current)"
3838
required: false
3939
addLatest:
40-
description: 'Adds latest tag to auto-generated GitOps tag'
40+
description: "Adds latest tag to auto-generated GitOps tag"
4141
required: false
42-
default: 'false'
42+
default: "false"
43+
addTimestamp:
44+
description: "Suffixes a build timestamp to the branch-based Docker tag"
45+
required: false
46+
default: "false"
4347
outputs:
4448
imageFullName:
45-
description: 'Full name of the Docker image with registry prefix and tag suffix'
49+
description: "Full name of the Docker image with registry prefix and tag suffix"
4650
imageName:
47-
description: 'Name of the Docker image with owner prefix'
51+
description: "Name of the Docker image with owner prefix"
4852
tags:
49-
description: 'Tags for the Docker image'
53+
description: "Tags for the Docker image"
5054
runs:
51-
using: 'node12'
52-
main: 'dist/index.js'
55+
using: "node12"
56+
main: "dist/index.js"
5357
branding:
54-
icon: 'anchor'
55-
color: 'blue'
58+
icon: "anchor"
59+
color: "blue"

0 commit comments

Comments
 (0)