Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5167ca4ba | ||
|
|
10e602777f | ||
|
|
382a87f452 | ||
|
|
2799bbf86a | ||
|
|
432cd004b3 | ||
|
|
9313daeb2f | ||
|
|
852d8b4b1f | ||
|
|
b93f6fad1d | ||
|
|
6ffdd6905f | ||
|
|
2739a0900f | ||
|
|
84d38211e2 | ||
|
|
abea83050d | ||
|
|
3361358488 | ||
|
|
2774ff3d56 | ||
|
|
b03d823861 | ||
|
|
6de5e14b55 | ||
|
|
5b8fd77939 | ||
|
|
81f3992e82 | ||
|
|
5e7108e09c | ||
|
|
f87713fbd6 | ||
|
|
7567c7b51b | ||
|
|
861e7a6d6a | ||
|
|
97941981d1 | ||
|
|
7041d8f35d | ||
|
|
843595a14f | ||
|
|
aa956b3fe8 | ||
|
|
e27c9c84cb | ||
|
|
26be7144b7 | ||
|
|
704c6b40c4 | ||
|
|
60c3aacb17 | ||
|
|
69ba977c50 | ||
|
|
a556e80cb3 | ||
|
|
96ab422aa6 | ||
|
|
09a017779e | ||
|
|
9baceaf7be | ||
|
|
30d779d1a8 | ||
|
|
8a5806631a | ||
|
|
66277dfaec | ||
|
|
5a618d1434 | ||
|
|
ba4f12bfe1 | ||
|
|
7f8bdc5174 | ||
|
|
2cdc04310b | ||
|
|
766da51375 | ||
|
|
49d8359332 | ||
|
|
b2856ab64f | ||
|
|
ef7baa2fee | ||
|
|
5f19c66987 | ||
|
|
9e8150a63d | ||
|
|
ff4c066a7a | ||
|
|
0f1898c5f3 |
24
.github/workflows/dockerhub-description.yml
vendored
Normal file
24
.github/workflows/dockerhub-description.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy README.md to TEST.md
|
||||
run: |
|
||||
mkdir -p some/path
|
||||
mv README.md some/path/TEST.md
|
||||
- name: Docker Hub Description
|
||||
uses: ./
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
README_FILEPATH: ./some/path/TEST.md
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM peterevans/curl-jq:1.0.0
|
||||
FROM peterevans/curl-jq:1.0.1
|
||||
|
||||
LABEL maintainer="Peter Evans <mail@peterevans.dev>"
|
||||
LABEL repository="https://github.com/peter-evans/dockerhub-description"
|
||||
@@ -9,7 +9,7 @@ LABEL com.github.actions.description="An action to update a Docker Hub repositor
|
||||
LABEL com.github.actions.icon="upload"
|
||||
LABEL com.github.actions.color="blue"
|
||||
|
||||
COPY LICENSE README.md
|
||||
COPY LICENSE README.md /
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
|
||||
115
README.md
115
README.md
@@ -1,4 +1,5 @@
|
||||
# Docker Hub Description
|
||||
[](https://github.com/marketplace/actions/docker-hub-description)
|
||||
|
||||
A GitHub action to update a Docker Hub repository description from `README.md`.
|
||||
|
||||
@@ -6,68 +7,96 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
action "Update Docker Hub Repository Description" {
|
||||
uses = "peter-evans/dockerhub-description@master"
|
||||
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"]
|
||||
}
|
||||
```yml
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
```
|
||||
|
||||
#### Required secrets
|
||||
#### Required environment variables
|
||||
|
||||
- `DOCKERHUB_USERNAME` - Docker Hub username
|
||||
- `DOCKERHUB_PASSWORD` - Docker Hub password
|
||||
- `DOCKERHUB_REPOSITORY` - The name of the Docker Hub repository to update. (This may also be an environment variable if not considered sensitive)
|
||||
- `DOCKERHUB_USERNAME` - Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. Aliases: `DOCKER_USERNAME`
|
||||
- `DOCKERHUB_PASSWORD` - Docker Hub password. Fallback to `DOCKER_PASSWORD` if set. Aliases: `DOCKER_PASSWORD`
|
||||
- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `<namespace>/<name>`. May also be passed as a secret if considered sensitive. Aliases: `DOCKER_REPOSITORY`, `GITHUB_REPOSITORY`
|
||||
|
||||
**Note**: Docker Hub [Personal Access Tokens](https://docs.docker.com/docker-hub/access-tokens/) cannot be used as they are not supported by the API. See [here](https://github.com/docker/hub-feedback/issues/1927) and [here](https://github.com/docker/hub-feedback/issues/1914) for further details. Unfortunately, this means that enabling the new 2FA feature on Docker Hub will prevent the action from working.
|
||||
|
||||
#### Optionally specifying the file path
|
||||
|
||||
The action assumes that there is a file called `README.md` located at the root of the repository.
|
||||
If this is not the case, the path can be overridden with an environment variable.
|
||||
|
||||
```
|
||||
action "Update Docker Hub Repository Description" {
|
||||
uses = "peter-evans/dockerhub-description@master"
|
||||
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"]
|
||||
env = {
|
||||
README_FILEPATH = "./some-path/README.md"
|
||||
}
|
||||
}
|
||||
```yml
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
README_FILEPATH: ./some-path/README.md
|
||||
```
|
||||
|
||||
#### Examples
|
||||
|
||||
Updates the Docker Hub repository description whenever there is a `git push` to the `master` branch.
|
||||
```
|
||||
workflow "New workflow" {
|
||||
on = "push"
|
||||
resolves = ["Update Docker Hub Repository Description"]
|
||||
}
|
||||
The following workflow updates the Docker Hub repository description whenever there are changes to `README.md` and the workflow file itself on the `master` branch. This workflow assumes its location to be `.github/workflows/dockerhub-description.yml`.
|
||||
|
||||
action "Filter master branch" {
|
||||
uses = "actions/bin/filter@master"
|
||||
args = "branch master"
|
||||
}
|
||||
|
||||
action "Update Docker Hub Repository Description" {
|
||||
needs = ["Filter master branch"]
|
||||
uses = "peter-evans/dockerhub-description@master"
|
||||
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"]
|
||||
}
|
||||
```yml
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
```
|
||||
|
||||
Updates the Docker Hub repository description whenever a new release is created.
|
||||
```
|
||||
workflow "New workflow" {
|
||||
on = "release"
|
||||
resolves = ["Update Docker Hub Repository Description"]
|
||||
}
|
||||
|
||||
action "Update Docker Hub Repository Description" {
|
||||
uses = "peter-evans/dockerhub-description@master"
|
||||
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"]
|
||||
}
|
||||
```yml
|
||||
name: Update Docker Hub Description
|
||||
on: release
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
```
|
||||
|
||||
## Using the Docker image independently of GitHub Actions
|
||||
|
||||
The image can be executed in other environments independently of GitHub Actions.
|
||||
Simply volume mount the location of the `README.md` file to the container and set environment variables as follows.
|
||||
|
||||
```bash
|
||||
docker run -v $PWD:/workspace \
|
||||
-e DOCKERHUB_USERNAME='user1' \
|
||||
-e DOCKERHUB_PASSWORD='xxxxx' \
|
||||
-e DOCKERHUB_REPOSITORY='user1/my-docker-image' \
|
||||
-e README_FILEPATH='/workspace/README.md' \
|
||||
peterevans/dockerhub-description:2.3
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see the [LICENSE](LICENSE) file for details
|
||||
[MIT](LICENSE)
|
||||
|
||||
22
action.yml
Normal file
22
action.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
name: 'Docker Hub Description'
|
||||
author: 'Peter Evans'
|
||||
description: 'An action to update a Docker Hub repository description from README.md'
|
||||
# env:
|
||||
# DOCKERHUB_USERNAME:
|
||||
# description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME
|
||||
# required: true
|
||||
# DOCKERHUB_PASSWORD:
|
||||
# description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD
|
||||
# required: true
|
||||
# DOCKERHUB_REPOSITORY:
|
||||
# description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY
|
||||
# required: true
|
||||
# README_FILEPATH:
|
||||
# description: Path to the repository readme.
|
||||
# default: ./README.md
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://peterevans/dockerhub-description:2.3.0'
|
||||
branding:
|
||||
icon: 'upload'
|
||||
color: 'blue'
|
||||
@@ -1,10 +1,36 @@
|
||||
#!/bin/sh -l
|
||||
set -euo pipefail
|
||||
set -eo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Allow DOCKERHUB_* variables to be set from their DOCKER_* variant
|
||||
DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-${DOCKER_USERNAME}}
|
||||
DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-${DOCKER_PASSWORD}}
|
||||
DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${DOCKER_REPOSITORY}}
|
||||
|
||||
# If the repository isn't explicitly defined, infer it from GitHub if possible
|
||||
DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${GITHUB_REPOSITORY}}
|
||||
|
||||
# Validate we can authenticate
|
||||
if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then
|
||||
echo 'Unable to authenticate with Docker Hub, set a valid $DOCKERHUB_USERNAME and $DOCKERHUB_PASSWORD'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate we have the repository name
|
||||
if [ -z "$DOCKERHUB_REPOSITORY" ]; then
|
||||
echo 'Unable to determine Docker Hub repository name, set with $DOCKERHUB_REPOSITORY'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the default path to README.md
|
||||
README_FILEPATH=${README_FILEPATH:="./README.md"}
|
||||
|
||||
# Check the file size
|
||||
if [ $(wc -c <${README_FILEPATH}) -gt 25000 ]; then
|
||||
echo "File size exceeds the maximum allowed 25000 bytes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Acquire a token for the Docker Hub API
|
||||
echo "Acquiring token"
|
||||
LOGIN_PAYLOAD="{\"username\": \"${DOCKERHUB_USERNAME}\", \"password\": \"${DOCKERHUB_PASSWORD}\"}"
|
||||
@@ -12,12 +38,14 @@ TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD}
|
||||
|
||||
# Send a PATCH request to update the description of the repository
|
||||
echo "Sending PATCH request"
|
||||
REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_USERNAME}/${DOCKERHUB_REPOSITORY}/"
|
||||
RESPONSE_CODE=$(curl -s --write-out %{response_code} --silent --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL})
|
||||
REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_REPOSITORY}/"
|
||||
RESPONSE_CODE=$(curl -s --write-out %{response_code} --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL})
|
||||
echo "Received response code: $RESPONSE_CODE"
|
||||
|
||||
if [ $RESPONSE_CODE -eq 200 ]; then
|
||||
echo "Request successful"
|
||||
exit 0
|
||||
else
|
||||
echo "Request failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user