Skip to content

bin/ci-post-review-app-destroy Hooks don't get executed #162

Description

@daniel-nerdgeschoss

Hello,

thank you so much for Dokku! We're in the process of switching our Review apps to Dokku, but we hit a snag where our custom hooks to destroy the review database don't get called during review-apps:destroy.

We also use ci-pre-deploy/ci-post-deploy, and those DO run during review-apps:create.

$ ls -la bin                                                                                                                                           
-rw-r--r--@  1 daniel  staff   156 Feb  5 15:28 ci-post-deploy
-rw-r--r--@  1 daniel  staff   245 Feb  5 16:41 ci-post-review-app-destroy
-rw-r--r--@  1 daniel  staff   653 Feb  5 15:28 ci-pre-deploy
-rw-r--r--@  1 daniel  staff    47 Feb  5 16:41 ci-pre-review-app-destroy

bin/ci-post-review-app-destroy:

#!/bin/sh -l

if [ "$IS_REVIEW_APP" = "true" ]; then
  ssh "$SSH_REMOTE" -- postgres:destroy "$APP_NAME-db" --force
fi

We're using Github Actions, the YAML file looks like this:

---
name: 'Review App'

on:
  pull_request:
    types: [opened, reopened, closed, synchronize]

jobs:
  create_review_app:
    runs-on: ubuntu-latest

    environment:
      name: Review App
      url: ${{ steps.create_review_app.outputs.app_url }}

    # only run when a pull request is opened
    if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')
    steps:
      - name: Cloning repo
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Create the review app
        uses: dokku/github-action@master
        id: create_review_app
        with:
          command: review-apps:create
          git_remote_url: 'ssh://dokku@example.com:22/sandbox'
          git_push_flags: '--force'
          # specify a name for the review app
          review_app_name: pr-${{ github.event.pull_request.number }}
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
          trace: 1

  destroy_review_app:
    runs-on: ubuntu-latest
    # only run when a pull request is closed
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    steps:
      - name: Destroy the review app
        uses: dokku/github-action@master
        with:
          # destroy a review app
          command: review-apps:destroy
          git_remote_url: 'ssh://dokku@example.com:22/sandbox'
          # specify a name for the review app
          review_app_name: pr-${{ github.event.pull_request.number }}
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
          trace: 1

We tried running with trace: 1 to see if anything looks suspicious:

[snip]
+ ssh-add /root/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (daniel@nerdgeschoss.de)
+ parse-ci-commit
+ value=
+ '[' -n  ]
+ '[' -n  ]
+ '[' -n  ]
+ '[' -n  ]
+ '[' -n  ]
+ '[' -n 447dd0d8a9613fcbba457ac5da2d1dcfb0bddde6 ]
+ value=447dd0d8a9613fcbba457ac5da2d1dcfb0bddde6
+ echo 447dd0d8a9613fcbba457ac5da2d1dcfb0bddde6
+ commit_sha=447dd0d8a9613fcbba457ac5da2d1dcfb0bddde6
+ parse-app-name
+ '[' -n  ]
+ sed -e 's/.*\///'
+ echo ssh://dokku@example.com:22/sandbox
+ app_name=sandbox
+ parse-ssh-host
+ parse-ssh-port
+ ssh_remote=ssh://dokku@example.com:22
+ '[' review-apps:destroy '=' review-apps:create ]
+ '[' review-apps:destroy '=' review-apps:destroy ]
+ '[' -z pr-410 ]
+ '[' review-apps:destroy '=' review-apps:destroy ]
+ '[' -f bin/ci-pre-review-app-destroy ]
+ log-info 'Destroying review app '"'"'pr-410'"'"
Destroying review app 'pr-410'
+ ssh ssh://dokku@example.com:22 -- --force apps:destroy pr-410
-----> Destroying pr-410 (including all add-ons)
       Unlinking from pr-410-db
       Unlinking from sandbox-db
-----> Cleaning up...
-----> Retiring old containers and images
+ '[' -f bin/ci-post-review-app-destroy ]
+ exit 0

But to me it looks like the files really can't be found? The only difference I can see in bin/dokku-deploy is that git config --global --add safe.directory "$PWD" is only called after review-apps:destroy is done, but I don't understand how that would influence it.

I hope that this is enough information to be helpful. If I can provide anything else, let me know. Thank you for taking time to look into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions