24 Commits

Author SHA1 Message Date
Peter Evans
e27c9c84cb Update README 2019-08-22 10:56:12 +09:00
Peter Evans
26be7144b7 Update workflow 2019-08-22 10:53:31 +09:00
Peter Evans
704c6b40c4 Don't include username in repository path 2019-08-22 10:51:29 +09:00
Peter Evans
60c3aacb17 Update README 2019-08-12 17:31:07 +09:00
Peter Evans
69ba977c50 Update workflow 2019-08-12 17:30:59 +09:00
Peter Evans
a556e80cb3 Update README 2019-08-12 14:18:43 +09:00
Peter Evans
96ab422aa6 Convert main.workflow to v2 yml 2019-08-12 14:18:06 +09:00
Peter Evans
09a017779e Remove duplicate flag 2019-07-07 16:19:29 +09:00
Peter Evans
9baceaf7be Update README 2019-07-01 22:27:07 +09:00
Peter Evans
30d779d1a8 Update README 2019-06-30 13:10:08 +09:00
Peter Evans
8a5806631a Update README 2019-06-30 11:17:55 +09:00
Peter Evans
66277dfaec Add circleci config 2019-06-30 10:56:03 +09:00
Peter Evans
5a618d1434 Update base image 2019-06-29 11:08:25 +09:00
Peter Evans
ba4f12bfe1 Fix copy directive 2019-06-29 11:08:06 +09:00
Peter Evans
7f8bdc5174 Update README 2019-06-26 20:41:46 +09:00
Peter Evans
2cdc04310b Update main.workflow 2019-06-26 20:41:30 +09:00
Peter Evans
766da51375 Update main.workflow 2019-06-26 20:34:04 +09:00
Peter Evans
49d8359332 Update main.workflow 2019-06-26 20:28:22 +09:00
Peter Evans
b2856ab64f Update README 2019-06-26 07:49:55 +09:00
Peter Evans
ef7baa2fee Update README examples 2019-06-25 21:10:05 +09:00
Peter Evans
5f19c66987 Update main.workflow 2019-06-25 20:35:40 +09:00
Peter Evans
9e8150a63d Update main.workflow 2019-06-25 20:18:14 +09:00
Peter Evans
ff4c066a7a Update README 2019-06-25 19:57:50 +09:00
Peter Evans
0f1898c5f3 Update README 2019-06-25 19:53:47 +09:00
5 changed files with 154 additions and 43 deletions

70
.circleci/config.yml Normal file
View File

@@ -0,0 +1,70 @@
version: 2.1
executors:
docker-executor:
environment:
IMAGE_NAME: peterevans/dockerhub-description
docker:
- image: circleci/buildpack-deps:stretch
jobs:
build:
executor: docker-executor
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Build Docker image
command: |
docker build -t $IMAGE_NAME:latest . --label "org.opencontainers.image.version=${CIRCLE_TAG/v/''}"
- run:
name: Cache Docker image
command: docker save -o image.tar $IMAGE_NAME
- persist_to_workspace:
root: .
paths:
- ./image.tar
publish-tag:
executor: docker-executor
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load cached Docker image
command: docker load -i /tmp/workspace/image.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
IMAGE_TAG=${CIRCLE_TAG/v/''}
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:$IMAGE_TAG
# If the minor version can be extracted then tag and push
MINOR_VERSION=$(echo $CIRCLE_TAG | sed -n "s/^v\([0-9]*.[0-9]*\).[0-9]*$/\1/p")
if [[ ${#MINOR_VERSION} -gt 0 ]]; then
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$MINOR_VERSION
docker push $IMAGE_NAME:$MINOR_VERSION
fi
workflows:
version: 2
build:
jobs:
- build
build-and-publish-tags:
jobs:
- build:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
- publish-tag:
context: org-global
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/

16
.github/workflows/push.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: Update Docker Hub Description
on:
push:
branches:
- master
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Docker Hub Description
uses: ./
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description

View File

@@ -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 maintainer="Peter Evans <mail@peterevans.dev>"
LABEL repository="https://github.com/peter-evans/dockerhub-description" 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.icon="upload"
LABEL com.github.actions.color="blue" LABEL com.github.actions.color="blue"
COPY LICENSE README.md COPY LICENSE README.md /
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh

103
README.md
View File

@@ -1,4 +1,6 @@
# Docker Hub Description # Docker Hub Description
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Docker%20Hub%20Description-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/docker-hub-description)
[![CircleCI](https://circleci.com/gh/peter-evans/dockerhub-description/tree/master.svg?style=svg)](https://circleci.com/gh/peter-evans/dockerhub-description/tree/master)
A GitHub action to update a Docker Hub repository description from `README.md`. A GitHub action to update a Docker Hub repository description from `README.md`.
@@ -6,66 +8,89 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
## Usage ## Usage
``` ```yml
action "Update Docker Hub Repository Description" { - name: Docker Hub Description
uses = "peter-evans/dockerhub-description@master" uses: peter-evans/dockerhub-description@v1.0.1
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] 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_USERNAME` - Docker Hub username
- `DOCKERHUB_PASSWORD` - Docker Hub password - `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_REPOSITORY` - The Docker Hub repository to update in the format `<namespace>/<name>`
Note that `DOCKERHUB_REPOSITORY` may also be passed as a secret if considered sensitive.
#### Optionally specifying the file path #### Optionally specifying the file path
The action assumes that there is a file called `README.md` located at the root of the repository. 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. If this is not the case, the path can be overridden with an environment variable.
``` ```yml
action "Update Docker Hub Repository Description" { - name: Docker Hub Description
uses = "peter-evans/dockerhub-description@master" uses: peter-evans/dockerhub-description@v1.0.1
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] env:
env = { DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
README_FILEPATH = "./some-path/README.md" DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
} DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
} README_FILEPATH: ./some-path/README.md
``` ```
#### Examples #### Examples
Updates the Docker Hub repository description whenever there is a `git push` to the `master` branch. Updates the Docker Hub repository description whenever there is a `git push` to the `master` branch.
``` ```yml
workflow "New workflow" { name: Update Docker Hub Description
on = "push" on:
resolves = ["Update Docker Hub Repository Description"] push:
} branches:
- master
action "Filter master branch" { jobs:
uses = "actions/bin/filter@master" dockerHubDescription:
args = "branch master" runs-on: ubuntu-latest
} steps:
- uses: actions/checkout@master
action "Update Docker Hub Repository Description" { - name: Docker Hub Description
needs = ["Filter master branch"] uses: peter-evans/dockerhub-description@v1.0.1
uses = "peter-evans/dockerhub-description@master" env:
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] 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. Updates the Docker Hub repository description whenever a new release is created.
```yml
name: Update Docker Hub Description
on: release
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v1.0.1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
``` ```
workflow "New workflow" {
on = "release"
resolves = ["Update Docker Hub Repository Description"]
}
action "Update Docker Hub Repository Description" { ## Using the Docker image independently of GitHub Actions
uses = "peter-evans/dockerhub-description@master"
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] 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:1.0.1
``` ```
## License ## License

View File

@@ -12,8 +12,8 @@ TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD}
# Send a PATCH request to update the description of the repository # Send a PATCH request to update the description of the repository
echo "Sending PATCH request" echo "Sending PATCH request"
REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_USERNAME}/${DOCKERHUB_REPOSITORY}/" REPO_URL="https://hub.docker.com/v2/repositories/${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}) 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" echo "Received response code: $RESPONSE_CODE"
if [ $RESPONSE_CODE -eq 200 ]; then if [ $RESPONSE_CODE -eq 200 ]; then