From 6306fbc960bea657516d6961301b10961abb575f Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 14:41:25 +0530 Subject: [PATCH 1/9] deploy pipeline in gitlab --- .../setup-deploy-pipeline.asciidoc | 6 + .../setup-deploy-pipeline.asciidoc | 66 +++ .../src/gitlab/setup-deploy-pipeline.asciidoc | 6 + .../pipelines/common/pipeline_generator.lib | 393 ++++++++---------- .../pipelines/gitlab/pipeline_generator.sh | 188 +++++++++ .../gitlab/templates/common/.gitlab-ci.yml | 19 + .../templates/deploy/deploy-pipeline.cfg | 29 ++ .../deploy/deploy-pipeline.yml.template | 78 ++++ .../gitlab/templates/deploy/deploy.sh | 22 + .../gitlab/templates/deploy/secrets.sh | 11 + 10 files changed, 592 insertions(+), 226 deletions(-) create mode 100644 documentation/src/azure-devops/setup-deploy-pipeline.asciidoc create mode 100644 documentation/src/common_templates/setup-deploy-pipeline.asciidoc create mode 100644 documentation/src/gitlab/setup-deploy-pipeline.asciidoc create mode 100644 scripts/pipelines/gitlab/pipeline_generator.sh create mode 100644 scripts/pipelines/gitlab/templates/common/.gitlab-ci.yml create mode 100644 scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.cfg create mode 100644 scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template create mode 100644 scripts/pipelines/gitlab/templates/deploy/deploy.sh create mode 100644 scripts/pipelines/gitlab/templates/deploy/secrets.sh diff --git a/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc b/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..b7a58985b --- /dev/null +++ b/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc @@ -0,0 +1,6 @@ +:provider: Azure Devops +:pipeline_type: Pipeline +:trigger_sentence: +:pipeline_type2: pipeline +:path_provider: azure-devops +include::../common_templates/setup-deploy-pipeline.asciidoc[] \ No newline at end of file diff --git a/documentation/src/common_templates/setup-deploy-pipeline.asciidoc b/documentation/src/common_templates/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..966abcdac --- /dev/null +++ b/documentation/src/common_templates/setup-deploy-pipeline.asciidoc @@ -0,0 +1,66 @@ += Setting up a Deploy Pipeline on Azure DevOps + +In this section we will create a deploy pipeline on Azure DevOps to deploy the project application on an already provisioned Kubernetes cluster. This pipeline will be configured in order to be triggered every time package pipeline is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package pipeline has passed. By default, it depends on the environment provisioning pipeline being successfully run on beforehand and, depending on the Kubernetes provider, it consumes the artifact produced by that. It also consumes variable groups created by package and environment provisioning pipelines. + +The creation of the pipeline will follow the project workflow, so a new branch named `feature/deploy-pipeline` will be created and the YAML file for the pipeline will be pushed to it. + +Then, a Pull Request (PR) will be created in order to merge the new branch into the appropriate branch (provided in `-b` flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using `-w` flag. + +The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` will automatically create the new branch, create a deploy pipeline based on a YAML template appropriate for the project manifests files, create the Pull Request, and if it is possible, merge this new branch into the specified branch. + +== Prerequisites + +* This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with `git pull`). + +* The YAML containing Deployment object should be named `application-deployment.yaml` for allowing automated `imagePullSecret` injection. + +== Creating the pipeline using provided script + +=== Usage +``` +pipeline_generator.sh \ + -c \ +ifdef::trigger_sentence_azure,trigger_sentence_github[ -n \] + -d \ +ifdef::trigger_sentence_azure,trigger_sentence_github[ --package-pipeline-name \] +ifdef::trigger_sentence_azure,trigger_sentence_github[ --env-provision-pipeline-name \] + --k8s-provider \ + --k8s-namespace \ + --k8s-deploy-files-path \ + [--k8s-image-pull-secret-name ] \ + [-b ] \ + [-w] +``` +NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines/azure-devops/templates/deploy/deploy-pipeline.cfg`. + +=== Flags +``` +-c --config-file [Required] Configuration file containing pipeline definition. +ifdef::trigger_sentence_azure,trigger_sentence_github[-n --pipeline-name [Required] Name that will be set to the pipeline.] +-d --local-directory [Required] Local directory of your project. +ifdef::trigger_sentence_azure,trigger_sentence_github[ --package-pipeline-name [Required] Package pipeline name.] +ifdef::trigger_sentence_azure,trigger_sentence_github[ --env-provision-pipeline-name [Required] Environment provisioning pipeline name.] + --k8s-provider [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS. + --k8s-namespace [Required] Kubernetes namespace where the application will be deployed. + --k8s-deploy-files-path [Required] Path from the root of the project to the YAML manifests directory. + --k8s-image-pull-secret-name Name for the generated secret containing registry credentials. Required when using a private registry to host images. +-b --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided. +-w Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag. +``` + +=== Examples + +``` +ifdef::trigger_sentence_azure,trigger_sentence_github[ ./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -n quarkus-project-deploy -d C:/Users/$USERNAME/Desktop/quarkus-project --package-pipeline-name quarkus-project-package --env-provision-pipeline-name eks-provisioning --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop -w] + +ifdef::trigger_sentence_gitlab[ ./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -d C:/Users/$USERNAME/Desktop/quarkus-project --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop -w] +``` + + +=== Appendix: accessing the application + +Once the pipeline is executed and your application is deployed, you can list the hostname to access it with: + +``` +kubectl get ingress -n +``` diff --git a/documentation/src/gitlab/setup-deploy-pipeline.asciidoc b/documentation/src/gitlab/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..d80bfdbd1 --- /dev/null +++ b/documentation/src/gitlab/setup-deploy-pipeline.asciidoc @@ -0,0 +1,6 @@ +:provider: Gitlab +:pipeline_type: pipeline +:trigger_sentence: +:pipeline_type2: Gitlab pipeline +:path_provider: gitlab +include::../common_templates/setup-deploy-pipeline.asciidoc[] \ No newline at end of file diff --git a/scripts/pipelines/common/pipeline_generator.lib b/scripts/pipelines/common/pipeline_generator.lib index 55ca0e296..22b4f329f 100644 --- a/scripts/pipelines/common/pipeline_generator.lib +++ b/scripts/pipelines/common/pipeline_generator.lib @@ -1,226 +1,167 @@ -#!/bin/bash -function help { - echo "" - echo "Generates a $pipeline_type on $provider based on the given definition." - echo "" - echo "Common flags:" - echo " -c, --config-file [Required] Configuration file containing $pipeline_type definition." - echo " -n, --pipeline-name [Required] Name that will be set to the $pipeline_type." - echo " -d, --local-directory [Required] Local directory of your project." - echo " -a, --artifact-path Path to be persisted as an artifact after $pipeline_type execution, e.g. where the application stores logs or any other blob on runtime." - echo " -b, --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided." - echo " -w Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag." - echo "" - echo "Build $pipeline_type flags:" - echo " -l, --language [Required] Language or framework of the project." - echo " -t, --target-directory Target directory of build process. Takes precedence over the language/framework default one." - echo "" - echo "Test $pipeline_type flags:" - echo " -l, --language [Required] Language or framework of the project." - [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build $pipeline_type name." - echo "" - echo "Quality $pipeline_type flags:" - echo " -l, --language [Required] Language or framework of the project." - echo " --sonar-url [Required] Sonarqube URL." - echo " --sonar-token [Required] Sonarqube token." - [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build $pipeline_type name." - [ "$provider" == "azure-devops" ] && echo " --test-pipeline-name [Required] Test $pipeline_type name." - echo "" - [ "$provider" == "github" ] && echo "" - [ "$provider" == "github" ] && echo "CI pipeline flags" - [ "$provider" == "github" ] && echo " --build-pipeline-name [Required] Name of the job calling the build $pipeline_type." - [ "$provider" == "github" ] && echo " --test-pipeline-name Name of the job calling the test $pipeline_type." - [ "$provider" == "github" ] && echo " --quality-pipeline-name Name of the job calling the quality $pipeline_type." - [ "$provider" == "github" ] && echo "" - echo "Package pipeline flags:" - echo " -l, --language [Required, if dockerfile not set] Language or framework of the project." - echo " --dockerfile [Required, if language not set] Path from the root of the project to its Dockerfile. Takes precedence over the language/framework default one." - [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build $pipeline_type name." - [ "$provider" == "azure-devops" ] && echo " --quality-pipeline-name [Required] Quality $pipeline_type name." - [ "$provider" == "github" ] && echo " --ci-pipeline-name [Required] CI $pipeline_type name." - echo " -i, --image-name [Required] Name (excluding tag) for the generated container image." - echo " -u, --registry-user [Required, unless AWS] Container registry login user." - echo " -p, --registry-password [Required, unless AWS] Container registry login password." - echo " --aws-access-key [Required, if AWS] AWS account access key ID. Takes precedence over registry credentials." - echo " --aws-secret-access-key [Required, if AWS] AWS account secret access key." - echo " --aws-region [Required, if AWS] AWS region for ECR." - echo "" - echo "Library package $pipeline_type flags:" - echo " -l, --language [Required] Language or framework of the project." - echo "" - echo "Azure AKS provisioning $pipeline_type flags:" - echo " --resource-group [Required] Name of the resource group for the cluster." - echo " --storage-account [Required] Name of the storage account for the cluster." - echo " --storage-container [Required] Name of the storage container where the Terraform state of the cluster will be stored." - echo " --rancher Install Rancher to manage the cluster." - echo "" - echo "AWS EKS provisioning $pipeline_type flags:" - echo " --cluster-name [Required] Name for the cluster." - echo " --s3-bucket [Required] Name of the S3 bucket where the Terraform state of the cluster will be stored." - echo " --s3-key-path [Required] Path within the S3 bucket where the Terraform state of the cluster will be stored." - echo " --aws-access-key [Required, on first run] AWS account access key ID." - echo " --aws-secret-access-key [Required, on first run] AWS account secret access key." - echo " --aws-region [Required, on first run] AWS region for provisioning resources." - - echo " --rancher Install Rancher to manage the cluster." - echo "" - echo "Deploy $pipeline_type flags:" - echo "" - echo " --package-pipeline-name [Required] Package $pipeline_type name." - echo " --env-provision-pipeline-name [Required] Environment provisioning $pipeline_type name." - echo " --k8s-provider [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS." - echo " --k8s-namespace [Required] Kubernetes namespace where the application will be deployed." - echo " --k8s-deploy-files-path [Required] Path from the root of the project to the YAML manifests directory." - echo " --k8s-image-pull-secret-name Name for the generated secret containing registry credentials. Required when using a private registry to host images." - echo "" - - exit -} - -function validateRegistryLoginCredentials { - # if the user chose to push to a registry and the user has not already given a password - # then prompt the user - if [ -v dockerUser ] && [ ! -v dockerPassword ] - then - read -rsp "Please enter Docker registry password..." dockerPassword - fi - - if [ -v awsRegion ] && [ -v awsAccessKey ] && [ ! -v awsSecretAccessKey ] - then - read -rsp "Please enter AWS secret access key..." awsSecretAccessKey - fi -} - -function ensurePathFormat { - currentDirectory=$(pwd) - - # When necessary, converts a relative path into an absolute path, and a Windows-style path (e.g. "C:\Users" or C:/Users) into a - # Unix-style path using forward slashes (e.g. "/c/Users"). - localDirectory=${localDirectory//'\'/"/"} - cd "${localDirectory}" || { echo -e "${red}Error: Local directory '${localDirectory}' does not exist. Check provided path (missing quotes?)."; exit 1; } - localDirectory=$(pwd) - - # Return to initial directory - cd "$currentDirectory" -} - -function importConfigFile { - # Import config file. - source $configFile - IFS=, read -ra flags <<< "$mandatoryFlags" - - # Check if the config file was supplied. - if test -z "$configFile" - then - echo -e "${red}Error: $pipeline_type definition configuration file not specified." >&2 - exit 2 - fi - - # Check if the required flags in the config file have been activated. - for flag in "${flags[@]}" - do - if test -z $flag - then - echo -e "${red}Error: Missing parameters, some flags are mandatory." >&2 - echo -e "${red}Use -h or --help flag to display help." >&2 - exit 2 - fi - done -} - -function checkInstallations { - # Check if Git is installed - if ! [ -x "$(command -v git)" ]; then - echo -e "${red}Error: Git is not installed." >&2 - exit 127 - fi - - # Check if the CLI tool for the provider is installed - if ([ "$provider" == "github" ] && ! [ -x "$(command -v gh)" ]); then - echo -e "${red}Error: Github CLI is not installed." >&2 - exit 127 - elif ([ "$provider" == "azure-devops" ] && ! [ -x "$(command -v az)" ]); then - echo -e "${red}Error: Azure CLI is not installed." >&2 - exit 127 - fi - - # Check if Python is installed - if ! [ -x "$(command -v python)" ]; then - echo -e "${red}Error: Python is not installed." >&2 - exit 127 - fi -} - -function createNewBranch { - echo -e "${green}Creating the new branch: ${sourceBranch}..." - echo -ne ${white} - - # Create the new branch. - cd "${localDirectory}" - git checkout -b ${sourceBranch} -} - -function copyYAMLFile { - echo -e "${green}Copying the corresponding files into your directory..." - echo -ne ${white} - - # Create .pipelines and scripts if they do not exist. - mkdir -p "${localDirectory}/$scriptFilePath" - - # Generate pipeline YAML from template and put it in the repository. - # We cannot use a variable in the definition of resource in the pipeline so we have to use a placeholder to replace it with the value we need - commonEnvSubstList='${buildPipelineName} ${testPipelineName} ${qualityPipelineName} ${pipelineName} ${ciPipelineName} ${packagePipelineName}' - envsubst "${commonEnvSubstList} ${specificEnvSubstList}" < "${hangarPath}/${templatesPath}/${yamlFile}.template" > "${localDirectory}/${pipelinePath}/${yamlFile}" - - # Check if an extra artifact to store is supplied. - if test ! -z "$artifactPath" - then - # Add the extra step to the YAML. - if [ "$provider" == "azure-devops" ] - then - cat "${hangarPath}/${commonTemplatesPath}/store-extra-path.yml" >> "${localDirectory}/${pipelinePath}/${yamlFile}" - elif [ "$provider" == "github" ] - then - storeExtraPathContent="\n - name: Publish Additional Output Artifact\n uses: actions\/upload-artifact@v3\n with:\n name: additional-pipeline-output\n path: \"\${{ env.artifactPath }}\"" - sed -i "s/# mark to insert step for additonal artifact #/$storeExtraPathContent\n/" "${localDirectory}/${pipelinePath}/${yamlFile}" - fi - else - if [ "$provider" == "github" ] - then - sed -i '/# mark to insert step for additonal artifact #/d' "${localDirectory}/${pipelinePath}/${yamlFile}" - fi - fi -} - -function copyCommonScript { - echo -e "${green}Copying the script(s) common to any $pipeline_type files into your directory..." - echo -ne ${white} - - ! (ls "${hangarPath}/${commonTemplatesPath}"/*.sh) &> /dev/null || cp "${hangarPath}/${commonTemplatesPath}"/*.sh "${localDirectory}/${scriptFilePath}" -} - -function commitCommonFiles { - echo -e "${green}Commiting and pushing into Git remote..." - echo -ne ${white} - - # Move into the project's directory and pushing the template into the Azure DevOps repository. - cd "${localDirectory}" - - # Add the YAML files. - git add "$pipelinePath" -f - - # Git commit and push it into the repository. - # changing all files to be executable - find "$pipelinePath" -type f -name '*.sh' -exec git update-index --chmod=+x {} \; - - git commit -m "Adding the source YAML" - git push -u origin ${sourceBranch} -} - -function setTargetDirectory { - case $language in - node | angular) targetDirectory="./" ;; - quarkus*) targetDirectory="./target/" ;; - *) echo -e "${red}Error: Specified language '${language}' is not supported." >&2; exit 1 - esac -} +#!/bin/bash +function help { + echo "" + echo "Generates a pipeline on $provider based on the given definition." + echo "" + echo "Common flags:" + echo " -c, --config-file [Required] Configuration file containing pipeline definition." + echo " -n, --pipeline-name [Required] Name that will be set to the pipeline." + echo " -d, --local-directory [Required] Local directory of your project." + echo " -a, --artifact-path Path to be persisted as an artifact after pipeline execution, e.g. where the application stores logs or any other blob on runtime." + echo " -b, --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided." + echo " -w Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag." + echo "" + echo "Build pipeline flags:" + echo " -l, --language [Required] Language or framework of the project." + echo " -t, --target-directory Target directory of build process. Takes precedence over the language/framework default one." + echo "" + echo "Test pipeline flags:" + echo " -l, --language [Required] Language or framework of the project." + [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build pipeline name." + echo "" + echo "Quality pipeline flags:" + echo " -l, --language [Required] Language or framework of the project." + echo " --sonar-url [Required] Sonarqube URL." + echo " --sonar-token [Required] Sonarqube token." + [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build pipeline name." + [ "$provider" == "azure-devops" ] && echo " --test-pipeline-name [Required] Test pipeline name." + echo "" + echo "Package pipeline flags:" + echo " -l, --language [Required, if dockerfile not set] Language or framework of the project." + echo " --dockerfile [Required, if language not set] Path from the root of the project to its Dockerfile. Takes precedence over the language/framework default one." + [ "$provider" == "azure-devops" ] && echo " --build-pipeline-name [Required] Build pipeline name." + echo " --quality-pipeline-name [Required] Quality pipeline name." + echo " -i, --image-name [Required] Name (excluding tag) for the generated container image." + echo " -u, --registry-user [Required, unless AWS] Container registry login user." + echo " -p, --registry-password [Required, unless AWS] Container registry login password." + echo " --aws-access-key [Required, if AWS] AWS account access key ID. Takes precedence over registry credentials." + echo " --aws-secret-access-key [Required, if AWS] AWS account secret access key." + echo " --aws-region [Required, if AWS] AWS region for ECR." + echo "" + echo "Library package pipeline flags:" + echo " -l, --language [Required] Language or framework of the project." + echo "" + echo "Deploy pipeline flags:" + echo "" + echo "Azure AKS provisioning pipeline flags:" + echo " --resource-group [Required] Name of the resource group for the cluster." + echo " --storage-account [Required] Name of the storage account for the cluster." + echo " --storage-container [Required] Name of the storage container where the Terraform state of the cluster will be stored." + echo "" + echo "AWS EKS provisioning pipeline flags:" + echo " --cluster-name [Required] Name for the cluster." + echo " --s3-bucket [Required] Name of the S3 bucket where the Terraform state of the cluster will be stored." + echo " --s3-key-path [Required] Path within the S3 bucket where the Terraform state of the cluster will be stored." + + exit +} + +function ensurePathFormat { + currentDirectory=$(pwd) + + # When necessary, converts a relative path into an absolute path, and a Windows-style path (e.g. "C:\Users" or C:/Users) into a + # Unix-style path using forward slashes (e.g. "/c/Users"). + localDirectory=${localDirectory//'\'/"/"} + cd "${localDirectory}" || { echo -e "${red}Error: Local directory '${localDirectory}' does not exist. Check provided path (missing quotes?)."; exit 1; } + localDirectory=$(pwd) + + # Return to initial directory + cd "$currentDirectory" +} + +function importConfigFile { + # Import config file. + source $configFile + IFS=, read -ra flags <<< "$mandatoryFlags" + + # Check if the config file was supplied. + if test -z "$configFile" + then + echo -e "${red}Error: Pipeline definition configuration file not specified." >&2 + exit 2 + fi + + # Check if the required flags in the config file have been activated. + for flag in "${flags[@]}" + do + if test -z $flag + then + echo -e "${red}Error: Missing parameters, some flags are mandatory." >&2 + echo -e "${red}Use -h or --help flag to display help." >&2 + exit 2 + fi + done +} + +function checkInstallations { + # Check if Git is installed + if ! [ -x "$(command -v git)" ]; then + echo -e "${red}Error: Git is not installed." >&2 + exit 127 + fi + + # Check if the CLI tool for the provider is installed + if ([ "$provider" == "github" ] && ! [ -x "$(command -v gh)" ]); then + echo -e "${red}Error: Github CLI is not installed." >&2 + exit 127 + elif ([ "$provider" == "azure-devops" ] && ! [ -x "$(command -v az)" ]); then + echo -e "${red}Error: Azure CLI is not installed." >&2 + exit 127 + elif ([ "$provider" == "gitlab" ] && ! [ -x "$(command -v glab)" ]); then + echo -e "${red}Error: Azure CLI is not installed." >&2 + exit 127 + fi + + # Check if Python is installed + if ! [ -x "$(command -v python)" ]; then + echo -e "${red}Error: Python is not installed." >&2 + exit 127 + fi +} + +function createNewBranch { + echo -e "${green}Creating the new branch: ${sourceBranch}..." + echo -ne ${white} + + # Create the new branch. + cd "${localDirectory}" + git checkout -b ${sourceBranch} +} + +function copyYAMLFile { + echo -e "${green}Copying the corresponding files into your directory..." + echo -ne ${white} + + # Create .pipelines and scripts if they do not exist. + mkdir -p "${localDirectory}/$scriptFilePath" + + # Generate pipeline YAML from template and put it in the repository. + # We cannot use a variable in the definition of resource in the pipeline so we have to use a placeholder to replace it with the value we need + commonEnvSubstList='${buildPipelineName} ${testPipelineName} ${qualityPipelineName} ${pipelineName}' + envsubst "${commonEnvSubstList} ${specificEnvSubstList}" < "${hangarPath}/${templatesPath}/${yamlFile}.template" > "${localDirectory}/${pipelinePath}/${yamlFile}" +} + +function copyCommonScript { + echo -e "${green}Copying the script(s) common to any pipeline files into your directory..." + echo -ne ${white} + + ! (ls "${hangarPath}/${commonTemplatesPath}"/*.sh) &> /dev/null || cp "${hangarPath}/${commonTemplatesPath}"/*.sh "${localDirectory}/${scriptFilePath}" +} + +function commitCommonFiles { + echo -e "${green}Commiting and pushing into Git remote..." + echo -ne ${white} + + # Move into the project's directory and pushing the template into the Azure DevOps repository. + cd ${localDirectory} + + # Add the YAML files. + git add "$pipelinePath" -f + + # Git commit and push it into the repository. + # changing all files to be executable + find "$pipelinePath" -type f -name '*.sh' -exec git update-index --chmod=+x {} \; + + git commit -m "Adding the source YAML" + git push -u origin ${sourceBranch} +} \ No newline at end of file diff --git a/scripts/pipelines/gitlab/pipeline_generator.sh b/scripts/pipelines/gitlab/pipeline_generator.sh new file mode 100644 index 000000000..352234689 --- /dev/null +++ b/scripts/pipelines/gitlab/pipeline_generator.sh @@ -0,0 +1,188 @@ +#!/bin/bash +set -e +FLAGS=$(getopt -a --options c:n:d:a:b:l:i:u:p:hw --long "config-file:,pipeline-name:,local-directory:,artifact-path:,target-branch:,language:,build-pipeline-name:,sonar-url:,sonar-token:,image-name:,registry-user:,registry-password:,storage-container:,cluster-name:,s3-bucket:,s3-key-path:,quality-pipeline-name:,dockerfile:,test-pipeline-name:,aws-access-key:,aws-secret-access-key:,aws-region:,package-pipeline-name:,env-provision-pipeline-name:,k8s-provider:,k8s-namespace:,k8s-deploy-files-path:,k8s-image-pull-secret-name:,help,rancher" -- "$@") + +eval set -- "$FLAGS" +while true; do + case "$1" in + -c | --config-file) configFile=$2; shift 2;; + -n | --pipeline-name) export pipelineName=$2; shift 2;; + -d | --local-directory) localDirectory=$2; shift 2;; + -a | --artifact-path) artifactPath=$2; shift 2;; + -b | --target-branch) targetBranch=$2; shift 2;; + -l | --language) language=$2; shift 2;; + --build-pipeline-name) export buildPipelineName=$2; shift 2;; + --sonar-url) sonarUrl=$2; shift 2;; + --sonar-token) sonarToken=$2; shift 2;; + -i | --image-name) imageName=$2; shift 2;; + -u | --registry-user) dockerUser=$2; shift 2;; + -p | --registry-password) dockerPassword=$2; shift 2;; + --storage-container) storageContainerName=$2; shift 2;; + --rancher) installRancher="true"; shift 1;; + --cluster-name) clusterName=$2; shift 2;; + --s3-bucket) s3Bucket=$2; shift 2;; + --s3-key-path) s3KeyPath=$2; shift 2;; + --quality-pipeline-name) export qualityPipelineName=$2; shift 2;; + --test-pipeline-name) export testPipelineName=$2; shift 2;; + --dockerfile) dockerFile=$2; shift 2;; + --aws-access-key) awsAccessKey="$2"; shift 2;; + --aws-secret-access-key) awsSecretAccessKey="$2"; shift 2;; + --aws-region) awsRegion="$2"; shift 2;; + --package-pipeline-name) export packagePipelineName=$2; shift 2;; + --env-provision-pipeline-name) envProvisionPipelineName="$2"; shift 2;; + --k8s-provider) k8sProvider=$2; shift 2;; + --k8s-namespace) k8sNamespace="$2"; shift 2;; + --k8s-deploy-files-path) k8sDeployFiles=$2; shift 2;; + --k8s-image-pull-secret-name) k8sImagePullSecret=$2; shift 2;; + -h | --help) help="true"; shift 1;; + -w) webBrowser="true"; shift 1;; + --) shift; break;; + esac +done + +# Colours for the messages. +white='\e[1;37m' +green='\e[1;32m' +red='\e[0;31m' + +# Common var +commonTemplatesPath="scripts/pipelines/gitlab/templates/common" # Path for common files of the pipelines +pipelinePath=".pipelines" # Path to the pipelines. +scriptFilePath=".pipelines/scripts" # Path to the scripts. +gitlabCiFile=".gitlab-ci.yml" +export provider="gitlab" + +function obtainHangarPath { + + # This line goes to the script directory independent of wherever the user is and then jumps 3 directories back to get the path + hangarPath=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && cd ../../.. && pwd ) +} + +function addAdditionalArtifact { + # Check if an extra artifact to store is supplied. + if test ! -z "$artifactPath" + then + # Add the extra step to the YAML. + grep " artifacts:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null && storeExtraPathContent=" - \"$artifactPath\"" + grep " artifacts:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null || storeExtraPathContent="\n artifacts:\n paths:\n - \"$artifactPath\"" + sed -i "s/# mark to insert step for additonal artifact #/$storeExtraPathContent\n/" "${localDirectory}/${pipelinePath}/${yamlFile}" + else + echo "The '-a' flag has not been set, skipping the step to add additional artifact." + sed -i '/# mark to insert step for additonal artifact #/d' "${localDirectory}/${pipelinePath}/${yamlFile}" + fi +} + +# Function that adds the variables to be used in the pipeline. +function addCommonPipelineVariables { + if test -z "${artifactPath}" + then + echo "Skipping creation of the variable artifactPath as the flag has not been used." + # Delete the commentary to set the artifactPath input/var + sed -i '/# mark to insert additional artifact env var #/d' "${localDirectory}/${pipelinePath}/${yamlFile}" + else + # add the input for the additional artifact + grep "variables:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null && textArtifactPathVar=" artifactPath: ${artifactPath//\//\\/}" + grep "variables:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null || textArtifactPathVar="variables:\n artifactPath: \"${artifactPath//\//\\/}\"" + sed -i "s/# mark to insert additional artifact env var #/$textArtifactPathVar/" "${localDirectory}/${pipelinePath}/${yamlFile}" + fi +} + +function addCiFile { + echo -e "${green}Copying and commiting the gitlab ci file." + echo -ne ${white} + + cp "${hangarPath}/${commonTemplatesPath}/${gitlabCiFile}" "${localDirectory}/${gitlabCiFile}" + testCommit=$(git status) + if echo "$testCommit" | grep "nothing to commit, working tree clean" > /dev/null + then + echo "gilab-ci file already present with same content, nothing to commit." + else + git add "${gitlabCiFile}" -f + git commit -m "adding gitlab-ci.yml" + git push + fi +} + +function createPR { + # Check if a target branch is supplied. + if test -z "$targetBranch" + then + # No branch specified in the parameters, no Pull Request is created, the code will be stored in the current branch. + echo -e "${green}No branch specified to do the Pull Request, changes left in the ${sourceBranch} branch." + exit + else + echo -e "${green}Creating a Pull Request..." + echo -ne "${white}" + repoURL=$(git config --get remote.origin.url) + repoNameWithGit="${repoURL/https:\/\/gitlab.com\/}" + repoName="${repoNameWithGit/.git}" + # Create the Pull Request to merge into the specified branch. + #debug + echo "glab mr create -b \"$targetBranch\" -d \"merge request $sourceBranch\" -s \"$sourceBranch\" -H \"${repoName}\" -t \"merge $sourceBranch\"" + pr=$(glab mr create -b "$targetBranch" -d "merge request $sourceBranch" -s "$sourceBranch" -H "${repoName}" -t "merge $sourceBranch") + + # Create merge approval to the pull request. + glab mr approvers "$sourceBranch" -R "${repoName}" + + #trying to merge + if glab mr merge -s $(basename "$pr") -y + then + # Pull Request merged successfully. + echo -e "${green}Pull Request merged into $targetBranch branch successfully." + exit + else + # Check if the -w flag is activated. + if [[ "$webBrowser" == "true" ]] + then + # -w flag is activated and a page with the corresponding Pull Request is opened in the web browser. + echo -e "${green}Pull Request successfully created." + echo -e "${green}Opening the Pull Request on the web browser..." + python -m webbrowser "$pr" + exit + else + # -w flag is not activated and the URL to the Pull Request is shown in the console. + echo -e "${green}Pull Request successfully created." + echo -e "${green}To review the Pull Request and accept it, click on the following link:" + echo "${pr}" + exit + fi + fi + fi +} + + +obtainHangarPath + +# Load common functions +. "$hangarPath/scripts/pipelines/common/pipeline_generator.lib" + +if [[ "$help" == "true" ]]; then help; fi + +ensurePathFormat + +importConfigFile + +checkInstallations + +createNewBranch + +type addPipelineVariables &> /dev/null && addPipelineVariables + +copyYAMLFile + +addAdditionalArtifact + +copyCommonScript + +type copyScript &> /dev/null && copyScript + +# This function does not exists for the github pipeline generator at this moment, but I let the line with 'type' to keep the same structure as the others pipeline generator +type addCommonPipelineVariables &> /dev/null && addCommonPipelineVariables + +commitCommonFiles + +type commitFiles &> /dev/null && commitFiles + +addCiFile + +createPR diff --git a/scripts/pipelines/gitlab/templates/common/.gitlab-ci.yml b/scripts/pipelines/gitlab/templates/common/.gitlab-ci.yml new file mode 100644 index 000000000..4f5b09c04 --- /dev/null +++ b/scripts/pipelines/gitlab/templates/common/.gitlab-ci.yml @@ -0,0 +1,19 @@ +include: + - '.pipelines/*.yml' + +workflow: + rules: + - if: '$CI_PIPELINE_SOURCE == "web"' + when: always + - when: never + +# stages: +# - build +# - test +# - quality +# - package +# - deploy + +# default: +# image: maven:3-jdk-11 +# tags: ['docker_ruby'] diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.cfg b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.cfg new file mode 100644 index 000000000..fd0233178 --- /dev/null +++ b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.cfg @@ -0,0 +1,29 @@ +# List of the flages we used in different stages for deploy pipeline. +# Comma separated list of flags. Make sure to end with a comma, Eg: $name,$xyz, +mandatoryFlags="$localDirectory,$k8sProvider,$k8sNamespace,$k8sDeployFiles," +# Path to the templates. +templatesPath="scripts/pipelines/gitlab/templates/deploy" +# YAML file name. +yamlFile="deploy-pipeline.yml" +# Source branch. +sourceBranch="feature/deploy-pipeline" + +# Function that copies the extra yaml files into the directory. +function copyScript { + # Copy the deploy script. + cp "${hangarPath}/${templatesPath}/deploy.sh" "${localDirectory}/${scriptFilePath}" + + # Copy the script for generating imagePullSecrets for private registries. + cp "${hangarPath}/${templatesPath}/secrets.sh" "${localDirectory}/${scriptFilePath}" +} + +function addPipelineVariables { + # We cannot use a variable in the definition of resource in the pipeline so we have to use a placeholder to replace it with the value we need + # export packagePipelineName + # export envProvisionPipelineName + export k8sProvider + export k8sNamespace + export k8sDeployFiles + export k8sImagePullSecret + specificEnvSubstList='${k8sProvider} ${k8sNamespace} ${k8sDeployFiles} ${k8sImagePullSecret}' +} diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template new file mode 100644 index 000000000..fae39589f --- /dev/null +++ b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template @@ -0,0 +1,78 @@ +default: + image: ubuntu:latest + +workflow: + rules: + - if: '$CI_PIPELINE_SOURCE == "web"' + when: always + +.Prerequisites_install: &Prerequisites_install + before_script: + - apt-get update + - apt-get install sudo -y + - apt-get install -y wget + - apt-get install curl -y + - apt-get install zip -y + # INSTALL yq + - wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + - chmod a+x /usr/local/bin/yq + # INSTALL KUBECTL + - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + - chmod +x ./kubectl + - mv ./kubectl /usr/local/bin/kubectl + # INSTALL AWS CLI + - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + - unzip awscliv2.zip + - sudo ./aws/install + +variables: + k8sProvider: + value: "$k8sProvider" + description: 'Deploy Cluster Name' + secretsName: + value: "$k8sImagePullSecret" + description: "ImagePullSecret Name" + deploymentYamlPath: "$CI_PROJECT_DIR/$k8sDeployFiles/application-deployment.yaml" + ingressYamlPath: "$CI_PROJECT_DIR/$k8sDeployFiles/ingress.yaml" + deployFilesPath: "$CI_PROJECT_DIR/$k8sDeployFiles" + packageTagScript: ".pipelines/scripts/package-extra.sh" + +Create secrets AKS: + <<: *Prerequisites_install + script: + - export KUBECONFIG=${KUBECONFIG} + - chmod +x .pipelines/scripts/secrets.sh + - .pipelines/scripts/secrets.sh "$k8sNamespace" "$k8sImagePullSecret" "$docker_username" "$docker_password" "$registry" "$deploymentYamlPath" + rules: + - if: '$secretsName != null && $k8sProvider == "AKS"' + when: always + +Deploy app AKS: + <<: *Prerequisites_install + script: + - export KUBECONFIG=${KUBECONFIG} + - chmod +x .pipelines/scripts/deploy.sh + - .pipelines/scripts/deploy.sh "$k8sNamespace" "$imageName" "$aks_dns_name" "$deploymentYamlPath" "$ingressYamlPath" "$deployFilesPath" "$packageTagScript" "$branch" + rules: + - if: '$k8sProvider == "AKS"' + when: always + +Create secrets EKS: + <<: *Prerequisites_install + script: + - aws eks update-kubeconfig --name ${CLUSTER_NAME} --region ${AWS_REGION} + - chmod +x .pipelines/scripts/secrets.sh + - .pipelines/scripts/secrets.sh "$k8sNamespace" "$k8sImagePullSecret" "$aws_access_key" "$aws_secret_access_key" "$registry" "$deploymentYamlPath" + rules: + - if: '$secretsName != null && $k8sProvider == "EKS"' + when: always + +Deploy app EKS: + <<: *Prerequisites_install + script: + - aws eks update-kubeconfig --name ${CLUSTER_NAME} --region ${AWS_REGION} + - chmod +x .pipelines/scripts/deploy.sh + - .pipelines/scripts/deploy.sh "$k8sNamespace" "$imageName" "$eks_dns_name" "$deploymentYamlPath" "$ingressYamlPath" "$deployFilesPath" "$packageTagScript" "$branch" + rules: + - if: '$k8sProvider == "EKS"' + when: always diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy.sh b/scripts/pipelines/gitlab/templates/deploy/deploy.sh new file mode 100644 index 000000000..1b8c5705e --- /dev/null +++ b/scripts/pipelines/gitlab/templates/deploy/deploy.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e +# Add image name, dns_name and tag. +# Source package-extra.sh to get ${tag} +. "$7" + +# we get what is located after the last '/' in the branch name, so it removes /ref/head or /ref/head/ if your branche is named correctly" +branch_short=$(echo "$8" | awk -F '/' '{ print $NF }') + +# We change the name of the tag depending if it is a release or another branch +echo "tag_completed: $8" | grep release && tag_completed="${tag}" +echo "tag_completed_branch: $8" | grep release || tag_completed="${tag}_${branch_short}" + +export image="$2" tag_completed="${tag_completed}" dns="$3" +yq eval '.spec.template.spec.containers[0].image = "'"$image:$tag_completed"'"' -i "$4" +yq eval '.spec.rules[0].host = "'"$dns"'"' -i "$5" +# Create namespace if not exists +kubectl get namespace | grep -q "^$1" || kubectl create namespace "$1" +# Apply manifest files +kubectl apply -f "$6" --namespace="$1" +# Rollout deployments in the namespace +kubectl rollout restart deploy --namespace="$1" diff --git a/scripts/pipelines/gitlab/templates/deploy/secrets.sh b/scripts/pipelines/gitlab/templates/deploy/secrets.sh new file mode 100644 index 000000000..7efd569c1 --- /dev/null +++ b/scripts/pipelines/gitlab/templates/deploy/secrets.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +# Create namespace if not exists +kubectl get namespace | grep -q "^$1" || kubectl create namespace "$1" +# Fill imagePullSecrets +export secrets="$2" +yq e '.spec.template.spec."imagePullSecrets"=[{"name":"secrets"}]' -i "$6" +yq e '.spec.template.spec.imagePullSecrets[0].name = "'"$secrets"'"' -i "$6" +# Apply the changes. +# Create imagePullSecret if not exists +kubectl create secret docker-registry "$2" --docker-server="$5" --docker-username="$3" --docker-password="$4" --namespace="$1" --save-config --dry-run=client -o yaml | kubectl apply -f - --namespace="$1" \ No newline at end of file From e598fd6424c823604af9715695743fd36fc8b419 Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 09:12:13 +0000 Subject: [PATCH 2/9] Automatic generation of documentation --- .../setup-deploy-pipeline.asciidoc | 15 +++-- .../gitlab/setup-deploy-pipeline.asciidoc | 63 +++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 documentation/gitlab/setup-deploy-pipeline.asciidoc diff --git a/documentation/azure-devops/setup-deploy-pipeline.asciidoc b/documentation/azure-devops/setup-deploy-pipeline.asciidoc index 2d77b3284..4fdeed20c 100644 --- a/documentation/azure-devops/setup-deploy-pipeline.asciidoc +++ b/documentation/azure-devops/setup-deploy-pipeline.asciidoc @@ -1,3 +1,8 @@ +:provider: Azure Devops +:pipeline_type: Pipeline +:trigger_sentence: +:pipeline_type2: pipeline +:path_provider: azure-devops = Setting up a Deploy Pipeline on Azure DevOps In this section we will create a deploy pipeline on Azure DevOps to deploy the project application on an already provisioned Kubernetes cluster. This pipeline will be configured in order to be triggered every time package pipeline is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package pipeline has passed. By default, it depends on the environment provisioning pipeline being successfully run on beforehand and, depending on the Kubernetes provider, it consumes the artifact produced by that. It also consumes variable groups created by package and environment provisioning pipelines. @@ -20,13 +25,10 @@ The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` wi ``` pipeline_generator.sh \ -c \ - -n \ -d \ - --package-pipeline-name \ - --env-provision-pipeline-name ] \ --k8s-provider \ --k8s-namespace \ - --k8s-deploy-files-path \ + --k8s-deploy-files-path \ [--k8s-image-pull-secret-name ] \ [-b ] \ [-w] @@ -36,10 +38,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines === Flags ``` -c --config-file [Required] Configuration file containing pipeline definition. --n --pipeline-name [Required] Name that will be set to the pipeline. -d --local-directory [Required] Local directory of your project. - --package-pipeline-name [Required] Package pipeline name. - --env-provision-pipeline-name [Required] Environment provisioning pipeline name. --k8s-provider [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS. --k8s-namespace [Required] Kubernetes namespace where the application will be deployed. --k8s-deploy-files-path [Required] Path from the root of the project to the YAML manifests directory. @@ -51,7 +50,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines === Examples ``` -./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -n quarkus-project-deploy -d C:/Users/$USERNAME/Desktop/quarkus-project --package-pipeline-name quarkus-project-package --env-provision-pipeline-name eks-provisioning --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop -w + ``` diff --git a/documentation/gitlab/setup-deploy-pipeline.asciidoc b/documentation/gitlab/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..b1b034ccb --- /dev/null +++ b/documentation/gitlab/setup-deploy-pipeline.asciidoc @@ -0,0 +1,63 @@ +:provider: Gitlab +:pipeline_type: pipeline +:trigger_sentence: +:pipeline_type2: Gitlab pipeline +:path_provider: gitlab += Setting up a Deploy Pipeline on Azure DevOps + +In this section we will create a deploy pipeline on Azure DevOps to deploy the project application on an already provisioned Kubernetes cluster. This pipeline will be configured in order to be triggered every time package pipeline is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package pipeline has passed. By default, it depends on the environment provisioning pipeline being successfully run on beforehand and, depending on the Kubernetes provider, it consumes the artifact produced by that. It also consumes variable groups created by package and environment provisioning pipelines. + +The creation of the pipeline will follow the project workflow, so a new branch named `feature/deploy-pipeline` will be created and the YAML file for the pipeline will be pushed to it. + +Then, a Pull Request (PR) will be created in order to merge the new branch into the appropriate branch (provided in `-b` flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using `-w` flag. + +The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` will automatically create the new branch, create a deploy pipeline based on a YAML template appropriate for the project manifests files, create the Pull Request, and if it is possible, merge this new branch into the specified branch. + +== Prerequisites + +* This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with `git pull`). + +* The YAML containing Deployment object should be named `application-deployment.yaml` for allowing automated `imagePullSecret` injection. + +== Creating the pipeline using provided script + +=== Usage +``` +pipeline_generator.sh \ + -c \ + -d \ + --k8s-provider \ + --k8s-namespace \ + --k8s-deploy-files-path \ + [--k8s-image-pull-secret-name ] \ + [-b ] \ + [-w] +``` +NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines/azure-devops/templates/deploy/deploy-pipeline.cfg`. + +=== Flags +``` +-c --config-file [Required] Configuration file containing pipeline definition. +-d --local-directory [Required] Local directory of your project. + --k8s-provider [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS. + --k8s-namespace [Required] Kubernetes namespace where the application will be deployed. + --k8s-deploy-files-path [Required] Path from the root of the project to the YAML manifests directory. + --k8s-image-pull-secret-name Name for the generated secret containing registry credentials. Required when using a private registry to host images. +-b --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided. +-w Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag. +``` + +=== Examples + +``` + +``` + + +=== Appendix: accessing the application + +Once the pipeline is executed and your application is deployed, you can list the hostname to access it with: + +``` +kubectl get ingress -n +``` From 26dd37f24e01c59b6046ff9807fc0de3e689c318 Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 14:54:46 +0530 Subject: [PATCH 3/9] Update setup-deploy-pipeline.asciidoc --- documentation/src/azure-devops/setup-deploy-pipeline.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc b/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc index b7a58985b..a3f1477e4 100644 --- a/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc +++ b/documentation/src/azure-devops/setup-deploy-pipeline.asciidoc @@ -1,6 +1,6 @@ :provider: Azure Devops :pipeline_type: Pipeline -:trigger_sentence: +:trigger_sentence_azure: :pipeline_type2: pipeline :path_provider: azure-devops -include::../common_templates/setup-deploy-pipeline.asciidoc[] \ No newline at end of file +include::../common_templates/setup-deploy-pipeline.asciidoc[] From 42aa06022bf22b03973ca1826fe9659b1da27c0a Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 09:25:08 +0000 Subject: [PATCH 4/9] Automatic generation of documentation --- .../azure-devops/setup-deploy-pipeline.asciidoc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/documentation/azure-devops/setup-deploy-pipeline.asciidoc b/documentation/azure-devops/setup-deploy-pipeline.asciidoc index 4fdeed20c..f91c49785 100644 --- a/documentation/azure-devops/setup-deploy-pipeline.asciidoc +++ b/documentation/azure-devops/setup-deploy-pipeline.asciidoc @@ -1,6 +1,6 @@ :provider: Azure Devops :pipeline_type: Pipeline -:trigger_sentence: +:trigger_sentence_azure: :pipeline_type2: pipeline :path_provider: azure-devops = Setting up a Deploy Pipeline on Azure DevOps @@ -25,7 +25,10 @@ The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` wi ``` pipeline_generator.sh \ -c \ + -n \ -d \ + --package-pipeline-name \ + --env-provision-pipeline-name \ --k8s-provider \ --k8s-namespace \ --k8s-deploy-files-path \ @@ -38,7 +41,10 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines === Flags ``` -c --config-file [Required] Configuration file containing pipeline definition. +-n --pipeline-name [Required] Name that will be set to the pipeline. -d --local-directory [Required] Local directory of your project. + --package-pipeline-name [Required] Package pipeline name. + --env-provision-pipeline-name [Required] Environment provisioning pipeline name. --k8s-provider [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS. --k8s-namespace [Required] Kubernetes namespace where the application will be deployed. --k8s-deploy-files-path [Required] Path from the root of the project to the YAML manifests directory. @@ -50,6 +56,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines === Examples ``` + ./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -n quarkus-project-deploy -d C:/Users/$USERNAME/Desktop/quarkus-project --package-pipeline-name quarkus-project-package --env-provision-pipeline-name eks-provisioning --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop -w ``` From 1b25e739bc88c20db929e8ac61dca78cf6bc988e Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 14:55:23 +0530 Subject: [PATCH 5/9] Update setup-deploy-pipeline.asciidoc --- documentation/src/gitlab/setup-deploy-pipeline.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/gitlab/setup-deploy-pipeline.asciidoc b/documentation/src/gitlab/setup-deploy-pipeline.asciidoc index d80bfdbd1..1a47ae966 100644 --- a/documentation/src/gitlab/setup-deploy-pipeline.asciidoc +++ b/documentation/src/gitlab/setup-deploy-pipeline.asciidoc @@ -1,6 +1,6 @@ :provider: Gitlab :pipeline_type: pipeline -:trigger_sentence: +:trigger_sentence_gitlab: :pipeline_type2: Gitlab pipeline :path_provider: gitlab -include::../common_templates/setup-deploy-pipeline.asciidoc[] \ No newline at end of file +include::../common_templates/setup-deploy-pipeline.asciidoc[] From 45fe0ba5d8ce68846a884239d32c9fbf872dae3f Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Thu, 22 Sep 2022 09:25:49 +0000 Subject: [PATCH 6/9] Automatic generation of documentation --- documentation/gitlab/setup-deploy-pipeline.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/gitlab/setup-deploy-pipeline.asciidoc b/documentation/gitlab/setup-deploy-pipeline.asciidoc index b1b034ccb..ddebff7e8 100644 --- a/documentation/gitlab/setup-deploy-pipeline.asciidoc +++ b/documentation/gitlab/setup-deploy-pipeline.asciidoc @@ -1,6 +1,6 @@ :provider: Gitlab :pipeline_type: pipeline -:trigger_sentence: +:trigger_sentence_gitlab: :pipeline_type2: Gitlab pipeline :path_provider: gitlab = Setting up a Deploy Pipeline on Azure DevOps @@ -51,6 +51,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines ``` + ./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -d C:/Users/$USERNAME/Desktop/quarkus-project --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop -w ``` From 2eb647fd5cb58eba95fcf0fcf69e8aed3433dcb2 Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Fri, 23 Sep 2022 11:16:57 +0530 Subject: [PATCH 7/9] Update deploy-pipeline.yml.template --- .../gitlab/templates/deploy/deploy-pipeline.yml.template | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template index fae39589f..ed152e6fa 100644 --- a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template +++ b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template @@ -5,6 +5,7 @@ workflow: rules: - if: '$CI_PIPELINE_SOURCE == "web"' when: always + - when: never .Prerequisites_install: &Prerequisites_install before_script: From 2b7065c4640c552f67e89b7a495d187e895b88a8 Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Mon, 26 Sep 2022 09:20:20 +0530 Subject: [PATCH 8/9] Update deploy.sh --- scripts/pipelines/gitlab/templates/deploy/deploy.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy.sh b/scripts/pipelines/gitlab/templates/deploy/deploy.sh index 1b8c5705e..852adda8e 100644 --- a/scripts/pipelines/gitlab/templates/deploy/deploy.sh +++ b/scripts/pipelines/gitlab/templates/deploy/deploy.sh @@ -3,7 +3,6 @@ set -e # Add image name, dns_name and tag. # Source package-extra.sh to get ${tag} . "$7" - # we get what is located after the last '/' in the branch name, so it removes /ref/head or /ref/head/ if your branche is named correctly" branch_short=$(echo "$8" | awk -F '/' '{ print $NF }') From d33b8d583502bd831374e3f78d5fe8a8b93b141b Mon Sep 17 00:00:00 2001 From: prathibhapadma Date: Mon, 26 Sep 2022 09:22:50 +0530 Subject: [PATCH 9/9] Update deploy-pipeline.yml.template --- .../templates/deploy/deploy-pipeline.yml.template | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template index ed152e6fa..178f53eb9 100644 --- a/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template +++ b/scripts/pipelines/gitlab/templates/deploy/deploy-pipeline.yml.template @@ -27,10 +27,10 @@ workflow: - sudo ./aws/install variables: - k8sProvider: + K8SPROVIDER: value: "$k8sProvider" description: 'Deploy Cluster Name' - secretsName: + SECRETSNAME: value: "$k8sImagePullSecret" description: "ImagePullSecret Name" deploymentYamlPath: "$CI_PROJECT_DIR/$k8sDeployFiles/application-deployment.yaml" @@ -45,7 +45,7 @@ Create secrets AKS: - chmod +x .pipelines/scripts/secrets.sh - .pipelines/scripts/secrets.sh "$k8sNamespace" "$k8sImagePullSecret" "$docker_username" "$docker_password" "$registry" "$deploymentYamlPath" rules: - - if: '$secretsName != null && $k8sProvider == "AKS"' + - if: '$SECRETSNAME != "" && $K8SPROVIDER == "AKS"' when: always Deploy app AKS: @@ -55,7 +55,7 @@ Deploy app AKS: - chmod +x .pipelines/scripts/deploy.sh - .pipelines/scripts/deploy.sh "$k8sNamespace" "$imageName" "$aks_dns_name" "$deploymentYamlPath" "$ingressYamlPath" "$deployFilesPath" "$packageTagScript" "$branch" rules: - - if: '$k8sProvider == "AKS"' + - if: '$K8SPROVIDER == "AKS"' when: always Create secrets EKS: @@ -65,7 +65,7 @@ Create secrets EKS: - chmod +x .pipelines/scripts/secrets.sh - .pipelines/scripts/secrets.sh "$k8sNamespace" "$k8sImagePullSecret" "$aws_access_key" "$aws_secret_access_key" "$registry" "$deploymentYamlPath" rules: - - if: '$secretsName != null && $k8sProvider == "EKS"' + - if: '$SECRETSNAME != "" && $K8SPROVIDER == "EKS"' when: always Deploy app EKS: @@ -75,5 +75,5 @@ Deploy app EKS: - chmod +x .pipelines/scripts/deploy.sh - .pipelines/scripts/deploy.sh "$k8sNamespace" "$imageName" "$eks_dns_name" "$deploymentYamlPath" "$ingressYamlPath" "$deployFilesPath" "$packageTagScript" "$branch" rules: - - if: '$k8sProvider == "EKS"' + - if: '$K8SPROVIDER == "EKS"' when: always