From 6b2e830b6a3f04b5829c4c20826ee1091d69f1f0 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Fri, 29 May 2020 01:16:24 +0200
Subject: [PATCH] Add test for container image

Currently we just build time image before sending it out to production.
This new step should do some basic integration testing before actually
publishing the image.
---
 .gitlab-ci.yml | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cb9b434..7d205d7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,10 +1,37 @@
 include:
   local: /gitlab-ci-template.yml
 
+stages:
+  - build
+  - test
+  - tag
+
 variables:
   CI_REGISTRY_IMAGE_VERSION: "1.1.0"
   CI_REGISTRY_BUILD_ARG: "--build-arg 0.2.0"
 
+
+container-test:
+  stage: test
+  inherit:
+    default: false
+    variables:
+      - CI_REGISTRY
+      - CI_REGISTRY_USER
+      - CI_REGISTRY_PASSWORD
+      - CI_REGISTRY_IMAGE
+      - CI_REGISTRY_BUILD_ARGS
+  image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
+  before_script:
+    - podman login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+  script:
+    - podman build --pull $CI_REGISTRY_BUILD_ARGS -t "build-image:test" .
+    - si-tagging -l "build-image:test" "example.com/tagging-image" "0.1.2.3"
+    - podman images --format "{{.Repository}}:{{.Tag}}" | grep -Pe "^example.com/tagging-image:0.1.2$"
+    - podman images --format "{{.Repository}}:{{.Tag}}" | grep "latest"
+    - podman images --format "{{.Repository}}:{{.Tag}}" | grep -Pe "^example.com/tagging-image:0$"
+
+
 container-tagging:
   only:
     - master
-- 
GitLab