update DockerHub info
create a script that automatically updates the DockerHub project pages
This commit is contained in:
parent
9baba96f89
commit
e97a236529
6 changed files with 95 additions and 18 deletions
|
@ -6,9 +6,21 @@ set -euo pipefail
|
|||
|
||||
./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
|
||||
./docker-login "$CI_REGISTRY" "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD"
|
||||
./push-all "$CI_REGISTRY_IMAGE" "$IMAGE_TAG"
|
||||
./docker-login "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$REGISTRY"
|
||||
./push-all "$REGISTRY" "$IMAGE_PREFIX" "$IMAGE_TAG"
|
||||
if [[ $REGISTRY = *docker.io ]]; then
|
||||
./update-docker-hub "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$IMAGE_PREFIX"
|
||||
fi
|
||||
else
|
||||
echo "=== not pushing on non-master ==="
|
||||
fi
|
||||
|
|
15
.travis.sh
15
.travis.sh
|
@ -6,9 +6,20 @@ set -euo pipefail
|
|||
|
||||
./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
|
||||
./docker-login "$CI_REGISTRY" "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD"
|
||||
./push-all "$CI_REGISTRY_PREFIX" "$IMAGE_TAG"
|
||||
./docker-login "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$REGISTRY"
|
||||
./push-all "$REGISTRY" "$IMAGE_PREFIX" "$IMAGE_TAG"
|
||||
if [[ $REGISTRY = *docker.io ]]; then
|
||||
./update-dockerhub "$REGISTRY_USER" "$REGISTRY_PASSWORD" "$IMAGE_PREFIX"
|
||||
fi
|
||||
else
|
||||
echo "=== not pushing on non-master ==="
|
||||
fi
|
||||
|
|
12
README.md
12
README.md
|
@ -1,8 +1,8 @@
|
|||
# docker-nixpkgs: docker images from nixpkgs
|
||||
|
||||
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
|
||||
thanks to the [Gitlab CI schedules][gitlab-schedules].
|
||||
and the latest nixpkgs package set. All the images are refreshed daily with
|
||||
the latest versions of nixpkgs.
|
||||
|
||||
It's also a good demonstration on how to build and publish Docker images with
|
||||
Nix.
|
||||
|
@ -24,10 +24,8 @@ Here is an example of using one of the docker images. Usage will change from
|
|||
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
|
||||
$ 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
|
||||
```
|
||||
|
||||
|
@ -49,6 +47,8 @@ $ docker run -ti --rm registry.gitlab.com/zimbatm/docker-nixpkgs/curl http://ifc
|
|||
| nixos-unstable | the :latest version |
|
||||
| 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.
|
||||
|
|
14
docker-login
14
docker-login
|
@ -2,12 +2,18 @@
|
|||
#
|
||||
# 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
|
||||
|
||||
registry=$1
|
||||
username=$2
|
||||
password=$3
|
||||
username=$1
|
||||
password=$2
|
||||
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
|
||||
|
||||
|
|
13
push-all
13
push-all
|
@ -1,15 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Usage: ./push-all <registry-prefix> <image-tag>
|
||||
# Usage: ./push-all <registry> <image-prefix> <image-tag>
|
||||
set -euo pipefail
|
||||
|
||||
registry_prefix=${1:-nixpkgs}
|
||||
image_tag=${2:-latest}
|
||||
registry=${1:-docker.io}
|
||||
image_prefix=${2:-nixpkgs}
|
||||
image_tag=${3:-latest}
|
||||
|
||||
releases_json=$(nix-instantiate ./release.nix --strict --eval --json)
|
||||
|
||||
echo "=== Pushing images to $registry"
|
||||
|
||||
for attr in $(echo "$releases_json" | jq -r "keys[]") ; do
|
||||
file=$(echo "$releases_json" | jq -r ".\"$attr\"")
|
||||
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
|
||||
|
||||
echo OK
|
||||
|
|
43
update-dockerhub
Executable file
43
update-dockerhub
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue