launchrctl / launchr

Launchr is a CLI action runner that executes actions inside short-lived local containers.
Apache License 2.0
10 stars 2 forks source link

Change working directory when running action #24

Closed davidferlay closed 6 months ago

davidferlay commented 7 months ago

Observed

Currently we have some actions brought by compose package :

Expected

We need to update launchrctl so that some actions can be executed from current directory, so that the user doesn't have to worry about .compose at all.

This would require:

davidferlay commented 7 months ago

Aleksandr BRITVIN @abritvin
I think we may define on compose plugin level
I guess compose may alter discovered actions to exclude the prefix of .compose/build/
With that no need for a flag
Compose plugin defines the behavior for its actions

David Ferlay @dferlay
makes sense indeed
any opinion about second part Aleksandr BRITVIN ?

Aleksandr BRITVIN @abritvin
You need to change a Working Directory when running an action?
Currently we are running from CWD => /host
And you want /my/path => /host ?

David Ferlay @dferlay
yes
for certain actions only
so could be a new setting in action.yaml for it

Aleksandr BRITVIN @abritvin
I think yes, we must define in action.yaml

David Ferlay @dferlay
compose plugin could introduce that ? or need an update in launchrctl level

Aleksandr BRITVIN @abritvin
It's on launchr level

Igor IGNATYEV @iignatyev
not necessary to involve compose. Action can be written to target .compose on their own and rely on data in ./compose/build, or provide option to look there.
At least i have 1 action that will require getting inventory from .compose/build and retrieving git logs from .compose/packages

David Ferlay @dferlay
compose part would only be about altering names of actions brought by compose

Aleksandr BRITVIN @abritvin
I suppose we'll need a bit of refactoring to support that
lexbritvin commented 7 months ago

Discovery example output for compose:

Actions:
  plasma-core.platform:compare-artifacts    Compare artifacts: Current artifact vs target branch's artifact (download it and generate diff file)
  plasma-core.platform:components-propagate Propagate versions of components: Update version of resources using diff file
  plasma-core.platform:deploy               Deploy: Deploy Ansible resources to target cluster
davidferlay commented 7 months ago

So new behavior implemented in https://github.com/launchrctl/launchr/commit/f711c2d326807ca6a4848c4688453375c10e73c9, https://github.com/launchrctl/launchr/commit/e3f3c9cbe889dd5d0d5c39ef75deca02777661b7 and https://github.com/launchrctl/compose/pull/28 makes all actions from .compose/build to be executable from current dir but actualy run in .compose/build

Although that behavior solves our current DX issue, it's hardcoded and applies to all actions from .compose/build whereas some actions from .compose/build may need to be executed from current dir but actualy run in current dir

I think most flexible way is to add an optional "working-directory" attribute in action.yaml. That way, action creator will be able to specify in which directory action should be executed

For instance:

  1. While in main repo dir, action Test1 located in .compose/build/platform/actions/test1 dir should appear as platform:test1 in launchrctl and be executed in .compose/build dir
    action:
    title: test1
    description: Test wd specific dir
    image: buildargs:latest
    build:
    context: ./
    tags:
      - buildargs:latest
    working-directory: .compose/build     <----------- here
    command:
    - sh
    - /action/main.sh
  2. On the other hand, action2 located in .compose/build/platform/actions/test2 should also appear as platform:test1 in launchrctl but it should be executed in current dir
    action:
    title: test2
    description: Test wd current dir
    image: buildargs:latest
    build:
    context: ./
    tags:
      - buildargs:latest
    command:
    - sh
    - /action/main.sh

    (no working-directory attribute would default to execute in current dir)

Note that in both case, we need ability to execute action from current dir, with a nice name