Commit 2d7a5810 authored by Louis Gesbert's avatar Louis Gesbert
Browse files

Publish to Docker hub as a separate task

parent c256bbee
Pipeline #12434 failed with stages
in 39 seconds
stages:
- build
- publish
make-targets:
stage: .pre
image: alpine:3.11
......@@ -6,13 +10,13 @@ make-targets:
- curl https://api.github.com/repos/ocaml/ocaml/releases
| jq -r 'map(.tag_name | split(".") | {"maj":.[0:2], "pat":.}) | group_by(.maj) | .[] | max | .pat | join(".")'
| tail -n +3
> versions
> ocaml-versions
- curl https://api.github.com/repos/ocaml/opam/releases
| jq -r 'map(.tag_name | split(".") | {"maj":.[0:2], "pat":.}) | group_by(.maj) | .[] | max | .pat | join(".")'
| tail -n 1
> opam-version
- |
{ for v in $(cat versions); do
{ for v in $(cat ocaml-versions); do
echo "ocaml-image-$v:";
echo " extends: .ocaml-image";
echo " variables:";
......@@ -20,12 +24,13 @@ make-targets:
echo;
done;
echo "variables:";
echo " LATEST_OCAML_VERSION: $(tail -n1 versions)";
echo " LATEST_OCAML_VERSION: $(tail -n1 ocaml-versions)";
echo " OPAM_VERSION: $(cat opam-version)";
} > ocaml-images.yml
artifacts:
paths:
- ocaml-images.yml
- ocaml-versions
build-images:
stage: build
......@@ -37,3 +42,40 @@ build-images:
strategy: depend
only:
- master
publish-docker:
stage: publish
image: docker:latest
variables:
DOCKERHUB_IMAGE: ocamlpro/ocaml
before_script:
- |
echo "{
\"auths\": {
\"$CI_REGISTRY\": {
\"username\":\"$CI_REGISTRY_USER\",
\"password\":\"$CI_REGISTRY_PASSWORD\"
},
\"https://index.docker.io/v1/\": {
\"auth\":\"$DOCKERHUB_AUTH\"
}
}
}" > /root/.docker/config.json
script:
- for OCAML_VERSION in $(cat ocaml-versions); do
BASETAG=${OCAML_VERSION%.*}-$(date +%F);
SRC_IMG=$CI_REGISTRY_IMAGE:$BASETAG;
docker pull $SRC_IMG;
for TAG in
${BASETAG}
${OCAML_VERSION}
${OCAML_VERSION%.*}
$([ "$OCAML_VERSION" = $(tail -n1 ocaml-versions) ] && echo "latest")
; do
docker tag $SRC_IMG $DOCKERHUB_IMAGE:${TAG};
docker push $DOCKERHUB_IMAGE:${TAG};
done;
docker rmi $SRC_IMG
done
only:
- master
......@@ -3,8 +3,6 @@
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
DOCKERHUB_IMAGE: ocamlpro/ocaml
script:
- |
echo "{
......@@ -12,12 +10,7 @@
\"$CI_REGISTRY\": {
\"username\":\"$CI_REGISTRY_USER\",
\"password\":\"$CI_REGISTRY_PASSWORD\"
},
\"https://index.docker.io/v1/\": {
\"auth\":\"$DOCKERHUB_AUTH\"
}
}
}" > /kaniko/.docker/config.json
}}}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=true
--context=$CI_PROJECT_DIR
--dockerfile=$CI_PROJECT_DIR/Dockerfile
......@@ -25,16 +18,10 @@
--build-arg=OCAML_VERSION=$OCAML_VERSION
--build-arg=LAST_REPO_UPDATE=$(date +%s)
--destination=$CI_REGISTRY_IMAGE:${OCAML_VERSION%.*}-$(date +%F)
--destination=$CI_REGISTRY_IMAGE:${OCAML_VERSION%.*}
--destination=$CI_REGISTRY_IMAGE:${OCAML_VERSION}
--destination=$CI_REGISTRY_IMAGE:${OCAML_VERSION%.*}
$(if [ "$OCAML_VERSION" = "$LATEST_OCAML_VERSION" ]; then
echo "--destination=$CI_REGISTRY_IMAGE:latest";
fi)
--destination=$DOCKERHUB_IMAGE:${OCAML_VERSION%.*}-$(date +%F)
--destination=$DOCKERHUB_IMAGE:${OCAML_VERSION%.*}
--destination=$DOCKERHUB_IMAGE:${OCAML_VERSION}
$(if [ "$OCAML_VERSION" = "$LATEST_OCAML_VERSION" ]; then
echo "--destination=$DOCKERHUB_IMAGE:latest";
fi)
only:
- master
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment