DevSpace hook for running tests in container after an update to the container

290 views Asked by At

My ultimate goal is to have tests run automatically anytime a container is updated. For example, if update /api, it should sync the changes between local and the container. After that it should automatically run the tests... ultimately.

I'm starting out with Hello World! though per the example:

# DevSpace --version = 5.16.0
version: v1beta11
...
hooks:
- command: |
    echo Hello World!
  container:
    imageSelector: ${APP-NAME}/${API-DEV}
  events: ["after:initialSync:${API}"]
...

I've tried all of the following and don't get the desired behavior:

stop:sync:${API}
restart:sync:${name}
after:initialSync:${API}
devCommand:after:sync

At best I can just get Hello World! to print on the initial run of devspace dev -b, but nothing after I make changes to the files for /api which causes files to sync.

Suggestions?

1

There are 1 answers

0
Lukas Gentele On BEST ANSWER

You will need a post-sync hook for this, which is separate from the DevSpace lifecycle hooks. You can define it with the dev.sync directly and it looks like this:

dev:
  sync:
  - imageSelector: john/devbackend
    onUpload:
      execRemote:         
        onBatch:          
          command: bash
          args:           
          - -c
          - "echo 'Hello World!' && other commands..."

More information in the docs: https://devspace.sh/cli/docs/configuration/development/file-synchronization#onupload