mirror of
https://github.com/peter-evans/dockerhub-description.git
synced 2024-11-21 11:39:34 +01:00
refactor: update image to execute action with node
This commit is contained in:
parent
65f339015f
commit
33cc80a90a
2 changed files with 18 additions and 60 deletions
20
Dockerfile
20
Dockerfile
|
@ -1,16 +1,18 @@
|
|||
FROM peterevans/curl-jq:1.0.1
|
||||
FROM node:12-alpine
|
||||
|
||||
LABEL maintainer="Peter Evans <mail@peterevans.dev>"
|
||||
LABEL repository="https://github.com/peter-evans/dockerhub-description"
|
||||
LABEL homepage="https://github.com/peter-evans/dockerhub-description"
|
||||
|
||||
LABEL com.github.actions.name="Docker Hub Description"
|
||||
LABEL com.github.actions.description="An action to update a Docker Hub repository description from README.md"
|
||||
LABEL com.github.actions.icon="upload"
|
||||
LABEL com.github.actions.color="blue"
|
||||
LABEL \
|
||||
maintainer="Peter Evans <mail@peterevans.dev>" \
|
||||
org.opencontainers.image.title="dockerhub-description" \
|
||||
org.opencontainers.image.description="An action to update a Docker Hub repository description from README.md" \
|
||||
org.opencontainers.image.authors="Peter Evans <mail@peterevans.dev>" \
|
||||
org.opencontainers.image.url="https://github.com/peter-evans/dockerhub-description" \
|
||||
org.opencontainers.image.vendor="https://peterevans.dev" \
|
||||
org.opencontainers.image.licenses="MIT"
|
||||
|
||||
COPY LICENSE README.md /
|
||||
|
||||
COPY dist/index.js /index.js
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
|
|
@ -2,56 +2,12 @@
|
|||
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}}
|
||||
# Execute the action code and output to file
|
||||
node index.js > action.log 2>&1
|
||||
|
||||
# If the repository isn't explicitly defined, infer it from GitHub if possible
|
||||
DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${GITHUB_REPOSITORY}}
|
||||
# Remove lines containing sensitive information from the log
|
||||
sed -i '/::debug::/d' ./action.log
|
||||
sed -i '/::add-mask::/d' ./action.log
|
||||
|
||||
# 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 exists
|
||||
if [ ! -f ${README_FILEPATH} ]; then
|
||||
echo "Readme file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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}\"}"
|
||||
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD} https://hub.docker.com/v2/users/login/ | jq -r .token)
|
||||
|
||||
# Send a PATCH request to update the description of the repository
|
||||
echo "Sending PATCH request"
|
||||
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
|
||||
# Output the log
|
||||
cat action.log
|
||||
|
|
Loading…
Reference in a new issue