Skip to content

Commit

Permalink
Adopt a generic CI script
Browse files Browse the repository at this point in the history
  • Loading branch information
ndejong committed May 15, 2024
1 parent a216137 commit e586fa5
Showing 1 changed file with 74 additions and 5 deletions.
79 changes: 74 additions & 5 deletions .gitlab/ci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,105 @@

image: docker:23.0
image: docker:latest

variables:
RUNNER_INFRASTRUCTURE: "gitlab-org-docker"

services:
- name: docker:23.0-dind
- name: docker:dind
alias: docker

sast:
stage: analysis

include:
- template: Security/SAST.gitlab-ci.yml

stages:
- build
- analysis

# =============================================================================

build_dev:
stage: build

rules:
- if: $CI_COMMIT_BRANCH == 'dev'

tags:
- "${RUNNER_INFRASTRUCTURE}"

before_script:
- export BUILD_TAG="$(date -u +%Y%m%d%H%M%Sz)-${CI_COMMIT_SHORT_SHA}"
- export COMMIT_REF="${CI_COMMIT_BRANCH}"
- export COMMIT_HASH="${CI_COMMIT_SHORT_SHA}"
- export BUILD1_NAME="${CI_REGISTRY_IMAGE}/${CI_COMMIT_BRANCH}"

script:
- |
echo "BUILD_TAG=${BUILD_TAG}"
echo "BUILD1_NAME=${BUILD1_NAME}"
echo "BUILD2_NAME=${BUILD2_NAME}"
echo "COMMIT_REF=${COMMIT_REF}"
echo "COMMIT_HASH=${COMMIT_HASH}"
echo "COMMIT_TAG=${CI_COMMIT_TAG}"
- |
docker build \
--pull \
--label "commit=${COMMIT_HASH}" \
--tag "${BUILD1_NAME}:${BUILD_TAG}" \
--tag "${BUILD1_NAME}:latest" \
--build-arg COMMIT_REF=${COMMIT_REF} \
--build-arg COMMIT_HASH=${COMMIT_HASH} .
echo "${CI_REGISTRY_PASSWORD}" | docker login --password-stdin -u "${CI_REGISTRY_USER}" "${CI_REGISTRY}"
docker push "${BUILD1_NAME}:${BUILD_TAG}"
docker push "${BUILD1_NAME}:latest"
docker logout
# =============================================================================

build_tagged:
stage: build

rules:
- if: $CI_COMMIT_TAG =~ /v?(\d+\.)?(\d+\.)?(\*|\d+)(\+.*?)?$/
- if: $CI_COMMIT_TAG =~ /^v?(\d+\.)?(\d+\.)?(\*|\d+)(\+.*?)?$/

tags:
- "gitlab-org-docker"
- "${RUNNER_INFRASTRUCTURE}"

before_script:
- export BUILD_TAG="$(echo ${CI_COMMIT_TAG} | tr '+' '-')"
- export BUILD_TAG="${CI_COMMIT_TAG}"
- export COMMIT_REF="${CI_COMMIT_TAG}"
- export COMMIT_HASH="${CI_COMMIT_SHORT_SHA}"
- export BUILD1_NAME="${CI_REGISTRY_IMAGE}"
- export BUILD2_NAME="${DOCKERHUB_REGISTRY}/${DOCKERHUB_USERNAME}/${CI_PROJECT_NAME//docker-}"

script:
- |
echo "BUILD_TAG=${BUILD_TAG}"
echo "BUILD1_NAME=${BUILD1_NAME}"
echo "BUILD2_NAME=${BUILD2_NAME}"
echo "COMMIT_REF=${COMMIT_REF}"
echo "COMMIT_HASH=${COMMIT_HASH}"
echo "COMMIT_TAG=${CI_COMMIT_TAG}"
- |
docker build \
--pull \
--label "commit=${COMMIT_HASH}" \
--tag "${BUILD1_NAME}:${BUILD_TAG}" \
--tag "${BUILD1_NAME}:latest" \
--build-arg COMMIT_REF=${COMMIT_REF} \
--build-arg COMMIT_HASH=${COMMIT_HASH} .
echo "${CI_REGISTRY_PASSWORD}" | docker login --password-stdin -u "${CI_REGISTRY_USER}" "${CI_REGISTRY}"
docker push "${BUILD1_NAME}:${BUILD_TAG}"
docker push "${BUILD1_NAME}:latest"
docker logout
- |
docker build \
--pull \
--label "commit=${COMMIT_HASH}" \
Expand Down

0 comments on commit e586fa5

Please sign in to comment.