From 3c5720bdb158ede250fbe1037c28f370b038cd0b Mon Sep 17 00:00:00 2001
From: Ulf Seltmann <seltmann@ub.uni-leipzig.de>
Date: Tue, 31 Jul 2018 14:11:16 +0200
Subject: [PATCH] extended gitlab-ci process

---
 .gitlab-ci.yml | 71 +++++++++++++++++++++++++++++++++++++++++++++-----
 Changelog.md   |  4 ++-
 Readme.md      |  6 +++++
 3 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e60ed5b..1f54694 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,15 +1,14 @@
 stages:
-- image
+- build
+- publish
 - mirror
 
-'2.4':
-  stage: image
+docker_build_image_2.4:
+  stage: build
   image: docker:latest
   services:
   - docker:dind
   script: |
-    mkdir -p ~/.docker && echo "$DOCKER_AUTH_CONFIG" >~/.docker/config.json
-    export suffix=`expr $CI_COMMIT_TAG ':' '2.4-\(.*\)'`
     docker build --pull \
       --build-arg HTTP_PROXY=${HTTP_PROXY} \
       --build-arg HTTPS_PROXY=${HTTPS_PROXY} \
@@ -17,9 +16,65 @@ stages:
       --build-arg http_proxy=${HTTP_PROXY} \
       --build-arg https_proxy=${HTTPS_PROXY} \
       --build-arg no_proxy=${NO_PROXY} \
-      -t ubleipzig/httpd:2.4 \
+      -t image \
       -f 2.4/Dockerfile \
       2.4
+    docker save --output=image.tar.gz image
+  artifacts:
+    name: docker-image
+    paths:
+    - image.tar.gz
+  tags:
+  - docker
+
+docker_publish_alpha_2.4:
+  stage: publish
+  image: docker:latest
+  services:
+  - docker:dind
+  script: |
+    test "${DOCKER_AUTH_CONFIG}" == "" && echo "docker-config does not exists, aborting!" && false
+    mkdir -p ~/.docker && echo "$DOCKER_AUTH_CONFIG" >~/.docker/config.json
+    docker load --input=image.tar.gz
+    docker tag image ubleipzig/httpd:alpha-2.4-${CI_COMMIT_REF_NAME}
+    docker push ubleipzig/httpd:alpha-2.4-${CI_COMMIT_REF_NAME}
+  tags:
+  - docker
+  dependencies:
+  - docker_build_image_2.4
+  only:
+  - /^[0-9]+-/
+
+docker_publish_staging_2.4:
+  stage: publish
+  image: docker:latest
+  services:
+  - docker:dind
+  script: |
+    test "${DOCKER_AUTH_CONFIG}" == "" && echo "docker-config does not exists, aborting!" && false
+    mkdir -p ~/.docker && echo "$DOCKER_AUTH_CONFIG" >~/.docker/config.json
+    docker load --input=image.tar.gz
+    docker tag image ubleipzig/httpd:staging
+    docker push ubleipzig/httpd:staging
+  tags:
+  - docker
+  dependencies:
+  - docker_build_image_2.4
+  only:
+  - master
+
+docker_publish_production_2.4:
+  stage: publish
+  image: docker:latest
+  services:
+  - docker:dind
+  script: |
+    test "${DOCKER_AUTH_CONFIG}" == "" && echo "docker-config does not exists, aborting!" && false
+    mkdir -p ~/.docker && echo "$DOCKER_AUTH_CONFIG" >~/.docker/config.json
+    suffix=`expr $CI_COMMIT_TAG ':' '2.4-\(.*\)'`
+
+    docker load --input=image.tar.gz
+    docker tag image ubleipzig/httpd:2.4
     docker push ubleipzig/httpd:2.4
     for tag in "latest" "2" "2.4-${suffix}"; do
       docker tag ubleipzig/httpd:2.4 ubleipzig/httpd:${tag}
@@ -27,8 +82,10 @@ stages:
     done
   tags:
   - docker
+  dependencies:
+  - docker_build_image_2.4
   only:
-  - /^2.4/
+  - /^2.4-/
   except:
   - branches
 
diff --git a/Changelog.md b/Changelog.md
index e67550e..1a95e12 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,6 +1,6 @@
 # Changelog
 
-## 2.4-1 - 2018-07-02
+## [2.4-1] - 2018-07-02
 
 ### Added
 
@@ -8,3 +8,5 @@
 
 ## 2.4-0 - 2018-07-02
 * initial release
+
+[2.4-1]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/docker/httpd/compare/2.4-0...2.4-1
\ No newline at end of file
diff --git a/Readme.md b/Readme.md
index ffd6c0d..a5f20d7 100644
--- a/Readme.md
+++ b/Readme.md
@@ -25,6 +25,12 @@ _this will create a new image with a tag named `2.4-2`. Also the Tags `2.4`, `2`
 
 Only Repository-Masters will be able to create a new Tag.
 
+### Alpha-Images
+Each branch beginning with as number as for merge requests created by gitlab results in an alpha-image named `ubleipzig/httpd:2.4-<branch-name>`. This images are built when the branch is pushed.
+
+### Staging-Images
+When a push to `master` is made gitlab-ci creates an image named `ubleipzig/httpd:2.4-staging`.
+
 ## Contribution
 
 In case you want to contribute please fork and make a pull-request at [Gitlab-hosting of Leipzig University]. This is due to internal policies and the higher flexibility when it comes to build images and push to [Docker-Hub]
-- 
GitLab