Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
nginx_version: ['1.24.0', '1.25.3', '1.26.0']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
libpcre3 libpcre3-dev \
zlib1g zlib1g-dev \
libssl-dev \
libzstd-dev \
perl \
cpanminus

- name: Install Perl test dependencies
run: |
sudo cpanm --notest Test::Nginx

- name: Cache nginx
id: cache-nginx
uses: actions/cache@v4
with:
path: ~/nginx-${{ matrix.nginx_version }}
key: nginx-${{ matrix.nginx_version }}-${{ matrix.os }}

- name: Download and extract nginx
if: steps.cache-nginx.outputs.cache-hit != 'true'
run: |
cd ~
NGINX_VERSION="${{ matrix.nginx_version }}"
wget -q "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz"
tar -xzf "nginx-${NGINX_VERSION}.tar.gz"

- name: Configure and build nginx with zstd module
run: |
cd ~/nginx-${{ matrix.nginx_version }}
./configure \
--prefix=/tmp/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--add-module=${{ github.workspace }}
make -j$(nproc)
sudo make install

- name: Add nginx to PATH
run: |
echo "/tmp/nginx/sbin" >> $GITHUB_PATH

- name: Verify nginx installation
run: |
/tmp/nginx/sbin/nginx -V

- name: Run tests
run: |
export PATH=/tmp/nginx/sbin:$PATH
cd ${{ github.workspace }}
prove -r t/
env:
TEST_NGINX_BINARY: /tmp/nginx/sbin/nginx

build-docker:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build test Dockerfile
run: |
cat > Dockerfile.test << 'EOF'
FROM nginx:1.26.0 AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpcre3-dev \
zlib1g-dev \
libssl-dev \
libzstd-dev \
wget \
&& rm -rf /var/lib/apt/lists/*

# Get nginx source
WORKDIR /build
RUN wget -q http://nginx.org/download/nginx-1.26.0.tar.gz && \
tar -xzf nginx-1.26.0.tar.gz

# Copy module source
COPY . /build/zstd-nginx-module

# Build nginx with zstd module
WORKDIR /build/nginx-1.26.0
RUN ./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_slice_module \
--with-threads \
--with-file-aio \
--add-module=/build/zstd-nginx-module && \
make -j$(nproc) && \
make install

# Runtime stage
FROM nginx:1.26.0

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libzstd1 \
&& rm -rf /var/lib/apt/lists/*

# Copy compiled nginx with zstd module
COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx

# Test configuration
RUN nginx -V 2>&1 | grep zstd

EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
EOF

- name: Build Docker image
run: |
docker build -f Dockerfile.test -t nginx-zstd:test .

- name: Test Docker image
run: |
# Start container
docker run -d --name nginx-zstd-test nginx-zstd:test
sleep 2

# Check if nginx is running
docker ps | grep nginx-zstd-test

# Check nginx version includes zstd
docker exec nginx-zstd-test nginx -V 2>&1 | grep zstd

# Cleanup
docker stop nginx-zstd-test
docker rm nginx-zstd-test

lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check for trailing whitespace
run: |
if git grep -I --line-number -P '\s+$' -- '*.c' '*.h' 'config' \
2>/dev/null; then
echo "Error: Found trailing whitespace"
exit 1
else
echo "No trailing whitespace found"
fi

- name: Check file permissions
run: |
# Check that source files don't have execute permissions
if find . -name '*.c' -o -name '*.h' | xargs ls -l \
| grep '^-rwxr'; then
echo "Error: Source files should not be executable"
exit 1
else
echo "File permissions are correct"
fi
170 changes: 170 additions & 0 deletions CI_CD_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# CI/CD Implementation Summary

This document describes the CI/CD implementation for the zstd-nginx-module project.

## Overview

A comprehensive GitHub Actions CI/CD pipeline has been implemented to automatically build and test the zstd-nginx-module with various nginx versions and operating systems.

## Workflow File

Location: `.github/workflows/ci.yml`

## CI/CD Features

### 1. Test Job

The main test job builds nginx with the zstd module and runs the test suite:

**Matrix Testing:**
- **Operating Systems:** Ubuntu 20.04, Ubuntu 22.04
- **Nginx Versions:** 1.24.0, 1.25.3, 1.26.0
- **Total Combinations:** 6 test configurations

**Steps:**
1. Checkout code
2. Install system dependencies (build tools, libzstd, perl, etc.)
3. Install Perl test dependencies (Test::Nginx)
4. Cache nginx source for faster builds
5. Download and extract nginx source (if not cached)
6. Configure nginx with zstd module using `--add-module`
7. Build nginx
8. Install nginx
9. Verify installation
10. Run test suite with `prove -r t/`

### 2. Docker Build Job

Tests building a Docker image with nginx and zstd module:

**Steps:**
1. Creates a multi-stage Dockerfile for optimal image size
2. Builds nginx with zstd module in builder stage
3. Copies compiled binary to runtime stage
4. Verifies the module is properly integrated
5. Tests the container runs correctly

### 3. Lint Job

Performs basic code quality checks:

**Checks:**
- Trailing whitespace in source files
- Incorrect file permissions on source files

## Example Files

Three example files have been added to help users:

### 1. `example/nginx.conf`

Complete nginx configuration demonstrating:
- Global zstd compression settings
- Compression level configuration
- Minimum length thresholds
- MIME type filtering
- Static pre-compressed file serving
- Compression ratio logging

### 2. `example/Dockerfile`

Production-ready multi-stage Dockerfile showing:
- How to build nginx with zstd module
- Proper dependency installation
- Optimized layer caching
- Runtime image preparation
- Health checks

### 3. `example/README.md`

Comprehensive documentation covering:
- Docker usage instructions
- Manual build process
- Configuration examples
- Testing compression
- Performance tips
- Browser compatibility notes

## Documentation Updates

### README.md

Added:
- CI status badge showing workflow status
- Docker installation section with quick start
- Link to example documentation

## Workflow Triggers

The CI workflow runs on:
- Push to `main` or `master` branches
- Pull requests to `main` or `master` branches
- Manual workflow dispatch

## Caching Strategy

The workflow uses GitHub Actions cache to speed up builds:
- **Cached:** nginx source code by version and OS
- **Benefits:** Faster subsequent builds, reduced network usage

## Testing

The test suite uses the Test::Nginx framework which:
- Starts temporary nginx instances
- Tests module functionality
- Validates configuration options
- Ensures proper compression behavior

## Status

✅ CI/CD workflow created and validated
✅ YAML syntax verified with yamllint
✅ Example configurations provided
✅ Documentation updated
⏳ Workflow pending approval (common for new workflows)

## Next Steps for Users

1. **Repository Maintainer:** Approve the workflow run in GitHub Actions
2. **Review Results:** Check the workflow runs to ensure all tests pass
3. **Customize:** Adjust nginx versions or OS versions as needed
4. **Extend:** Add more test cases or additional checks

## Maintenance

To update the CI/CD:

### Add a New Nginx Version

Edit `.github/workflows/ci.yml`:
```yaml
matrix:
nginx_version: ['1.24.0', '1.25.3', '1.26.0', '1.27.0'] # Add new version
```

### Add a New OS Version

Edit `.github/workflows/ci.yml`:
```yaml
matrix:
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04] # Add new OS
```

### Add More Tests

Add new test files to the `t/` directory following the Test::Nginx format.

## Benefits

1. **Automated Testing:** Every change is automatically tested
2. **Multi-Version Support:** Ensures compatibility across nginx versions
3. **Quality Assurance:** Catches build and test failures early
4. **Documentation:** Examples help users get started quickly
5. **Visibility:** CI badge shows project health at a glance

## Resources

- [GitHub Actions Documentation](https://docs.github.com/en/actions)
- [Test::Nginx Documentation](https://metacpan.org/pod/Test::Nginx::Socket)
- [Nginx Module Development](https://nginx.org/en/docs/dev/development_guide.html)
- [Zstandard Compression](https://facebook.github.io/zstd/)
Loading