Skip to content

Commit

Permalink
chore: cd
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Nov 18, 2024
1 parent 9b0f71a commit 6866cd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
16 changes: 5 additions & 11 deletions .github/actions/deploy-k8s-kustomize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }} \
;
Expand Down
48 changes: 26 additions & 22 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<<EOF'
echo "${RUNTIME_ENV}"
echo EOF
} >> "$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 }}

0 comments on commit 6866cd8

Please sign in to comment.