From 6866cd89656c622284e2a61206efdc97495ef843 Mon Sep 17 00:00:00 2001 From: "Gabriel R. Antunes" Date: Mon, 18 Nov 2024 16:59:25 -0400 Subject: [PATCH] chore: cd --- .../actions/deploy-k8s-kustomize/action.yml | 16 ++----- .github/workflows/cd.yml | 48 ++++++++++--------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/.github/actions/deploy-k8s-kustomize/action.yml b/.github/actions/deploy-k8s-kustomize/action.yml index e82e5c8..805bc1b 100644 --- a/.github/actions/deploy-k8s-kustomize/action.yml +++ b/.github/actions/deploy-k8s-kustomize/action.yml @@ -2,8 +2,8 @@ name: "Continuous Deployment – K8S Kustomize" description: "Deploy resources to kubernetes cluster using kustomize definitions" inputs: - env-json: - description: "json with key value envs for the service secret" + runtime-env: + description: "string with key value envs for the service secret" required: true pwd: description: "working directory" @@ -22,17 +22,11 @@ runs: shell: bash working-directory: ${{ inputs.pwd }} env: - ENV_RUNTIME_JSON: ${{ inputs.env-json }} + ENV_RUNTIME_KEY_VALUE: ${{ inputs.runtime-env }} + ENV_RUNTIME_SECRET_NAME: "ladesa-ro-sso-secrets" run: | - ENV_RUNTIME_SECRET_NAME="ladesa-ro-sso-secrets"; - - ENV_RUNTIME_KEY_VALUE=$( \ - echo "${ENV_RUNTIME_JSON}" \ - | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' \ - ); - kubectl create secret generic ${ENV_RUNTIME_SECRET_NAME} \ - --from-env-file=<(echo "$ENV_RUNTIME_KEY_VALUE") \ + --from-env-file=<(echo "${ENV_RUNTIME_KEY_VALUE}") \ --namespace=${{ inputs.namespace }} \ ; diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 060374d..c01945e 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -17,16 +17,16 @@ jobs: steps: - uses: actions/checkout@v4 - # - uses: ./.github/actions/build-and-push - # with: - # setup-qemu: "false" - # build-image: "true" - # push-image: "true" - # image-name: ${{ vars.IMAGE_NAME_SSO_SERVICE }} - # image-tag: ${{ vars.IMAGE_TAG }} - # push-image-registry-url: ${{ secrets.REGISTRY_URL }} - # push-image-registry-username: ${{ secrets.REGISTRY_USERNAME }} - # push-image-registry-token: ${{ secrets.REGISTRY_TOKEN }} + - uses: ./.github/actions/build-and-push + with: + setup-qemu: "false" + build-image: "true" + push-image: "true" + image-name: ${{ vars.IMAGE_NAME_SSO_SERVICE }} + image-tag: ${{ vars.IMAGE_TAG }} + push-image-registry-url: ${{ secrets.REGISTRY_URL }} + push-image-registry-username: ${{ secrets.REGISTRY_USERNAME }} + push-image-registry-token: ${{ secrets.REGISTRY_TOKEN }} cd_deploy_development: name: Deploy to Cluster (Development) @@ -39,31 +39,35 @@ jobs: url: ${{ env.DEPLOYMENT_URL }} env: + ENV_PREFIX_RUNTIME: "${{ vars.ENV_PREFIX_RUNTIME }}" ENV_SECRETS_JSON: "${{ toJson(secrets) }}" ENV_VARS_JSON: "${{ toJson(vars) }}" steps: - uses: actions/checkout@v4 - - name: produce key=value with runtime env vars + - id: config + name: produce key=value with runtime env vars shell: bash run: | - ENV_STRIP_PREFIX="RUNTIME_"; - # Transforma os (secrets e vars) presentes nesta action para o runtime do sistema # Combina objetos JSON, filtra por prefixo, e converte para key=value - RUNTIME_ENV_KEY_VALUE=$(\ + RUNTIME_ENV=$(\ echo '${{ env.ENV_SECRETS_JSON }} ${{ env.ENV_VARS_JSON }}' \ | jq -s add \ - | jq --arg prefix "$ENV_STRIP_PREFIX" 'with_entries(select(.key | startswith($prefix)) | .key |= sub("^" + $prefix; ""))' \ + | jq --arg prefix "${{ env.ENV_PREFIX_RUNTIME }}" 'with_entries(select(.key | startswith($prefix)) | .key |= sub("^" + $prefix; ""))' \ | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' \ ); - echo "$RUNTIME_ENV_KEY_VALUE" + { + echo 'RUNTIME_ENV<> "$GITHUB_OUTPUT" - # - uses: ./.github/actions/deploy-k8s-kustomize - # with: - # env-json: ${{ toJson(secrets) }} - # pwd: ${{ env.DEPLOYMENT_PWD }} - # deployment: ${{ env.DEPLOYMENT_K8S_DEPLOYMENT }} - # namespace: ${{ env.DEPLOYMENT_K8S_NAMESPACE }} + - uses: ./.github/actions/deploy-k8s-kustomize + with: + runtime-env: ${{ steps.config.outputs.RUNTIME_ENV }} + pwd: ${{ env.DEPLOYMENT_PWD }} + deployment: ${{ env.DEPLOYMENT_K8S_DEPLOYMENT }} + namespace: ${{ env.DEPLOYMENT_K8S_NAMESPACE }}