Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13: [Bug]: Cyclic dependency when using different build target based on deploy mode #4603

Closed
stefreak opened this issue Jun 12, 2023 · 5 comments
Labels

Comments

@stefreak
Copy link
Member

stefreak commented Jun 12, 2023

Garden Bonsai (0.13) Bug

When using "sync" deploy mode it is necessary for compiled languages to use a different build target, because you need the tools to compile the code which you don't need without sync mode.

Current Behavior

Cyclic dependency, node was:"Deploy.limiter"

Expected behavior

I'd like an easy way of doing this without an error as it's a quite common use case.

Reproducible example

kind: Build
type: container
name: myservice
spec:
  dockerfile: Dockerfile
  targetStage: "${actions.deploy.myservice.mode == 'sync' && 'dev' || 'prod'}"

---

kind: Deploy
type: container
name: myservice
build: myservice
spec:
  sync:
    command: [air]
    paths:
      - target: /app
        source: .
        mode: one-way-replica
        exclude: []
  ports:
    - name: http
      containerPort: 8080
      servicePort: 80
  ingresses:
    - path: /
      port: http
      hostname: myservice.${var.base-hostname}

Workaround

Something like

${command.params contains 'sync' || isEmpty(command.params.sync)}

can be used as a workaround.

Suggested solution(s)

Not sure how to solve this in a good way. Maybe the deploys with sync mode enabled should be just a list and globally available from any actions.

Additional context

Your environment

  • OS: macOs
  • How I'm running Kubernetes:

garden version 0.13.2

@stefreak stefreak added the 0.13 label Jun 12, 2023
@edvald
Copy link
Collaborator

edvald commented Jun 12, 2023

We might be able to allow referencing the action modes without making a dependency on the resolution, but the better solution will be parameterized actions, which has a design draft already.

In the meantime, I'd suggest making two separate builds with the different stages, instead of referencing the dependency in a single build.

@stefreak
Copy link
Member Author

@edvald interesting idea to make two different builds! I'll try that. Thank you.

@stefreak
Copy link
Member Author

Here is a working workaround using your suggestion:

# Production container to be used without sync mode.
kind: Build
type: container
name: limiter-prod
include:
  - src
  - Dockerfile
exclude:
  - src/tmp/*
spec:
  dockerfile: "Dockerfile"

---

# The sync container only provides the tools necessary for building the library
# when using it during inner loop development together with Garden's sync mode.
kind: Build
type: container
name: limiter-sync
include:
  - Dockerfile
spec:
  dockerfile: "Dockerfile.syncmode"

---

kind: Deploy
type: container
name: limiter
build:
  $if: ${command.params contains 'sync' && (command.params.sync contains 'limiter' || isEmpty(command.params.sync))}
  $then: limiter-sync
  $else: limiter-prod
[...]

I wasn't able to use ${this.mode} unfortunately because of #4616

@Walther
Copy link
Contributor

Walther commented Jun 13, 2023

Another example of syncing compiled languages without the problem described in this issue, but with a rather significant caveat: if you switch between sync deployment and normal deployment, you will rebuild the image. That isn't great - if/when we figure out a proper solution for the problem discussed in this issue thread, we should definitely convert that example to use that solution instead as well - but could work as a workaround for some users.

@vvagaytsev
Copy link
Collaborator

#4616 was fixed and ${this.mode} is available now. The quickstart-example PR was updated with the new syntax. Closing this as there is a nice workaround.

@vvagaytsev vvagaytsev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants