Overview
The Biblioteca Virtual Frontend uses GitHub Actions to automate the build and deployment process. The CI/CD pipeline automatically builds Docker images and pushes them to Docker Hub whenever changes are pushed to the main branch.GitHub Actions Workflow
The CI/CD pipeline is defined in.github/workflows/docker-frontend.yml:
Pipeline Stages
1
Trigger on Push
The workflow triggers automatically when code is pushed to the
main branch.2
Checkout Repository
Uses
actions/checkout@v4 to clone the repository code.3
Login to Docker Hub
Authenticates with Docker Hub using stored secrets.
4
Build Docker Image
Builds the Docker image using the multi-stage Dockerfile.
5
Push to Docker Hub
Pushes the built image to Docker Hub registry.
Required Secrets
Configure these secrets in your GitHub repository settings:DOCKERHUB_USERNAME
Your Docker Hub username. Settings Path:Repository > Settings > Secrets and variables > Actions > New repository secret
DOCKERHUB_TOKEN
Docker Hub access token for authentication. Settings Path:Repository > Settings > Secrets and variables > Actions > New repository secret
Creating a Docker Hub Access Token
1
Login to Docker Hub
Navigate to hub.docker.com and sign in.
2
Account Settings
Go to Account Settings > Security.
3
Generate Token
Click “New Access Token” and provide a description.
4
Copy Token
Copy the generated token immediately (it won’t be shown again).
5
Add to GitHub
Add the token as
DOCKERHUB_TOKEN in GitHub repository secrets.Workflow Customization
Build with Tags
Add version tags to your Docker images:Add Testing Step
Include tests before building:Multi-Environment Deployment
Deploy to different environments based on branches:Monitoring Pipeline Execution
View Workflow Runs
Navigate to your repository on GitHub:Check Build Logs
Click on a workflow run to view detailed logs for each step.Workflow Status Badge
Add a status badge to your README:Deployment Options
Pull and Run Latest Image
After the pipeline completes, pull the latest image:Auto-Deploy with Watchtower
Use Watchtower to automatically update running containers:Watchtower checks for image updates every 5 minutes (300 seconds) and automatically restarts containers with the latest version.
Advanced CI/CD Patterns
Cache Dependencies
Speed up builds by caching npm dependencies:Parallel Jobs
Run tests and linting in parallel:Notifications
Send notifications on build completion:Troubleshooting
Authentication Failure
If login to Docker Hub fails:- Verify
DOCKERHUB_USERNAMEis correct - Ensure
DOCKERHUB_TOKENis valid and has not expired - Check token permissions
Build Failure
Common issues:- Out of memory: Increase runner resources
- Dependency errors: Clear cache and rebuild
- Dockerfile syntax: Validate Dockerfile locally
Push Failure
If pushing to Docker Hub fails:- Verify repository exists on Docker Hub
- Check authentication token permissions
- Ensure image name matches Docker Hub repository
Best Practices
- Use specific action versions: Pin to specific versions (e.g.,
@v4) - Secure secrets: Never log or expose secret values
- Tag images: Use semantic versioning for production releases
- Test locally: Validate builds locally before pushing
- Monitor workflows: Set up notifications for failures
- Cache dependencies: Speed up builds with caching
- Run tests: Always test before deploying