This directory contains GitHub Actions workflows for continuous integration and deployment of Next.js applications.
.github/workflows/
├── ci.yml - Continuous Integration workflow
└── cd.yml - Continuous Deployment workflow
The CI workflow runs on every push to main and develop branches, as well as on pull requests to these branches. It performs the following tasks:
- Checks code quality using ESLint
- Ensures code follows project standards and best practices
- Runs Jest tests to verify functionality
- Ensures all tests pass before allowing deployment
- Builds the Next.js application
- Verifies that the build process completes successfully
- Uploads build artifacts for potential use in deployment
- Uses Snyk to scan for vulnerabilities in dependencies
- Runs OWASP ZAP scan for security issues
- Identifies potential security concerns before deployment
The CD workflow runs when code is pushed to main or develop branches, or when a version tag is created. It automates the deployment process:
- Automatically determines the target environment based on branch or tag
- Sets appropriate image tags for Docker images
- Builds the Docker image using the production Dockerfile
- Pushes the image to DockerHub with appropriate tags
- Utilizes caching for faster builds
- Updates Kubernetes manifests with the new image tag
- Applies the changes to the appropriate environment
- Verifies successful deployment
- Sends Slack notifications about deployment status
- Provides quick feedback on deployment success or failure
The following secrets need to be configured in your GitHub repository:
SNYK_TOKEN: API token for Snyk vulnerability scanning
DOCKERHUB_USERNAME: DockerHub usernameDOCKERHUB_TOKEN: DockerHub access tokenAWS_ACCESS_KEY_ID: AWS access key for EKS accessAWS_SECRET_ACCESS_KEY: AWS secret key for EKS accessAWS_REGION: AWS region where EKS cluster is locatedEKS_CLUSTER_NAME: Name of the EKS clusterSLACK_WEBHOOK: Webhook URL for Slack notifications
To customize these workflows for your specific needs:
- Modify the branch triggers in the
onsection - Adjust environment names and conditions in the
set-environmentjob - Update Docker image names and tags in the
build-and-pushjob - Modify Kubernetes deployment paths in the
deployjob
- Store sensitive information in GitHub Secrets
- Use specific versions for GitHub Actions to prevent unexpected changes
- Implement security scanning as part of the CI process
- Use caching for dependencies and Docker layers
- Run jobs in parallel when possible
- Only run necessary steps based on changes
- Verify deployments with health checks
- Implement notifications for deployment status
- Use environment protection rules for production deployments
- Secret Management: Ensure all required secrets are properly configured
- Permission Issues: Ensure GitHub Actions has appropriate permissions
- Resource Constraints: Be aware of GitHub Actions minutes and resource limits
- Dependency Caching: Properly configure caching to speed up workflows
- Error Handling: Implement proper error handling and notifications