This repository includes GitHub Actions workflows for building, pushing Docker images, and deploying via ArgoCD.
- Triggers:
- Push to
mainordevelopbranches (whenbackend/**files change) - Pull requests to
mainbranch - Manual workflow dispatch
- Push to
- Features:
- Builds and pushes Docker image to GitHub Container Registry
- Runs security scan with Trivy
- Automatically deploys to ArgoCD on push to
main - Supports manual deployment with custom image tag
- Automatic rollback on deployment failure
- Triggers:
- Push to
mainbranch - Manual workflow dispatch
- Push to
- Features:
- Deploys existing Docker images via ArgoCD API
- Manual rollback capability
- Deployment status monitoring
Configure these secrets in your GitHub repository settings:
ARGOCD_SERVER: Your ArgoCD server URL (e.g.,https://argocd.example.com)ARGOCD_TOKEN: ArgoCD authentication token
- Using ArgoCD CLI:
argocd account generate-token --account <username>-
Using ArgoCD UI:
- Login to ArgoCD UI
- Go to User Info → Generate New Token
- Copy the generated token
-
Using API:
curl -k -X POST https://your-argocd-server/api/v1/session \
-d '{"username":"admin","password":"your-password"}' | \
jq -r '.token'- Builds Docker image from
backend/directory - Tags with branch name and commit SHA
- Pushes to
ghcr.io/[owner]/[repo]/backend - Runs security scanning with Trivy
- Only runs on actual code changes (not on manual dispatch if
skip_buildis true)
- Updates ArgoCD application with new image
- Triggers sync operation
- Monitors deployment progress (up to 10 minutes)
- Provides detailed status reporting
- Creates deployment summary in GitHub Actions
- Automatically triggers on deployment failure
- Rolls back to previous revision
- Provides rollback status summary
Use workflow dispatch with:
image_tag: Specify the image tag to deployskip_build: Set totrueto skip building and deploy existing image
- Go to Actions tab in GitHub
- Select "Build, Push, and Deploy via ArgoCD"
- Click "Run workflow"
- Enter image tag (e.g.,
main-abc1234) - Check "Skip build" if deploying existing image
Your ArgoCD application should be configured to use Kustomize with image replacement:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nodejs-app
spec:
source:
repoURL: https://github.com/your-org/your-repo
path: k8s
targetRevision: main
kustomize:
images:
- ghcr.io/your-org/your-repo/backend:main-latestThe workflow provides:
- Real-time sync and health status
- Deployment completion confirmation
- ArgoCD application details
- Direct links to ArgoCD UI
-
Invalid ArgoCD credentials
- Verify
ARGOCD_SERVERandARGOCD_TOKENsecrets - Ensure token has proper permissions
- Verify
-
Application not found
- Verify ArgoCD application name is
nodejs-app - Or update workflow to use your application name
- Verify ArgoCD application name is
-
Image not found
- Ensure Docker image was built and pushed successfully
- Check GitHub Container Registry for image availability
-
Deployment timeout
- Check ArgoCD application sync status
- Review Kubernetes pod logs
- Verify cluster resources
- Check GitHub Actions logs for detailed error messages
- Monitor ArgoCD UI for sync status
- Review ArgoCD application events
- Use GitHub Container Registry with proper authentication
- Store ArgoCD credentials as GitHub secrets
- Enable vulnerability scanning with Trivy
- Use least-privilege access for ArgoCD tokens
- Regular token rotation recommended
Replace nodejs-app with your ArgoCD application name in both workflows.
Update REGISTRY and IMAGE_NAME environment variables to use different container registry.
Modify the polling loop in "Wait for deployment completion" step to change timeout duration.
Integrate with Slack, Discord, or other notification services by adding notification steps.