Skip to main content

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
Never commit Docker Hub credentials to your repository. Always use GitHub Secrets.

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:
  1. Verify DOCKERHUB_USERNAME is correct
  2. Ensure DOCKERHUB_TOKEN is valid and has not expired
  3. 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:
  1. Verify repository exists on Docker Hub
  2. Check authentication token permissions
  3. Ensure image name matches Docker Hub repository

Best Practices

  1. Use specific action versions: Pin to specific versions (e.g., @v4)
  2. Secure secrets: Never log or expose secret values
  3. Tag images: Use semantic versioning for production releases
  4. Test locally: Validate builds locally before pushing
  5. Monitor workflows: Set up notifications for failures
  6. Cache dependencies: Speed up builds with caching
  7. Run tests: Always test before deploying

Manual Workflow Trigger

Enable manual workflow dispatch:
Then trigger manually from GitHub Actions tab.