The part that confuses me about gitops is the recommendation to separate source-code from manifests, e.g. This is what argocd has to say about it:
The use of a different Git repository to hold your kubernetes manifests (separate from your application source code), is highly recommended. See best practices for further rationale.
In a typical project, I would use gitlab to setup a test environment and then on_stop
action to delete the environment for each PR. However, if I separate manifests from the source code, it is not clear what argocd is supposed to be watching.
For the sake of example lets assume that we have two repositories:
foo
hosts the app codebar
hosts manifests of different apps
Suppose:
- I've created a new branch
feature-001
infoo
branch. - Every time we add a commit to
feature-001
it creates a new docker image (foo:$COMMIT_SHA
).
How would I create a argocd controlled app that watches this branch for changes?
I can of course create the app using CLI:
argocd app create "foo-$COMMIT_SHA" --repo https://github.com/gajus/bar.git --path bar -p image=foo:$COMMIT_SHA
but how would ArgoCD know to track this feature-001
branch for changes?, i.e. How do I tell argocd to deploy a new version of the app when a new Docker image is published from this branch?
I am not sure why you are dismissing the CLI option. The CLI can create an application including pointing to a git revision which (can be a branch).
For example:
Note the automated sync-policy being set here. That will meant that any updates to the revision will update the branch.
The above answer explains how the ArgoCD Application can track git changes, but this question hints at the issue of updating the tag within the deployment/replicaset manifest. This is highly dependent on how you do this for your main branch. Some people will have that hard coded, others commit the
$COMMIT_SHA
from repofoo
to repobar
, and others use a templating language and inject variables.Based on your concern I am going to assume you follow the commit from repo
foo
to repobar
approach. If this is the case, I would suggest adding the flag--upsert
into the CLI command and just running the same CLI command each time in your branch pipeline.NOTE: Added bonus option here is to add an additional flag for something like
--label branch=${BRANCH_NAME}
. This can then be used to find/cleanup any branch deploys on a regular basis.