From c87aaed67158b02b4ca76831680e7cd82557b88d Mon Sep 17 00:00:00 2001 From: KalyanaVadlamani <159027167+KalyanaVadlamani@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:52:12 +0100 Subject: [PATCH] HEAT-227-fix: Updated the pipeline to poulate dev & prod secrets (#12) --- .../actions/cloud-platform-deploy/action.yml | 17 ++++--- .github/actions/get-env-details/action.yml | 29 +++++++++++ .github/workflows/deploy.yml | 49 ++++++------------- .github/workflows/pipeline.yml | 25 +++++----- 4 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 .github/actions/get-env-details/action.yml diff --git a/.github/actions/cloud-platform-deploy/action.yml b/.github/actions/cloud-platform-deploy/action.yml index 96e367c..95a588a 100644 --- a/.github/actions/cloud-platform-deploy/action.yml +++ b/.github/actions/cloud-platform-deploy/action.yml @@ -29,6 +29,12 @@ runs: steps: - uses: actions/checkout@v3 + - name: Get environment details + uses: ./.github/actions/get-env-details + id: env + with: + environment: ${{ inputs.environment }} + - name: Authenticate uses: ./.github/actions/cloud-platform-auth with: @@ -43,10 +49,9 @@ runs: run: | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" brew install helm - cd helm_deploy/${{ github.event.repository.name }} - yq -i ".appVersion = \"${{ inputs.version }}\"" "Chart.yaml" - helm dependency update . - exec helm upgrade '${{ github.event.repository.name }}' . \ + yq -i ".appVersion = \"${{ inputs.version }}\"" "helm_deploy/${{ github.event.repository.name }}/Chart.yaml" + helm dependency update "helm_deploy/${{ github.event.repository.name }}" + exec helm upgrade '${{ github.event.repository.name }}' 'helm_deploy/${{ github.event.repository.name }}' \ --atomic \ --history-max 10 \ --force \ @@ -55,5 +60,5 @@ runs: --set 'generic-service.image.tag=${{ inputs.version }}' \ --set 'version=${{ inputs.version }}' \ --timeout 10m \ - --values '${{ steps.env.outputs.values-file }}' \ - --wait \ No newline at end of file + --values 'helm_deploy/${{ steps.env.outputs.values-file }}' \ + --wait diff --git a/.github/actions/get-env-details/action.yml b/.github/actions/get-env-details/action.yml new file mode 100644 index 0000000..ef726ca --- /dev/null +++ b/.github/actions/get-env-details/action.yml @@ -0,0 +1,29 @@ +name: Get environment details +description: Map the GitHub environment name to the corresponding Namespace environment details + +inputs: + environment: + description: GitHub environment name + required: true + +outputs: + values-file: + description: The filename for the values file containing environment configuration + value: ${{ steps.cloud-platform.outputs.values-file }} + cloud-platform-namespace: + description: The name of the corresponding Cloud Platform namespace + value: ${{ steps.cloud-platform.outputs.namespace }} + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + + - name: Map GitHub environment to Cloud Platform namespace + id: cloud-platform + shell: bash + run: | + if [ '${{ inputs.environment }}' == 'development' ]; then namespace='dev'; fi + if [ '${{ inputs.environment }}' == 'production' ]; then namespace='prod'; fi + echo "namespace=${namespace}" | tee -a "$GITHUB_OUTPUT" + echo "values-file=values-${namespace}.yaml" | tee -a "$GITHUB_OUTPUT" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f9774d..5f1acb5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,13 +2,9 @@ name: Deploy on: workflow_call: - inputs: - github_environment: - description: The name of the github environment for deployment secrets - type: string - required: true + inputs: environment: - description: The name of the environment to deploy to + description: The name of the environment to deploy to (dev/prod) type: string required: true version: @@ -18,20 +14,13 @@ on: workflow_dispatch: inputs: - github_environment: - description: The name of the github environment for deployment secrets - type: choice - required: true - options: - - development - - production environment: description: Environment type: choice required: true options: - - dev - - prod + - development + - production version: description: Image version type: string @@ -42,31 +31,23 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - environment: [development, production] + environment: - name: ${{ inputs.github_environment }} + name: ${{ inputs.environment }} steps: - - uses: actions/checkout@v3 - - - name: Deploy to Dev - uses: ./.github/actions/cloud-platform-deploy + - uses: actions/checkout@v4 + - uses: ./.github/actions/get-env-details + id: env with: environment: ${{ inputs.environment }} - version: ${{ inputs.version }} - api: https://${{ secrets.DEVELOPMENT_KUBE_CLUSTER }} - cert: ${{ secrets.DEVELOPMENT_KUBE_CERT }} - cluster: ${{ secrets.DEVELOPMENT_KUBE_CLUSTER }} - namespace: ${{ secrets.DEVELOPMENT_KUBE_NAMESPACE }} - token: ${{ secrets.DEVELOPMENT_KUBE_TOKEN }} - - name: Deploy to Prod + - name: Deploy to Platform uses: ./.github/actions/cloud-platform-deploy with: environment: ${{ inputs.environment }} version: ${{ inputs.version }} - api: https://${{ secrets.PRODUCTION_KUBE_CLUSTER }} - cert: ${{ secrets.PRODUCTION_KUBE_CERT }} - cluster: ${{ secrets.PRODUCTION_KUBE_CLUSTER }} - namespace: ${{ secrets.PRODUCTION_KUBE_NAMESPACE }} - token: ${{ secrets.PRODUCTION_KUBE_TOKEN }} + api: https://${{ secrets.KUBE_CLUSTER }} + cert: ${{ secrets.KUBE_CERT }} + cluster: ${{ secrets.KUBE_CLUSTER }} + namespace: ${{ secrets.KUBE_NAMESPACE }} + token: ${{ secrets.KUBE_TOKEN }} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 1bfb42b..e0a7836 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -4,16 +4,21 @@ on: push: branches: - main - workflow_dispatch: # Can be triggered manually from a branch + + workflow_dispatch: inputs: environment: - description: 'Deployment Environment (valid values: "development", "production")' + description: Environment + type: choice required: true - default: 'development' + options: + - development + - production version: - description: 'Application version to deploy' - required: true - + description: Image version + type: string + required: true + jobs: build: name: Build @@ -22,25 +27,21 @@ jobs: push: true secrets: inherit - deploy_to_dev: name: Deploy to dev uses: ./.github/workflows/deploy.yml needs: build with: - github_environment: development - environment: dev + environment: development version: ${{ needs.build.outputs.version }} secrets: inherit - deploy_to_prod: name: Deploy to prod uses: ./.github/workflows/deploy.yml needs: - deploy_to_dev # wait for the deploy_to_dev job to complete with: - github_environment: production - environment: prod + environment: production version: ${{ github.event.inputs.version }} secrets: inherit \ No newline at end of file