6

we are trying to use GitOps at my company using ArgoCD and we have one primary concern:

Jenkins, our CI tool, currently pushed to our docker repo on merge of any PR with a tag relating to the git commit hash currently in use.

Edit: We would like, upon choosing a targetRevision, to get its git hash as a string to use in value overwriting the imageTag in our helm charts.

Now Option 1 is we just have it also change the imageTag in any relevant kubernetes files.

However I wonder if there is a way using PreSync hooks for ArgoCD to do this automatically. It knows the git hash already as it has pulled git. And having Jenkins make a git commit is never ideal.

Thanks for the help!

Ryan
  • 451
  • 4
  • 11
  • having bots do commits to Git is ideal for GitOps. yes, it feels weird, but this is not source CODE, its CONFIGS. we leverage SOPS to encrypt secrets and have a GHA bot automatically make a PR and mark it as automerge to bump a container tag (if CI publishes a new image) – LostJon Sep 14 '21 at 12:13

1 Answers1

1

You might use the targetRevision: HEAD

https://github.com/argoproj/argocd-example-apps/blob/master/apps/values.yaml

So application config in ArgoCD goes like

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: message-app-staging
  namespace: argocd
  environment: staging
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default

  # Source of the application manifests
  source:
    repoURL: https://github.com/akash-gautam/message-app-manifests.git
    targetRevision: HEAD
    path: manifests/staging

  # Destination cluster and namespace to deploy the application
  destination:
    server: https://kubernetes.default.svc
    namespace: staging

  syncPolicy:
    automated:
      prune: false
      selfHeal: false

If a branch name, or a symbolic reference (like HEAD) is specified, Argo CD will continually compare live state against the resource manifests defined at the tip of the specified branch or the resolved commit of the symbolic reference.

Above case would be best to use with helm.

If you have static Manifest in YAML i would suggest to also checkout : https://github.com/Alwinius/bow or https://github.com/keel-hq/keel

Bow detects updated image tags from a Docker registry of images defined in a GitOps deployment repository containing Kubernetes Deployments/StatefulSets or Helm templates.

Extra : https://www.padok.fr/en/blog/argocd-image-updater

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • 3
    This won’t help us override the image tag of the docker image repo urls in our helm charts when pulling the GitHub. This will just make sure we pull the helm charts from HEAD. What I really need is to tell ArgoCD to overwrite a value in a helm chart with the value of the git sha it has pulled with targetRevision. I just need that environment variable to make it work. – Ryan Sep 12 '21 at 03:18
  • 1
    @Ryan were you able to resolve this; we are hitting the same issue and like to override the image tag in the values.yml based on the COMMIT_ID which is available in the pipeline env. – Paul Bormans Jun 13 '22 at 10:20
  • 1
    is there any solution to this question.? – SHC Nov 23 '22 at 15:05