diff --git a/documentation/azure-devops/setup-deploy-pipeline.asciidoc b/documentation/azure-devops/setup-deploy-pipeline.asciidoc index 2d77b3284..c6a5b8e80 100644 --- a/documentation/azure-devops/setup-deploy-pipeline.asciidoc +++ b/documentation/azure-devops/setup-deploy-pipeline.asciidoc @@ -1,12 +1,17 @@ -= Setting up a Deploy Pipeline on Azure DevOps +:provider: Azure Devops +:pipeline_type: Pipeline +:trigger_sentence: +:pipeline_type2: pipeline +:path_provider: azure-devops += Setting up a Deploy Pipeline on {provider} -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. +In this section we will create a deploy {pipeline_type} on {provider} 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_type} is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package {pipeline_type} has passed. By default, it depends on the environment provisioning {pipeline_type} 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 {pipeline_type}. 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. +The script located at `/scripts/pipelines/{path_provider}/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 @@ -14,7 +19,7 @@ The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` wi * The YAML containing Deployment object should be named `application-deployment.yaml` for allowing automated `imagePullSecret` injection. -== Creating the pipeline using provided script +== Creating the {pipeline_type} using provided script === Usage ``` @@ -23,15 +28,15 @@ pipeline_generator.sh \ -n \ -d \ --package-pipeline-name \ - --env-provision-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] ``` -NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines/azure-devops/templates/deploy/deploy-pipeline.cfg`. +NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines/{path_provider}/templates/deploy/deploy-pipeline.cfg`. === Flags ``` @@ -43,7 +48,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines --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. + --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. ``` @@ -57,7 +62,7 @@ NOTE: The config file for the deploy pipeline is located at `/scripts/pipelines === Appendix: accessing the application -Once the pipeline is executed and your application is deployed, you can list the hostname to access it with: +Once the {pipeline_type} is executed and your application is deployed, you can list the hostname to access it with: ``` kubectl get ingress -n diff --git a/documentation/github/setup-deploy-pipeline.asciidoc b/documentation/github/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..ff4064029 --- /dev/null +++ b/documentation/github/setup-deploy-pipeline.asciidoc @@ -0,0 +1,69 @@ +:provider: Github +:pipeline_type: workflow +:trigger_sentence_github: +:pipeline_type2: Github action +:path_provider: github += Setting up a Deploy Pipeline on {provider} + +In this section we will create a deploy {pipeline_type} on {provider} 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_type} is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package {pipeline_type} has passed. By default, it depends on the environment provisioning {pipeline_type} 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 {pipeline_type}. + +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/{path_provider}/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_type} using provided script + +=== Usage +``` +pipeline_generator.sh \ + -c \ + -n \ + -d \ + --package-pipeline-name \ + --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/{path_provider}/templates/deploy/deploy-pipeline.cfg`. + +=== 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. + --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 + +``` +./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 +``` + + +=== Appendix: accessing the application + +Once the {pipeline_type} 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/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..5bc290298 --- /dev/null +++ b/documentation/src/common_templates/setup-deploy-pipeline.asciidoc @@ -0,0 +1,64 @@ += Setting up a Deploy Pipeline on {provider} + +In this section we will create a deploy {pipeline_type} on {provider} 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_type} is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package {pipeline_type} has passed. By default, it depends on the environment provisioning {pipeline_type} 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 {pipeline_type}. + +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/{path_provider}/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_type} using provided script + +=== Usage +``` +pipeline_generator.sh \ + -c \ + -n \ + -d \ + --package-pipeline-name \ + --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/{path_provider}/templates/deploy/deploy-pipeline.cfg`. + +=== 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. + --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 + +``` +./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 +``` + + +=== Appendix: accessing the application + +Once the {pipeline_type} 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/github/setup-deploy-pipeline.asciidoc b/documentation/src/github/setup-deploy-pipeline.asciidoc new file mode 100644 index 000000000..22177fdb8 --- /dev/null +++ b/documentation/src/github/setup-deploy-pipeline.asciidoc @@ -0,0 +1,6 @@ +:provider: Github +:pipeline_type: workflow +:trigger_sentence_github: +:pipeline_type2: Github action +:path_provider: github +include::../common_templates/setup-deploy-pipeline.asciidoc[] diff --git a/scripts/pipelines/github/pipeline_generator.sh b/scripts/pipelines/github/pipeline_generator.sh index 556f6f248..a121b7fd5 100644 --- a/scripts/pipelines/github/pipeline_generator.sh +++ b/scripts/pipelines/github/pipeline_generator.sh @@ -1,6 +1,6 @@ #!/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:,resource-group:,storage-account:,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:,ci-pipeline-name:,help" -- "$@") +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:,resource-group:,storage-account:,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:,rancher:,ci-pipeline-name:,package-pipeline-name:,env-provision-pipeline-name:,k8s-provider:,k8s-namespace:,k8s-deploy-files-path:,k8s-image-pull-secret-name:,help" -- "$@") eval set -- "$FLAGS" while true; do @@ -30,6 +30,12 @@ while true; do --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;; diff --git a/scripts/pipelines/github/templates/deploy/deploy-pipeline.cfg b/scripts/pipelines/github/templates/deploy/deploy-pipeline.cfg new file mode 100644 index 000000000..10ad9114b --- /dev/null +++ b/scripts/pipelines/github/templates/deploy/deploy-pipeline.cfg @@ -0,0 +1,30 @@ +# 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="$pipelineName,$localDirectory,$packagePipelineName,$envProvisionPipelineName,$k8sProvider,$k8sNamespace,$k8sDeployFiles," +# Path to the templates. +templatesPath="scripts/pipelines/github/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='${packagePipelineName} ${envProvisionPipelineName} ${k8sProvider} ${k8sNamespace} ${k8sDeployFiles} ${k8sImagePullSecret}' +} + diff --git a/scripts/pipelines/github/templates/deploy/deploy-pipeline.yml.template b/scripts/pipelines/github/templates/deploy/deploy-pipeline.yml.template new file mode 100644 index 000000000..93154cca4 --- /dev/null +++ b/scripts/pipelines/github/templates/deploy/deploy-pipeline.yml.template @@ -0,0 +1,113 @@ +name: $pipelineName + +on: + workflow_run: + workflows: $packagePipelineName + types: completed + workflow_dispatch: + inputs: + k8sProvider: + description: 'Deploy Cluster Name.' + required: true + type: string + default: '$k8sProvider' + secretsName: + description: 'ImagePullSecret Name.' + type: string + default: '$k8sImagePullSecret' +# mark to insert additional artifact input # + +env: + k8sProvider: ${{ github.event.inputs.k8sProvider || '$k8sProvider' }} + deploymentYamlPath: "${{ github.workspace }}/$k8sDeployFiles/application-deployment.yaml" + ingressYamlPath: "${{ github.workspace }}/$k8sDeployFiles/ingress.yaml" + deployFilesPath: "${{ github.workspace }}/$k8sDeployFiles" + aksProvisionPipeline: 'aks-provisioning.yml' + packagePipelineYamlName: "package-pipeline.yml" + packageTagScript: ".github/workflows/scripts/package-extra.sh" + k8sNamespace: "$k8sNamespace" + kubeConfigPath: "/home/runner/.kube/config" + kubeConfigFolder: "/home/runner/.kube" +# mark to insert additional artifact env var # + +jobs: + Deploy: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} + steps: + - name: get info from package + uses: dawidd6/action-download-artifact@v2 + id: downloadFromBuild + if: ${{ github.event_name == 'workflow_run' }} + with: + workflow: ${{ env.packagePipelineYamlName }} + run_number: ${{ github.event.workflow_run.run_number }} + check_artifacts: true + name: package_workflow_info + + - name: Get env var from the package-pipeline + uses: tw3lveparsecs/github-actions-setvars@v0.1 + if: ${{ github.event_name == 'workflow_run' }} + with: + envFilePath: package_workflow_info.env + + - name: Cancel Workflow (if the branch are not develop or release) + if: ${{ github.event_name == 'workflow_run' && env.branch_package_workflow != 'develop' && !(startsWith(env.branch_package_workflow, 'release/')) }} + uses: andymckay/cancel-action@0.2 + + - name: Checkout the repository + uses: actions/checkout@master + with: + ref: ${{ env.commit_package_workflow || github.sha }} + + - name: Set additional Environment Variables + uses: tw3lveparsecs/github-actions-setvars@v0.1 + with: + envFilePath: ".github/vars/*" + + - name: Download artifact from AKS provision pipeline workflow + if: ${{ env.k8sProvider == 'AKS' }} + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ env.aksProvisionPipeline }} + check_artifacts: true + search_artifacts: true + name: kubeconfig + + - name: MV kubeconfig AKS + if: ${{ env.k8sProvider == 'AKS' }} + run: mkdir -p ${{ env.kubeConfigFolder }}; mv ${{ github.workspace }}/kubeconfig ${{ env.kubeConfigPath }} + + - name: Download artifact from EKS provision pipeline workflow + if: ${{ env.k8sProvider == 'EKS' }} + run: | + aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} + aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws eks update-kubeconfig --name ${{ env.eks_cluster_name }} --region ${{ secrets.AWS_REGION }} + + - name: Create secrets + if: ${{ github.event.inputs.secretsName != '' }} + env: + KUBECONFIG: ${{ env.kubeConfigPath }} + run: .github/workflows/scripts/secrets.sh "${{ env.k8sNamespace }}" "${{ github.event.inputs.secretsName }}" "${{ secrets.DOCKER_USER }}" "${{ secrets.DOCKER_PASSWORD }}" "${{ env.registry }}" "${{ env.deploymentYamlPath }}" + + - name: Deploy app AKS + if: ${{ env.k8sProvider == 'AKS' }} + env: + KUBECONFIG: ${{ env.kubeConfigPath }} + run: .github/workflows/scripts/deploy.sh "${{ env.k8sNamespace }}" "${{ env.imageName }}" "${{ env.aks_dns_name }}" "${{ env.deploymentYamlPath }}" "${{ env.ingressYamlPath }}" "${{ env.deployFilesPath }}" "${{ env.packageTagScript }}" "${{ env.branch_package_workflow || github.ref }}" + + - name: Deploy app EKS + if: ${{ env.k8sProvider == 'EKS' }} + env: + KUBECONFIG: ${{ env.kubeConfigPath }} + run: .github/workflows/scripts/deploy.sh "${{ env.k8sNamespace }}" "${{ env.imageName }}" "${{ env.eks_dns_name }}" "${{ env.deploymentYamlPath }}" "${{ env.ingressYamlPath }}" "${{ env.deployFilesPath }}" "${{ env.packageTagScript }}" "${{ env.branch_package_workflow || github.ref }}" + +# mark to insert step for additional artifact # + on-failure: + name: CI Workflow Failed + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - name: Cancel Workflow + uses: andymckay/cancel-action@0.2 \ No newline at end of file diff --git a/scripts/pipelines/github/templates/deploy/deploy.sh b/scripts/pipelines/github/templates/deploy/deploy.sh new file mode 100644 index 000000000..7da63aa37 --- /dev/null +++ b/scripts/pipelines/github/templates/deploy/deploy.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +# Add image name, dns_name and tag. +# Run package-extra.sh to ${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" +# Deploy apps in exists namespace, If not exists Create new namespace and apply manifest files. +kubectl get namespace | grep -q "^$1" || kubectl create namespace "$1" +kubectl apply -f "$6" --namespace="$1" diff --git a/scripts/pipelines/github/templates/deploy/secrets.sh b/scripts/pipelines/github/templates/deploy/secrets.sh new file mode 100644 index 000000000..0d68cf1f6 --- /dev/null +++ b/scripts/pipelines/github/templates/deploy/secrets.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +# Deploy apps in exists namespace, If not exists Create new namespace. +kubectl get namespace | grep -q "^$1" || kubectl create namespace "$1" +# Command to create secrets to pull image from private registry. +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. +kubectl create secret docker-registry "$2" --docker-server="$5" --docker-username="$3" --docker-password="$4" --namespace="$1" --save-config --dry-run=none -o yaml | kubectl apply -f "$6" --namespace="$1" \ No newline at end of file diff --git a/scripts/pipelines/github/templates/package/package-pipeline.yml.template b/scripts/pipelines/github/templates/package/package-pipeline.yml.template index 72a64a013..36ffb8073 100644 --- a/scripts/pipelines/github/templates/package/package-pipeline.yml.template +++ b/scripts/pipelines/github/templates/package/package-pipeline.yml.template @@ -75,6 +75,17 @@ jobs: run: .github/workflows/scripts/package.sh -f "$GITHUB_WORKSPACE/${{ env.relativeDockerfilePath }}" -c "$GITHUB_WORKSPACE" -a "${{ secrets.AWS_ACCESS_KEY }}" -s "${{ secrets.AWS_SECRET_ACCESS_KEY }}" -l "${{ env.region }}" -r "${{ env.registry }}" -i "${{ env.imageName }}" -b "${{ github.event.workflow_run.head_branch || github.ref }}" if: ${{ env.isECR == 'true' }} + - name: store workflow_run info + run: | + echo "branch_package_workflow=${{ github.event.workflow_run.head_branch || github.ref }}" >> package_workflow_info.env + echo "commit_package_workflow=${{ github.event.workflow_run.head_commit.id || github.sha }}" >> package_workflow_info.env + + - name: Publish workflow_run info + uses: actions/upload-artifact@v3 + with: + name: package_workflow_info + path: package_workflow_info.env + # mark to insert step for additional artifact # on-failure: name: CI Workflow Failed