From f00beeb3397d93a7bfcf5774a4cc733ea6729126 Mon Sep 17 00:00:00 2001 From: Mati Machado Date: Tue, 8 Feb 2022 18:43:27 -0300 Subject: [PATCH] chore: add support for basic auth (#8) * chore: add variables * chore: add support for basic auth * fix: bash syntax * fix: bash syntax * fix: bash syntax * fix: bash syntax * fix: bash syntax * choree: update pipeline variables * choree: update pipeline variables * fix: release not found * chore: update values --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- action.yaml | 18 +++++++++++++++++- deploy.sh | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 89 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 67a747c..ff4fcb6 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,15 @@ Following inputs can be used as `step.with` keys | `namespace` | String | Kubernetes namespace to use. | | `values` | String | Comma separates list of value set for helms. e.x: key1=value1,key2=value2 | | `name` | String | The name of the helm release | -| `chart-path` | String | The path to the chart. (defaults to `helm/`) | +| `chart-path` | String | The path to the chart. (defaults to `helm/`) (For local repo)| +| `chart-repository` | String | The URL of the chart repository. (For remote repo)| +| `chart-name` | String | Helm chart name inside the repository. (For remote repo)| +| `repo-username` | String | Username for repository basic auth| +| `repo-password` | String | Password for repository basic auth| ## Example usage +#### Local repository ```yaml uses: craftech-io/eks-helm-deploy-action@v1 @@ -36,4 +41,40 @@ with: namespace: dev values: key1=value1,key2=value2 name: release_name +``` + +#### Remote repository + +```yaml +uses: craftech-io/eks-helm-deploy-action@v1 +with: + aws-access-key-id: ${{ secrets.AWS_ACCESS__KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + cluster-name: mycluster + config-files: .github/values/dev.yaml + chart-repository: https://chartmuseum.mgt.example.com + chart-name: example + namespace: dev + values: key1=value1,key2=value2 + name: release_name +``` + +#### Remote repository w/basic auth + +```yaml +uses: craftech-io/eks-helm-deploy-action@v1 +with: + aws-access-key-id: ${{ secrets.AWS_ACCESS__KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + cluster-name: mycluster + config-files: .github/values/dev.yaml + chart-repository: https://chartmuseum.mgt.example.com + chart-name: example + repo-username: user + repo-password: aV3ryC0mpl3xP455w0rd + namespace: dev + values: key1=value1,key2=value2 + name: release_name ``` \ No newline at end of file diff --git a/action.yaml b/action.yaml index 58ddd6f..595cf4c 100644 --- a/action.yaml +++ b/action.yaml @@ -40,6 +40,9 @@ inputs: chart-repository: description: 'The repository of the chart.' required: false + chart-name: + description: 'Chart name in the repository' + required: false timeout: description: 'Timeout for the job.' required: true @@ -48,6 +51,15 @@ inputs: description: 'Update chart dependencies' required: false default: "true" + repo-name: + description: 'Name of the repository' + required: false + repo-username: + description: 'Username to authenticate to the repository.' + required: false + repo-password: + description: 'Password to authenticate to repository.' + required: false runs: using: 'docker' image: 'Dockerfile' @@ -64,4 +76,8 @@ runs: DEPLOY_CHART_PATH: ${{ inputs.chart-path }} TIMEOUT: ${{ inputs.timeout }} UPDATE_DEPS: ${{ inputs.update-deps }} - HELM_REPOSITORY: ${{ inputs.chart-repository }} \ No newline at end of file + HELM_REPOSITORY: ${{ inputs.chart-repository }} + HELM_CHART_NAME: ${{ inputs.chart-name }} + REPO_NAME: ${{ inputs.repo-name }} + REPO_USERNAME: ${{ inputs.repo-username }} + REPO_PASSWORD: ${{ inputs.repo-password }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 7657c7b..5eae592 100755 --- a/deploy.sh +++ b/deploy.sh @@ -14,14 +14,32 @@ fi # Helm Deployment -if [ -n "$HELM_REPOSITORY" ]; then - HELM_CHART_NAME=${DEPLOY_CHART_PATH%/*} - DEPS_UPDATE_COMMAND="helm repo add ${HELM_CHART_NAME} ${HELM_REPOSITORY}" +#################### +# Dependency Update +#################### +# Verify local or remote repository +if [ -z ${HELM_CHART_NAME} ]; then + HELM_CHART_NAME=${DEPLOY_CHART_PATH%/*} +fi +if [ ! -z "$HELM_REPOSITORY" ]; then + #Verify basic auth + if [ ! -z ${REPO_USERNAME} ] && [ ! -z ${REPO_PASSWORD} ]; then + echo "Executing: helm repo add --username="${REPO_USERNAME}" --password="${REPO_PASSWORD}" ${HELM_CHART_NAME} ${HELM_REPOSITORY}" + helm repo add --username="${REPO_USERNAME}" --password="${REPO_PASSWORD}" ${HELM_CHART_NAME} ${HELM_REPOSITORY} + else + echo "Executing: helm repo add ${HELM_CHART_NAME} ${HELM_REPOSITORY}" + helm repo add ${HELM_CHART_NAME} ${HELM_REPOSITORY} + fi else - DEPS_UPDATE_COMMAND="helm dependency update ${DEPLOY_CHART_PATH}" + echo "Executing: helm dependency update ${DEPLOY_CHART_PATH}" + helm dependency update ${DEPLOY_CHART_PATH} fi -UPGRADE_COMMAND="helm upgrade --timeout ${TIMEOUT}" +#################### +# Helm upgrade +#################### + +UPGRADE_COMMAND="helm upgrade -i --timeout ${TIMEOUT}" for config_file in ${DEPLOY_CONFIG_FILES//,/ } do UPGRADE_COMMAND="${UPGRADE_COMMAND} -f ${config_file}" @@ -32,8 +50,12 @@ fi if [ -n "$DEPLOY_VALUES" ]; then UPGRADE_COMMAND="${UPGRADE_COMMAND} --set ${DEPLOY_VALUES}" fi -UPGRADE_COMMAND="${UPGRADE_COMMAND} ${DEPLOY_NAME} ${DEPLOY_CHART_PATH}" -echo "Executing: ${DEPS_UPDATE_COMMAND}" -${DEPS_UPDATE_COMMAND} + +if [ -z "$HELM_REPOSITORY" ]; then + UPGRADE_COMMAND="${UPGRADE_COMMAND} ${DEPLOY_NAME} ${DEPLOY_CHART_PATH}" +else + UPGRADE_COMMAND="${UPGRADE_COMMAND} ${DEPLOY_NAME} ${HELM_CHART_NAME}/${HELM_CHART_NAME}" +fi + echo "Executing: ${UPGRADE_COMMAND}" ${UPGRADE_COMMAND} \ No newline at end of file