From 6050bfc89078b81c53a5154262ac0ec84dfe5c5f Mon Sep 17 00:00:00 2001
From: Julien Leduc <julien.leduc@cern.ch>
Date: Thu, 24 Nov 2016 16:51:59 +0100
Subject: [PATCH] renaming tag according to CTA_BUILD_ID

---
 .gitlab-ci.yml | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 474b679cc1..d3d599c6b4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@ stages:
   - build:srpm
   - build:rpm
   - build:dockerimage
+  - rename:dockerimage
 
 before_script:
   - export CTA_BUILD_ID=${CI_PIPELINE_ID}git${CI_BUILD_REF:0:8}
@@ -56,3 +57,22 @@ ctafrontend_docker:
   variables:
     TO: gitlab-registry.cern.ch/cta/cta-orchestration:${CI_PIPELINE_ID}
     DOCKER_FILE: continuousintegration/docker/ctafrontend/cc7/Dockerfile
+
+
+ctafrontend_docker_rename:
+  stage: rename:dockerimage
+  variables:
+    REPOSITORY: cta/cta-orchestration
+    GITLAB_HOST: gitlab.cern.ch
+  script:
+    - OLDTAG=${CI_PIPELINE_ID}
+    - NEWTAG=${CTA_BUILD_ID}
+    - JWT_PULL_PUSH_TOKEN=$(curl -q -u ${DOCKER_LOGIN_USERNAME}:${DOCKER_LOGIN_PASSWORD} "https://${GITLAB_HOST}/jwt/auth?service=container_registry&scope=repository:${REPOSITORY}:pull,push" | jq .token -r)
+    - echo "List of tags in registry"
+    - curl "https://${CI_REGISTRY}/v2/${REPOSITORY}/tags/list" -H "Authorization: Bearer ${JWT_PULL_PUSH_TOKEN}"
+    - echo "Pulling the manifest of tag:${OLDTAG}"
+    - curl "https://${CI_REGISTRY}/v2/${REPOSITORY}/manifests/${OLDTAG}" -H "Authorization: Bearer ${JWT_PULL_PUSH_TOKEN}" -H 'accept: application/vnd.docker.distribution.manifest.v2+json' > manifest.json
+    - echo "Pushing new tag: ${NEWTAG}"
+    - curl -XPUT "https://${CI_REGISTRY}/v2/${REPOSITORY}/manifests/${NEWTAG}" -H "Authorization: Bearer ${JWT_PULL_PUSH_TOKEN}" -H 'content-type: application/vnd.docker.distribution.manifest.v2+json' -d '@manifest.json' -v
+    - echo "List of tags in registry"
+    - curl "https://${CI_REGISTRY}/v2/${REPOSITORY}/tags/list" -H "Authorization: Bearer ${JWT_PULL_PUSH_TOKEN}"
-- 
GitLab