From 5caa335b94c4b94de46db703230b7e32de2e6607 Mon Sep 17 00:00:00 2001
From: Matthew Defenderfer <mdefende@uab.edu>
Date: Wed, 24 Apr 2024 14:36:27 -0500
Subject: [PATCH] trying something new

---
 .gitlab-ci.yml | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e09c422..ed08dec 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,14 +1,26 @@
-job:
-  tags:
-    - test
-
-stages:
-  - build
-
-build:
+docker-build:
+  # Use the official docker image.
+  image: docker:stable
   stage: build
+  services:
+    - docker:26.0.1-dind
+  variables:
+    DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
+    DOCKER_TLS_CERTDIR: "/certs"
+  before_script:
+    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+  # All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
+  # Default branch is also tagged with `latest`
   script:
-    - docker build -t test:latest .
-  only:
-    changes:
-      - Dockerfile
\ No newline at end of file
+    - docker build --pull -t "$DOCKER_IMAGE_NAME" .
+    - docker push "$DOCKER_IMAGE_NAME"
+    - |
+      if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
+        docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest"
+        docker push "$CI_REGISTRY_IMAGE:latest"
+      fi
+  # Run this job in a branch where a Dockerfile exists
+  rules:
+    - if: $CI_COMMIT_BRANCH
+      exists:
+        - Dockerfile
-- 
GitLab