hey <@1072591948499664996> is it possible for acti...
# 🤖|ask-kapa
g
hey @microscopic-river-74022 is it possible for actions which are started in sync mode to select another targetImage as in normal deploy mode?
m
Please stand by @gentle-umbrella-55872 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
---------------------- Yes, it is possible to change the behavior of your actions in sync mode. You can use template expressions to detect sync mode and change behavior accordingly. This can be done much easier with Bonsai via the
${actions.deploy.<name>.mode}
template string or
${this.mode}
if referenced in the action itself. Here is an example config that works with both Bonsai and 0.12. In this block the variables
sync-mode
or
dev-mode
are set to true if the relative mode is requested for the
api
service/deploy.
Copy code
yaml
variables:
 sync-mode: ${command.params contains 'sync' && (command.params.sync contains 'api' || isEmpty(command.params.sync))}
 dev-mode: ${command.name == 'dev' || (command.params contains 'dev-mode' && (command.params.dev-mode contains 'api' || isEmpty(command.params.dev-mode)))}
Sync mode or dev mode have been requested if either
var.sync-mode
or
var.dev-mode
are true. You can use a template expression like
${var.sync-mode || var.dev-mode ? 'yes' : 'no'}
to change the behavior of your actions or modules. For more information, you can check out the Garden documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
g
and how do i select then the targetImage?
@microscopic-river-74022 and how do i then select the targetImage?
m
Let me check the knowledge base for you. One moment! :books:
---------------------- To target a specific image from a multi-stage Dockerfile in Garden, you can use the
spec.targetStage
field. Here is an example:
Copy code
yaml
kind: Build
name: my-build
type: container
spec:
  targetStage: <your-target-stage>
Replace
<your-target-stage>
with the name of the stage you want to target in your Dockerfile. For more information, you can refer to the Garden documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
g
@microscopic-river-74022 how do i combine the condition sync to the targetImage?
m
Let me check the knowledge base for you. One moment! :books:
---------------------- To combine the condition for sync mode and target a specific image, you can use Garden's template strings. Here's an example of how you might do it:
Copy code
yaml
kind: Build
name: my-build
type: container
spec:
  targetStage: ${{var.sync-mode || var.dev-mode ? 'sync-target-stage' : 'default-target-stage'}}
In this example, if the
sync-mode
or
dev-mode
variable is true, the
targetStage
will be set to
'sync-target-stage'
. Otherwise, it will be set to
'default-target-stage'
. You should replace
'sync-target-stage'
and
'default-target-stage'
with the names of the stages in your Dockerfile. Please note that this is a hypothetical example and the actual implementation may vary based on your specific use case and Dockerfile configuration. For more information on how to use template strings in Garden, you can refer to the Garden documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------