update DockerHub info

create a script that automatically updates the DockerHub project pages
This commit is contained in:
zimbatm 2019-02-13 18:30:15 +01:00
parent 9baba96f89
commit e97a236529
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
6 changed files with 95 additions and 18 deletions

View file

@ -6,9 +6,21 @@ set -euo pipefail
./build ./build
# default to the Gitlab registry
: "${REGISTRY:=$CI_REGISTRY}"
: "${REGISTRY_USER:=$CI_REGISTRY_USER}"
: "${REGISTRY_PASSWORD:=$CI_REGISTRY_PASSWORD}"
: "${IMAGE_PREFIX:=$CI_PROJECT_PATH}"
# IMAGE_TAG is provided by .gitlab-ci.yml
if [[ "$CI_COMMIT_REF_NAME" = master ]]; then if [[ "$CI_COMMIT_REF_NAME" = master ]]; then
./docker-login "$CI_REGISTRY" "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD" ./docker-login "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$REGISTRY"
./push-all "$CI_REGISTRY_IMAGE" "$IMAGE_TAG" ./push-all "$REGISTRY" "$IMAGE_PREFIX" "$IMAGE_TAG"
if [[ $REGISTRY = *docker.io ]]; then
./update-docker-hub "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$IMAGE_PREFIX"
fi
else else
echo "=== not pushing on non-master ===" echo "=== not pushing on non-master ==="
fi fi

View file

@ -6,9 +6,20 @@ set -euo pipefail
./build ./build
# default to Docker Hub
: "${REGISTRY:=docker.io}"
: "${IMAGE_PREFIX:=nixpkgs}"
# IMAGE_TAG is provided by .travis.yml
# the user has to set REGISTRY_USER and REGISTRY_PASSWORD
if [[ "$TRAVIS_BRANCH" = master && -z "$TRAVIS_PULL_REQUEST_BRANCH" ]]; then if [[ "$TRAVIS_BRANCH" = master && -z "$TRAVIS_PULL_REQUEST_BRANCH" ]]; then
./docker-login "$CI_REGISTRY" "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD" ./docker-login "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$REGISTRY"
./push-all "$CI_REGISTRY_PREFIX" "$IMAGE_TAG" ./push-all "$REGISTRY" "$IMAGE_PREFIX" "$IMAGE_TAG"
if [[ $REGISTRY = *docker.io ]]; then
./update-dockerhub "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$IMAGE_PREFIX"
fi
else else
echo "=== not pushing on non-master ===" echo "=== not pushing on non-master ==="
fi fi

View file

@ -1,8 +1,8 @@
# docker-nixpkgs: docker images from nixpkgs # docker-nixpkgs: docker images from nixpkgs
This project is a collection of docker images automatically produced with Nix This project is a collection of docker images automatically produced with Nix
and the latest nixpkgs package set. It even refreshes every morning a 4:00 UTC and the latest nixpkgs package set. All the images are refreshed daily with
thanks to the [Gitlab CI schedules][gitlab-schedules]. the latest versions of nixpkgs.
It's also a good demonstration on how to build and publish Docker images with It's also a good demonstration on how to build and publish Docker images with
Nix. Nix.
@ -24,10 +24,8 @@ Here is an example of using one of the docker images. Usage will change from
image to image. image to image.
``` ```
# the user must have an account at gitlab
$ docker login registry.gitlab.com
# run the curl image which has curl as an entry-point # run the curl image which has curl as an entry-point
$ docker run -ti --rm registry.gitlab.com/zimbatm/docker-nixpkgs/curl http://ifconfig.co $ docker run -ti --rm nixpkgs/curl http://ifconfig.co
180.52.248.114 180.52.248.114
``` ```
@ -49,6 +47,8 @@ $ docker run -ti --rm registry.gitlab.com/zimbatm/docker-nixpkgs/curl http://ifc
| nixos-unstable | the :latest version | | nixos-unstable | the :latest version |
| nixos-18.09 | automatic security updates | | nixos-18.09 | automatic security updates |
## License
[gitlab-schedules]: https://gitlab.com/zimbatm/docker-nixpkgs/pipeline_schedules Copyright (c) 2019 zimbatm and contributors.
Licensed under the MIT.

View file

@ -2,12 +2,18 @@
# #
# A simplified docker login approach that doesn't depends on the docker binary # A simplified docker login approach that doesn't depends on the docker binary
# #
# Usage: ./docker-login <registry> <username> <password> # Usage: ./docker-login <username> <password> [registry]
set -euo pipefail set -euo pipefail
registry=$1 username=$1
username=$2 password=$2
password=$3 registry=${3:-docker.io}
# Encode some funky docker heuristic
if [[ $registry = *docker.io ]]; then
# use the v2 registry so that skopeo can do noop layer copies
registry=https://index.docker.io/v2/
fi
mkdir ~/.docker mkdir ~/.docker

View file

@ -1,15 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Usage: ./push-all <registry-prefix> <image-tag> # Usage: ./push-all <registry> <image-prefix> <image-tag>
set -euo pipefail set -euo pipefail
registry_prefix=${1:-nixpkgs} registry=${1:-docker.io}
image_tag=${2:-latest} image_prefix=${2:-nixpkgs}
image_tag=${3:-latest}
releases_json=$(nix-instantiate ./release.nix --strict --eval --json) releases_json=$(nix-instantiate ./release.nix --strict --eval --json)
echo "=== Pushing images to $registry"
for attr in $(echo "$releases_json" | jq -r "keys[]") ; do for attr in $(echo "$releases_json" | jq -r "keys[]") ; do
file=$(echo "$releases_json" | jq -r ".\"$attr\"") file=$(echo "$releases_json" | jq -r ".\"$attr\"")
echo "--- $attr -> $file" echo "--- $attr -> $file"
skopeo copy "docker-archive://$file" "docker://$registry_prefix/$attr:$image_tag" skopeo copy "docker-archive://$file" "docker://$registry/$image_prefix/$attr:$image_tag"
done done
echo OK

43
update-dockerhub Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env bash
#
# Update docker hub image descriptions. The API is not documented and might
# break in the future.
#
# Usage: ./update-dockerhub <user> <password> [org]
set -euo pipefail
username=$1
password=$2
org=${3:-nixpkgs}
user=$username:$password
releases_json=$(nix-instantiate ./release.nix --strict --eval --json)
to_json() {
local desc=$1 full_desc=$2
jq -n \
--arg desc "$desc" \
--arg full_desc "$full_desc" \
'.description=$desc | .full_description=$full_desc'
}
echo "=== Updating Docker Hub project descriptions"
for attr in $(echo "$releases_json" | jq -r "keys[]") ; do
echo "--- $attr"
desc="$attr is automatically built from nix-community/docker-nixpkgs"
if [[ -f "$attr/README.md" ]]; then
full_desc=$(< "$attr/README.md")
else
full_desc=$(< "README.md")
fi
data=$(to_json "$desc" "$full_desc")
echo "data: $data"
url=https://cloud.docker.com/v2/repositories/$org/$attr/
curl -XPATCH -H "Content-Type: application/json" --user "$user" --data "$data" "$url"
done
echo OK