From 40f33eef9a260583984e9d0f10c260b4fe742688 Mon Sep 17 00:00:00 2001 From: zhenyus Date: Thu, 6 Mar 2025 17:18:12 +0800 Subject: [PATCH] feat(ci): implement conditional git commit in ArgoApplicationVersionUpdater and update container images to ci-essentials:0.0.1 Signed-off-by: zhenyus --- .../ArgoApplicationVersionUpdater.groovy | 31 ++++++++- .../devops/SemanticReleasingExecutor.groovy | 4 +- .../vars/executeFreeleapsPipeline.groovy | 6 +- infra/ci-essentials/Dockerfile | 65 +++++++++++++++++++ 4 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 infra/ci-essentials/Dockerfile diff --git a/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy b/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy index 43eef14f..5b97de77 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy @@ -29,20 +29,45 @@ class ArgoApplicationVersionUpdater { steps.writeYaml(file: valuesFile, data: data, overwrite: true) steps.withCredentials([steps.usernamePassword(credentialsId: 'freeleaps-ops-credentials', passwordVariable: 'OPS_GIT_PASSWORD', usernameVariable: 'OPS_GIT_USERNAME')]) { + // steps.sh """ + // echo "Install required tools for git..." + // apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates gnupg + // echo "Set ${workspace} as a safe directory..." + // git config --global --add safe.directory ${workspace} + // echo "Configure git user..." + // git config user.name "freeleaps-gitops-bot" + // git config user.email "gitops@mathmast.com" + // echo "Add and commit changes..." + // git remote add ci_origin https://${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@dev.azure.com/freeleaps/freeleaps-ops/_git/freeleaps-ops + // git add ${valuesFile} + // git commit -m "ci(bump): bump ${component.name} image version for ${environmentSlug} to ${steps.env.BUILD_IMAGE_VERSION}" + // echo "Push changes to freeleaps-ops repository..." + // git push ci_origin HEAD:master + // echo "Done." + // """ steps.sh """ - echo "Install required tools for git..." - apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates gnupg echo "Set ${workspace} as a safe directory..." git config --global --add safe.directory ${workspace} + echo "Configure git user..." git config user.name "freeleaps-gitops-bot" git config user.email "gitops@mathmast.com" + echo "Add and commit changes..." git remote add ci_origin https://${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@dev.azure.com/freeleaps/freeleaps-ops/_git/freeleaps-ops + git add ${valuesFile} - git commit -m "ci(bump): bump ${component.name} image version for ${environmentSlug} to ${steps.env.BUILD_IMAGE_VERSION}" + + if ! git diff --cached --quiet; then + git commit -m "ci(bump): bump ${component.name} image version for ${environmentSlug} to ${steps.env.BUILD_IMAGE_VERSION}" + echo "Detected changes, commit created." + else + echo "No changes detected, skipping commit." + fi + echo "Push changes to freeleaps-ops repository..." git push ci_origin HEAD:master + echo "Done." """ steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] ${component.name} image version bump to ${steps.env.BUILD_IMAGE_VERSION}") diff --git a/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy b/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy index 450d9bf4..f3111518 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy @@ -27,10 +27,10 @@ class SemanticReleasingExecutor { steps.withCredentials([steps.usernamePassword(credentialsId: credentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { steps.env.GIT_CREDENTIALS = "${steps.env.GIT_USERNAME}:${steps.env.GIT_PASSWORD}" steps.log.info("SemanticReleasingExecutor", "Installing semantic-release requirements...") - steps.sh "apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates curl wget gnupg" + // steps.sh "apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates curl wget gnupg" steps.writeFile file: '.releaserc.json', text: steps.libraryResource(config) steps.log.info("SemanticReleasingExecutor", "Installing semantic-release plugins...") - steps.sh "npm install -g ${plugins.join(' ')}" + // steps.sh "npm install -g ${plugins.join(' ')}" steps.sh "git config --global --add safe.directory ${steps.env.workroot}" steps.env.GIT_LOCAL_BRANCH = "${branch}" steps.sh "semantic-release --debug" diff --git a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy index d311f710..7e190b55 100644 --- a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy +++ b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy @@ -329,7 +329,7 @@ spec: containers: [ containerTemplate( name: 'semantic-releasing', - image: 'node:18-bullseye-slim', + image: 'freeleaps/ci-essentials:0.0.1', ttyEnabled: true, command: 'sleep', args: 'infinity' @@ -600,7 +600,7 @@ spec: containers: [ containerTemplate( name: "argo-app-version-updater", - image: "debian:12", + image: "freeleaps/ci-essentials:0.0.1", ttyEnabled: true, command: 'sleep', args: 'infinity' @@ -673,7 +673,7 @@ spec: effect: "NoSchedule" containers: - name: commit-message-linter - image: docker.io/commitlint/commitlint:master + image: docker.io/freeleaps/ci-essentials:0.0.1 command: - cat tty: true diff --git a/infra/ci-essentials/Dockerfile b/infra/ci-essentials/Dockerfile new file mode 100644 index 00000000..8c8f8f53 --- /dev/null +++ b/infra/ci-essentials/Dockerfile @@ -0,0 +1,65 @@ +FROM debian:bookworm + +LABEL version="0.0.1" +LABEL description="Packed with essential tools for Freeleaps DevOps System" +LABEL maintainer="Freeleaps " + +ARG DEBIAN_FRONTEND=noninteractive + +SHELL ["/bin/bash", "-l", "-euxo", "pipefail", "-c"] + +USER root + +# Install essential tools +RUN apt-get update; \ + apt-get full-upgrade -y; \ + apt-get install -y --no-install-recommends \ + git \ + curl \ + wget \ + unzip \ + vim \ + nano \ + jq \ + dnsutils \ + net-tools \ + iputils-ping \ + iproute2 \ + telnet \ + openssh-client \ + bash \ + ca-certificates \ + ; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +ENV NVM_DIR=/usr/local/nvm + +# Install nvm to management node versions +RUN mkdir -p "$NVM_DIR"; \ + curl -o- \ + "https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh" | \ + bash \ + ; \ + source $NVM_DIR/nvm.sh; \ + nvm install --lts --latest-npm + +# Add node and npm to path so the commands are available +ENV NODE_PATH=$NVM_DIR/v$NODE_VERSION/lib/node_modules +ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH + +# Install semantic release and conventional commits cli +RUN npm install -g \ + semantic-release \ + @semantic-release/changelog \ + @semantic-release/git \ + @semantic-release/exec \ + @semantic-release/release-notes-generator \ + conventional-changelog-conventionalcommits \ + @commitlint/cli \ + @commitlint/config-conventional \ + @commitlint/config-angular + +RUN mkdir -p /workspace +WORKDIR /workspace +USER root