Skip to main content

Synchronize Argo CD Application

In the following guide, we are going to create a self-service action in Port that executes a GitHub workflow to sync an argo cd application. With this, you can manage your Argo CD Application without leaving Port.

Prerequisites​

  1. Port's GitHub app needs to be installed.
  2. In your GitHub repository, go to Settings > Secrets and add the following secrets:
  3. Optional - Install Port's Argo CD integration learn more
Argo CD Integration

This step is not required for this example, but it will create all the blueprint boilerplate for you, and also ingest and update the catalog in real time with your Argo CD Applications.

  1. In Case you decided not to install the Argo CD integration, you will need to create a blueprint for the Argo CD Application in Port.
Argo CD Application Blueprint
  {
"identifier": "argocdApplication",
"description": "This blueprint represents an ArgoCD Application",
"title": "Running Service",
"icon": "Argo",
"schema": {
"properties": {
"gitRepo": {
"type": "string",
"icon": "Git",
"title": "Repository URL",
"description": "The URL of the Git repository containing the application source code"
},
"gitPath": {
"type": "string",
"title": "Path",
"description": "The path within the Git repository where the application manifests are located"
},
"destinationServer": {
"type": "string",
"title": "Destination Server",
"description": "The URL of the target cluster's Kubernetes control plane API"
},
"revision": {
"type": "string",
"title": "Revision",
"description": "Revision contains information about the revision the comparison has been performed to"
},
"targetRevision": {
"type": "string",
"title": "Target Revision",
"description": "Target Revision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch"
},
"syncStatus": {
"type": "string",
"title": "Sync Status",
"enum": [
"Synced",
"OutOfSync",
"Unknown"
],
"enumColors": {
"Synced": "green",
"OutOfSync": "red",
"Unknown": "lightGray"
},
"description": "Status is the sync state of the comparison"
},
"healthStatus": {
"type": "string",
"title": "Health Status",
"enum": [
"Healthy",
"Missing",
"Suspended",
"Degraded",
"Progressing",
"Unknown"
],
"enumColors": {
"Healthy": "green",
"Missing": "yellow",
"Suspended": "purple",
"Degraded": "red",
"Progressing": "blue",
"Unknown": "lightGray"
},
"description": "Status holds the status code of the application or resource"
},
"createdAt": {
"title": "Created At",
"type": "string",
"format": "date-time",
"description": "The created timestamp of the application"
},
"labels": {
"type": "object",
"title": "Labels",
"description": "Map of string keys and values that can be used to organize and categorize object"
},
"annotations": {
"type": "object",
"title": "Annotations",
"description": "Annotations are unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"project": {
"title": "ArgoCD Project",
"target": "argocdProject",
"required": false,
"many": false
},
"cluster": {
"title": "ArgoCD Cluster",
"target": "argocdCluster",
"required": false,
"many": false
},
"namespace": {
"title": "ArgoCD Namespace",
"target": "argocdNamespace",
"required": false,
"many": false
}
}
}
  1. Create a workflow file under .github/workflows/sync-argocd-app.yaml with the following content:
tip

We recommend creating a dedicated repository for the workflows that are used by Port actions.

GitHub Workflow
name: Sync Argo CD Application
on:
workflow_dispatch:
inputs:
application_name:
description: The Argo CD Application Name. e.g. app.example.com
required: true
port_payload:
required: true
description: >-
Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)

jobs:
sync-argocd-app:
runs-on: ubuntu-latest
steps:
- name: Log Executing Request to Sync Application
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(github.event.inputs.port_payload).context.runId}}
logMessage: "About to make a request to argocd server..."

- name: Sync Argo CD Application
uses: omegion/argocd-actions@v1
with:
address: ${{ secrets.ARGOCD_APPLICATION_HOST }}
token: ${{ secrets.ARGOCD_TOKEN }}
action: sync
appName: ${{ github.event.inputs.application_name }}

- name: Log If Request Fails
if: failure()
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(github.event.inputs.port_payload).context.runId}}
logMessage: "Request to sync Argo CD application failed ..."

- name: Report Sync Success
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(github.event.inputs.port_payload).context.runId}}
logMessage: "Successfully synced Argo CD Aplication ✅"

Port Configuration​

Create a new self service action using the following JSON configuration.

Sync Argo CD Application (click to expand)
Modification Required

Make sure to replace <GITHUB_ORG> and <GITHUB_REPO> with your GitHub organization and repository names respectively.

{
"identifier": "argocdApplication_sync_application",
"title": "Sync Application",
"icon": "Argo",
"description": "Sync An Argo CD Application",
"trigger": {
"type": "self-service",
"operation": "DAY-2",
"userInputs": {
"properties": {
"application_name": {
"title": "Application Name",
"description": "Argo CD Application Name",
"icon": "Argo",
"type": "string",
"default": {
"jqQuery": ".entity.title"
}
}
},
"required": [
"application_name"
],
"order": [
"application_name"
]
},
"blueprintIdentifier": "argocdApplication"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "sync-argocd-app.yaml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"application_name\")) then \"application_name\" else null end}}": "{{.inputs.\"application_name\"}}",
"port_payload": {
"action": "{{ .action.identifier[(\"argocdApplication_\" | length):] }}",
"resourceType": "run",
"status": "TRIGGERED",
"trigger": "{{ .trigger | {by, origin, at} }}",
"context": {
"entity": "{{.entity.identifier}}",
"blueprint": "{{.action.blueprint}}",
"runId": "{{.run.id}}"
},
"payload": {
"entity": "{{ (if .entity == {} then null else .entity end) }}",
"action": {
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "sync-argocd-app.yaml",
"omitUserInputs": false,
"omitPayload": false,
"reportWorkflowStatus": true
},
"trigger": "{{.trigger.operation}}"
},
"properties": {
"{{if (.inputs | has(\"application_name\")) then \"application_name\" else null end}}": "{{.inputs.\"application_name\"}}"
},
"censoredProperties": "{{.action.encryptedProperties}}"
}
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}

Now you should see the Sync Argo CD Application action in the self-service page. 🎉

Let's test it!​

  1. Head to the Self Service hub
  2. Click on the Sync Argo CD Application action
  3. Choose the Argo CD Application you want to synchronize (In case you didn't install the Argo CD integration, it means you don't have any Argo CD application in Port yet, so you will need to create one manually in Port to test this action)
  4. Select the application you want to sync. The application_name field should auto-fill after this, if not, manually enter the application name.
  5. Click on Execute
  6. Done! wait for the application to be synchronized.

Congrats 🎉 You've successfully synchronized your Argo CD Application in Port 🔥

More Self Service Argo CD Actions Examples​