From 87c0425c83a48dd87dbf89be2610c7fdee506580 Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Fri, 19 Jan 2024 08:29:57 +0100
Subject: [PATCH] Release complete set of image

---
 .gitlab-ci.yml | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 03f9812..6ff1924 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -92,7 +92,7 @@ container_scanning:
     CS_IMAGE: $GITLAB_OPENTOFU_IMAGE_NAME
     CS_SCHEMA_MODEL: 15
 
-gitlab-opentofu-image:deploy:
+gitlab-opentofu-image:deploy:with-opentofu-version:
   extends: .opentofu-versions
   stage: deploy
   image:
@@ -112,7 +112,23 @@ gitlab-opentofu-image:deploy:
   rules:
     - if: $CI_COMMIT_TAG
 
-gitlab-opentofu-image:latest:deploy:
+gitlab-opentofu-image:deploy:latest-with-opentofu-version:
+  extends: .opentofu-versions
+  stage: deploy
+  image:
+    name: gcr.io/go-containerregistry/crane:debug
+    entrypoint: [""]
+  variables:
+    RELEASE_IMAGE_NAME: "$CI_REGISTRY_IMAGE/gitlab-opentofu"
+    RELEASE_SEMVER: "latest-opentofu${OPENTOFU_VERSION}"
+  before_script:
+    - crane auth login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
+  script:
+    - crane copy "$GITLAB_OPENTOFU_IMAGE_NAME" "$RELEASE_IMAGE_NAME:$RELEASE_SEMVER"
+  rules:
+    - if: $CI_COMMIT_TAG
+
+gitlab-opentofu-image:deploy:latest:
   stage: deploy
   image:
     name: gcr.io/go-containerregistry/crane:debug
@@ -129,8 +145,8 @@ gitlab-opentofu-image:latest:deploy:
   parallel:
     matrix:
       - RELEASE_IMAGE_TAG: ${CI_COMMIT_TAG}
-      - RELEASE_IMAGE_TAG: ${CI_COMMIT_TAG}-opentofu
       - RELEASE_IMAGE_TAG: ${CI_COMMIT_TAG}-opentofulatest
+      - RELEASE_IMAGE_TAG: latest-opentofulatest
       - RELEASE_IMAGE_TAG: latest
 
 # If the pipeline is for a new tag with a semantic version, and all previous jobs succeed,
-- 
GitLab