From 9a91b51b8d8e2b3b2a6fc24ed342f47e3fedd212 Mon Sep 17 00:00:00 2001
From: Matt Kasa <mkasa@gitlab.com>
Date: Tue, 4 Aug 2020 16:53:39 -0700
Subject: [PATCH] fix: Update stable:latest tag based on STABLE_VERSION

---
 .gitlab-ci.yml  | 4 ++++
 CONTRIBUTING.md | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a826030..0a2cb93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,6 @@
 variables:
+  STABLE_VERSION: "0.12"
+  STABLE_IMAGE_NAME: "$CI_REGISTRY_IMAGE/stable:latest"
   BUILD_IMAGE_NAME: "$CI_REGISTRY_IMAGE/branches/$CI_COMMIT_REF_SLUG-$TERRAFORM_VERSION:$CI_COMMIT_SHA"
   RELEASE_IMAGE_NAME: "$CI_REGISTRY_IMAGE/releases/$TERRAFORM_VERSION"
   TF_ADDRESS: "$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$CI_JOB_ID"
@@ -48,6 +50,8 @@ stages:
     - docker image tag "$BUILD_IMAGE_NAME" "$RELEASE_IMAGE_NAME:$CI_COMMIT_TAG"
     - docker image push "$RELEASE_IMAGE_NAME:latest"
     - docker image push "$RELEASE_IMAGE_NAME:$CI_COMMIT_TAG"
+    - if [ "$TERRAFORM_VERSION" = "$STABLE_VERSION" ]; then docker image tag "$BUILD_IMAGE_NAME" "$STABLE_IMAGE_NAME"; fi
+    - if [ "$TERRAFORM_VERSION" = "$STABLE_VERSION" ]; then docker image push "$STABLE_IMAGE_NAME"; fi
 
   only:
     - tags
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9a48548..040eee1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -22,3 +22,11 @@ an empty commit sumarizing your changes like so:
 
 ```
 git commit --allow-empty -m '[BREAKING CHANGE|feat|fix]: <changelog summary message
+
+### Stable tag
+
+This project updates a `stable:latest` tag in the container registry which
+tracks the latest build of the image specified in `STABLE_VERSION` in
+`.gitlab-ci.yml`. Simply update this to reflect what version series is
+considered stable by upstream and the `stable:latest` tag will be updated
+automatically.
-- 
GitLab