Compare commits
13 Commits
44a3bc1cf4
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
| fcbd2c5452 | |||
| 039531ce7b | |||
| 91fe69a0a2 | |||
| 81af16cedf | |||
| 03be79d149 | |||
| 1112e15d80 | |||
| 0c86b453a6 | |||
| 882755ffc8 | |||
| 2854955c74 | |||
| fa06beefdd | |||
| d7f1052305 | |||
| 8ab7ff54b9 | |||
| 993104e122 |
@@ -1,19 +1,19 @@
|
||||
name: Zabbix APK Builder
|
||||
|
||||
on:
|
||||
# Trigger on pushes to main/test branch
|
||||
# Trigger on pushes to main/test branch into the zabbix-apk-builder directory
|
||||
push:
|
||||
branches: [ main, test ]
|
||||
paths: [ 'zabbix-apk-builder/**' ]
|
||||
|
||||
# Scheduled check for new versions (daily at 6 AM UTC)
|
||||
# Scheduled runs at 06:00 UTC daily
|
||||
schedule:
|
||||
- cron: '0 6 * * *'
|
||||
|
||||
jobs:
|
||||
check-version:
|
||||
runs-on: ubuntu-latest
|
||||
# Skip the execution if the commit message contains [ci skip]
|
||||
# Skip the execution if the commit author is the bot itself to prevent loops
|
||||
if: ${{ gitea.event.head_commit.author.name != 'Gitea Action' }}
|
||||
outputs:
|
||||
should_build: ${{ steps.version-check.outputs.should_build }}
|
||||
@@ -30,47 +30,28 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Install jq for JSON parsing (remove sudo for container environment)
|
||||
apt-get update && apt-get install -y jq
|
||||
# Remove jq installation
|
||||
# apt-get update && apt-get install -y jq
|
||||
|
||||
# Detect trigger type
|
||||
if [[ "${{ gitea.event_name }}" == "push" ]]; then
|
||||
echo "is_push_trigger=true" >> "${GITHUB_OUTPUT}"
|
||||
echo "Triggered by push event - force build"
|
||||
else
|
||||
echo "is_push_trigger=false" >> "${GITHUB_OUTPUT}"
|
||||
echo "Triggered by schedule - check version"
|
||||
fi
|
||||
IS_PUSH="${{ gitea.event_name == 'push' }}"
|
||||
echo "is_push_trigger=${IS_PUSH}" >> "${GITHUB_OUTPUT}"
|
||||
|
||||
# Get current version from APKBUILD
|
||||
# Get versions
|
||||
CURRENT_VERSION=$(grep '^pkgver=' zabbix-apk-builder/APKBUILD | cut -d'=' -f2)
|
||||
echo "current_version=${CURRENT_VERSION}" >> "${GITHUB_OUTPUT}"
|
||||
echo "Current version: ${CURRENT_VERSION}"
|
||||
|
||||
# Get latest version from Zabbix API (stable releases only)
|
||||
LATEST_VERSION=$(curl -s "https://git.zabbix.com/rest/api/1.0/projects/ZBX/repos/zabbix/tags?limit=100" | \
|
||||
jq -r '.values[].displayId' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
|
||||
grep -v 'rc\|beta\|alpha' | \
|
||||
sort -V | \
|
||||
tail -1)
|
||||
grep -o '"displayId":"[^"]*"' | cut -d'"' -f4 | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | grep -v 'rc\|beta\|alpha' | \
|
||||
sort -V | tail -1)
|
||||
|
||||
echo "current_version=${CURRENT_VERSION}" >> "${GITHUB_OUTPUT}"
|
||||
echo "latest_version=${LATEST_VERSION}" >> "${GITHUB_OUTPUT}"
|
||||
echo "Latest version: ${LATEST_VERSION}"
|
||||
|
||||
# Determine if we should build based on trigger type
|
||||
if [[ "${{ gitea.event_name }}" == "push" ]]; then
|
||||
# Push trigger: always build to test changes
|
||||
# Always build on push, build on schedule if versions differ
|
||||
if [[ "${IS_PUSH}" == "true" || "${CURRENT_VERSION}" != "${LATEST_VERSION}" ]]; then
|
||||
echo "should_build=true" >> "${GITHUB_OUTPUT}"
|
||||
echo "Build required: Push trigger detected"
|
||||
elif [[ "${CURRENT_VERSION}" != "${LATEST_VERSION}" ]]; then
|
||||
# Schedule trigger: only build if version changed
|
||||
echo "should_build=true" >> "${GITHUB_OUTPUT}"
|
||||
echo "Build required: New version ${LATEST_VERSION} available"
|
||||
else
|
||||
# Schedule trigger: no new version
|
||||
echo "should_build=false" >> "${GITHUB_OUTPUT}"
|
||||
echo "No build required: Version ${CURRENT_VERSION} is current"
|
||||
fi
|
||||
|
||||
update-version:
|
||||
@@ -125,18 +106,6 @@ jobs:
|
||||
token: ${{ secrets.ACCESS_TOKEN }}
|
||||
ref: ${{ gitea.ref }}
|
||||
|
||||
- name: Pull latest changes if version was updated
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Pull any version updates that may have been committed
|
||||
if [[ "${{ needs.check-version.outputs.is_push_trigger }}" == "false" ]]; then
|
||||
echo "Scheduled build - pulling latest changes"
|
||||
git pull origin "${GITEA_REF_NAME:-main}" || true
|
||||
else
|
||||
echo "Push build - using current ref"
|
||||
fi
|
||||
|
||||
- name: Verify build environment
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -151,6 +120,8 @@ jobs:
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Zabbix packages
|
||||
env:
|
||||
CI_RUN_ID: ${{ gitea.run_id }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
@@ -158,26 +129,31 @@ jobs:
|
||||
chmod +x build.sh
|
||||
./build.sh
|
||||
|
||||
- name: List built packages
|
||||
- name: Verify and list built packages
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
cd zabbix-apk-builder
|
||||
|
||||
echo "=== Built packages ==="
|
||||
if [[ -d "zabbix-apk-builder/packages" ]]; then
|
||||
ls -la zabbix-apk-builder/packages/
|
||||
echo "=== Package sizes ==="
|
||||
find zabbix-apk-builder/packages/ -name "*.apk" -exec du -h {} \;
|
||||
else
|
||||
echo "ERROR: No packages directory found"
|
||||
# Verify packages exist somewhere
|
||||
PACKAGE_COUNT=$(find packages -name "*.apk" | wc -l)
|
||||
|
||||
if [[ $PACKAGE_COUNT -eq 0 ]]; then
|
||||
echo "ERROR: No packages found"
|
||||
find packages -type f 2>/dev/null || echo "packages directory is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found $PACKAGE_COUNT packages:"
|
||||
find packages -name "*.apk" -exec ls -lh {} \;
|
||||
|
||||
- name: Upload packages as artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: zabbix-apk-packages
|
||||
path: zabbix-apk-builder/packages/*.apk
|
||||
name: zabbix-apk-packages-${{ gitea.run_number }}
|
||||
path: zabbix-apk-builder/packages/**/*.apk
|
||||
retention-days: 30
|
||||
if-no-files-found: error
|
||||
|
||||
deploy-test:
|
||||
needs: [check-version, build-packages]
|
||||
@@ -186,45 +162,42 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Download packages
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: zabbix-apk-packages
|
||||
name: zabbix-apk-packages-${{ gitea.run_number }}
|
||||
path: packages/
|
||||
|
||||
- name: Test deployment in Alpine container
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "=== Testing package installation ==="
|
||||
# Find packages
|
||||
AGENT_PKG=$(find packages -name "zabbix-agent-*.apk" | head -1)
|
||||
PROXY_PKG=$(find packages -name "zabbix-proxy-*.apk" | head -1)
|
||||
|
||||
# Verify packages were downloaded
|
||||
if [[ ! -d "packages" ]] || [[ -z "$(ls -A packages/ 2>/dev/null)" ]]; then
|
||||
echo "ERROR: No packages found for testing"
|
||||
exit 1
|
||||
fi
|
||||
# Test function
|
||||
test_package() {
|
||||
local pkg="$1"
|
||||
local binary="$2"
|
||||
|
||||
if [[ -f "$pkg" ]]; then
|
||||
echo "Testing $(basename "$pkg")..."
|
||||
CONTAINER_ID=$(docker run -d alpine:latest sleep 30)
|
||||
docker cp "$pkg" "$CONTAINER_ID:/$(basename "$pkg")"
|
||||
if docker exec "$CONTAINER_ID" sh -c "
|
||||
apk add --allow-untrusted /$(basename "$pkg") >/dev/null 2>&1
|
||||
which $binary >/dev/null 2>&1
|
||||
$binary --version >/dev/null 2>&1
|
||||
"; then
|
||||
echo "SUCCESS: $(basename "$pkg") test passed"
|
||||
else
|
||||
echo "FAIL: $(basename "$pkg") test failed"
|
||||
fi
|
||||
docker rm -f "$CONTAINER_ID" >/dev/null
|
||||
else
|
||||
echo "ERROR: Package not found: $pkg"
|
||||
fi
|
||||
}
|
||||
|
||||
# Test agent package
|
||||
if ls packages/zabbix-agent-*.apk >/dev/null 2>&1; then
|
||||
echo "Testing agent package..."
|
||||
docker run --rm -v "${PWD}/packages:/packages" alpine:latest sh -c "
|
||||
apk add --allow-untrusted /packages/zabbix-agent-*.apk
|
||||
which zabbix_agentd
|
||||
zabbix_agentd --version
|
||||
" && echo "✅ Agent test passed" || echo "❌ Agent test failed"
|
||||
else
|
||||
echo "⚠️ No agent package found"
|
||||
fi
|
||||
|
||||
# Test proxy package
|
||||
if ls packages/zabbix-proxy-*.apk >/dev/null 2>&1; then
|
||||
echo "Testing proxy package..."
|
||||
docker run --rm -v "${PWD}/packages:/packages" alpine:latest sh -c "
|
||||
apk add --allow-untrusted /packages/zabbix-proxy-*.apk
|
||||
which zabbix_proxy
|
||||
zabbix_proxy --version
|
||||
" && echo "✅ Proxy test passed" || echo "❌ Proxy test failed"
|
||||
else
|
||||
echo "⚠️ No proxy package found"
|
||||
fi
|
||||
|
||||
echo "✅ Package deployment test completed"
|
||||
test_package "$AGENT_PKG" "zabbix_agentd"
|
||||
test_package "$PROXY_PKG" "zabbix_proxy"
|
||||
@@ -138,7 +138,11 @@ proxy() {
|
||||
install -dm755 "$subpkgdir"/var/log/zabbix
|
||||
install -dm755 "$subpkgdir"/var/run/zabbix
|
||||
}
|
||||
|
||||
# --- TEST ---
|
||||
sha512sums="
|
||||
SKIP
|
||||
SKIP
|
||||
SKIP
|
||||
SKIP
|
||||
SKIP
|
||||
"
|
||||
@@ -36,34 +36,32 @@ COPY --chown=builder:builder . /home/builder/zabbix/
|
||||
|
||||
WORKDIR /home/builder/zabbix
|
||||
|
||||
# Create build script
|
||||
# Create build script that just builds packages
|
||||
USER root
|
||||
RUN cat > /usr/local/bin/build-and-copy.sh << 'EOF'
|
||||
RUN cat > /usr/local/bin/build-packages.sh << 'EOF'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "Building packages as builder user..."
|
||||
sudo -u builder sh -c "
|
||||
cd /home/builder/zabbix
|
||||
echo 'Generating checksums...'
|
||||
abuild checksum
|
||||
echo 'Building packages...'
|
||||
abuild -r
|
||||
"
|
||||
|
||||
echo "Copying packages to output..."
|
||||
find /home/builder/packages -name '*.apk' -exec cp {} /output/ \;
|
||||
echo "Build complete! Packages built in /home/builder/packages:"
|
||||
find /home/builder/packages -name "*.apk" -exec ls -la {} \;
|
||||
|
||||
# Make files readable and writable by everyone (fixes permission issues)
|
||||
chmod 666 /output/*.apk 2>/dev/null || true
|
||||
echo "Setting proper permissions on packages..."
|
||||
chmod 644 /home/builder/packages/*.apk 2>/dev/null || true
|
||||
|
||||
# Also try changing ownership to a generic user ID that should work
|
||||
# Use UID 1000 which is common for CI runners
|
||||
chown 1000:1000 /output/*.apk 2>/dev/null || true
|
||||
|
||||
echo "Build complete! Packages:"
|
||||
ls -la /output/
|
||||
echo "Final package list (excluding APKINDEX):"
|
||||
find /home/builder/packages -name "*.apk" -exec ls -la {} \;
|
||||
EOF
|
||||
|
||||
RUN chmod +x /usr/local/bin/build-and-copy.sh
|
||||
RUN chmod +x /usr/local/bin/build-packages.sh
|
||||
|
||||
# Set build command
|
||||
CMD ["/usr/local/bin/build-and-copy.sh"]
|
||||
CMD ["/usr/local/bin/build-packages.sh"]
|
||||
@@ -4,8 +4,7 @@ Automated Alpine Linux package builder for Zabbix Agent and Proxy with CI/CD pip
|
||||
|
||||
## Features
|
||||
|
||||
- 🔄 **Automatic Version Detection**: Monitors Zabbix releases using official Bitbucket API
|
||||
- 🏗️ **Docker-based Building**: Consistent, reproducible builds in isolated environment
|
||||
- 🔄 **Automatic Version Detection**: Monitors Zabbix releases using Bitbucket API
|
||||
- 🚀 **CI/CD Pipeline**: Full automation from version detection to package deployment
|
||||
- 📦 **Multi-package Support**: Builds agent and proxy packages
|
||||
- 🧪 **Automated Testing**: Tests package installation in Alpine containers
|
||||
@@ -13,34 +12,24 @@ Automated Alpine Linux package builder for Zabbix Agent and Proxy with CI/CD pip
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Repository Setup
|
||||
### Prerequisites
|
||||
|
||||
- Docker installed
|
||||
- Gitea repository with Actions enabled
|
||||
|
||||
### Manual Build
|
||||
|
||||
```bash
|
||||
# Clone this repository
|
||||
git clone https://git.mbuz.uk/mbuz/Zabbix.git
|
||||
# Clone the repository
|
||||
git clone <your-gitea-repo>
|
||||
cd zabbix-apk-builder
|
||||
|
||||
# Make build script executable
|
||||
chmod +x build.sh
|
||||
```
|
||||
|
||||
### 2. Manual Build
|
||||
|
||||
```bash
|
||||
# Build packages locally
|
||||
chmod +x build.sh
|
||||
./build.sh
|
||||
|
||||
# Packages will be in ./packages/
|
||||
ls -la packages/
|
||||
```
|
||||
|
||||
### 3. CI/CD Setup
|
||||
|
||||
```bash
|
||||
# Run the setup script
|
||||
./setup-cicd.sh
|
||||
|
||||
# Follow the prompts to configure GitHub secrets
|
||||
# Check built packages
|
||||
ls -la packages/builder/x86_64/
|
||||
```
|
||||
|
||||
## Package Information
|
||||
@@ -51,19 +40,12 @@ ls -la packages/
|
||||
2. **zabbix-proxy** - Zabbix Proxy
|
||||
3. **zabbix** - Meta package
|
||||
|
||||
### Current Version
|
||||
|
||||
- **Zabbix Version**: 7.4.2
|
||||
- **Alpine Base**: latest
|
||||
- **Architecture**: all
|
||||
|
||||
## CI/CD Pipeline
|
||||
|
||||
### Automatic Triggers
|
||||
|
||||
- **Daily**: Checks for new Zabbix versions at 6 AM UTC
|
||||
- **Push**: Builds when code changes in main/test branches
|
||||
- **Manual**: Force builds via Gitea Actions
|
||||
|
||||
### Version Detection
|
||||
|
||||
@@ -91,48 +73,22 @@ GITEA_SSH_KEY # SSH private key for Gitea access
|
||||
### File Structure
|
||||
|
||||
```
|
||||
.
|
||||
└── zabbix-git
|
||||
└── zabbix-apk-builder
|
||||
├── .gitea/workflows # Workflows for Gitea actions
|
||||
├── .gitignore # Ignore files
|
||||
├── APKBUILD # APKBUILD file for Zabbix
|
||||
├── Dockerfile # Dockerfile for building packages
|
||||
├── README.md # Project description
|
||||
├── build.sh # Script for manual builds
|
||||
├── packages/ # Directory for built packages
|
||||
├── zabbix-agent.* # Agent configuration files
|
||||
└── zabbix-proxy.* # Proxy configuration files
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Install Packages
|
||||
|
||||
```bash
|
||||
# Add repository
|
||||
echo "http://gitea-repo/mbuz/Zabbix/raw/branch/main/alpine/v3.18/main" >> /etc/apk/repositories
|
||||
|
||||
# Update and install
|
||||
apk update
|
||||
apk add zabbix-agent
|
||||
|
||||
# Enable and start
|
||||
rc-update add zabbix-agent default
|
||||
rc-service zabbix-agent start
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
```bash
|
||||
# Configure agent
|
||||
vim /etc/zabbix/zabbix_agentd.conf
|
||||
|
||||
# Set server IP
|
||||
Server=your.zabbix.server
|
||||
|
||||
# Restart service
|
||||
rc-service zabbix-agent restart
|
||||
zabbix-git/
|
||||
└── zabbix-apk-builder/
|
||||
├── .gitea/
|
||||
│ └── workflows/
|
||||
│ └── build.yaml # Main CI/CD pipeline
|
||||
├── APKBUILD # Alpine package definition
|
||||
├── Dockerfile # Build environment container
|
||||
├── README.md # This file
|
||||
├── build.sh # Local build script
|
||||
├── packages/ # Generated packages (gitignored)
|
||||
├── zabbix-agent.confd # Agent configuration
|
||||
├── zabbix-agent.initd # Agent init script
|
||||
├── zabbix-agent.pre-install # Agent pre-install script
|
||||
├── zabbix-proxy.confd # Proxy configuration
|
||||
├── zabbix-proxy.initd # Proxy init script
|
||||
└── zabbix-proxy.pre-install # Proxy pre-install script
|
||||
```
|
||||
|
||||
## Development
|
||||
@@ -154,28 +110,16 @@ docker run --rm -it \
|
||||
|
||||
### Branch Strategy
|
||||
|
||||
- **main**: Production releases, auto-deployed
|
||||
- **test**: Testing and validation, no auto-deploy
|
||||
- **main**: Production releases, merge only
|
||||
- **test**: Testing and validation
|
||||
|
||||
### Making Changes
|
||||
|
||||
1. Create feature branch from `test`
|
||||
1. Create feature branch from `main`
|
||||
2. Test changes thoroughly
|
||||
3. Merge to `test` for CI validation
|
||||
4. Merge to `main` for production release
|
||||
3. Validate CI
|
||||
4. Merge to `main`
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Build Issues
|
||||
|
||||
```bash
|
||||
# Check build logs
|
||||
docker logs $(docker ps -l -q)
|
||||
|
||||
# Manual build debug
|
||||
docker run -it --rm -v $(pwd):/build alpine:3.18 sh
|
||||
cd /build && ./build.sh
|
||||
```
|
||||
|
||||
### Version Detection
|
||||
|
||||
|
||||
@@ -5,36 +5,55 @@ set -e
|
||||
# Configuration
|
||||
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
IMAGE_NAME="zabbix-apk-builder"
|
||||
CONTAINER_NAME="zabbix-build-$"
|
||||
# Use a unique ID from the CI environment if available, otherwise fall back to PID
|
||||
UNIQUE_ID="${CI_RUN_ID:-$$}"
|
||||
CONTAINER_NAME="zabbix-build-${UNIQUE_ID}"
|
||||
OUTPUT_DIR="$PROJECT_DIR/packages"
|
||||
|
||||
echo "=== Zabbix APK Builder ==="
|
||||
echo "Project directory: $PROJECT_DIR"
|
||||
echo "Output directory: $OUTPUT_DIR"
|
||||
|
||||
# Clean up any existing containers
|
||||
# Clean up function
|
||||
cleanup() {
|
||||
echo "Cleaning up..."
|
||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
||||
echo "Cleaning up container..."
|
||||
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
# Create output directory
|
||||
# Clean and create output directory
|
||||
rm -rf "$OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Build Docker image
|
||||
echo "Building Docker image..."
|
||||
docker build -t "$IMAGE_NAME" "$PROJECT_DIR"
|
||||
|
||||
# Run the build in container
|
||||
echo "Running package build..."
|
||||
docker run --rm \
|
||||
--name "$CONTAINER_NAME" \
|
||||
-v "$OUTPUT_DIR:/output" \
|
||||
"$IMAGE_NAME"
|
||||
# Run the build in the container
|
||||
echo "Running package build in container..."
|
||||
docker run --name "$CONTAINER_NAME" "$IMAGE_NAME"
|
||||
|
||||
echo "Build completed successfully!"
|
||||
echo "To install packages:"
|
||||
echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-agent-*.apk"
|
||||
echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-proxy-*.apk"
|
||||
# Copy packages from container to host
|
||||
echo "Copying packages from container..."
|
||||
if docker cp "$CONTAINER_NAME:/home/builder/packages/." "$OUTPUT_DIR/"; then
|
||||
echo "✅ Packages copied successfully"
|
||||
|
||||
# Remove APKINDEX files (we only want the .apk packages)
|
||||
echo "Removing repository index files..."
|
||||
find "$OUTPUT_DIR" -name "APKINDEX.tar.gz" -delete 2>/dev/null || true
|
||||
|
||||
# Fix permissions on copied files
|
||||
echo "Fixing file permissions..."
|
||||
find "$OUTPUT_DIR" -name "*.apk" -exec chmod 644 {} \; 2>/dev/null || true
|
||||
|
||||
echo "Build completed successfully!"
|
||||
echo "Packages are in $OUTPUT_DIR:"
|
||||
find "$OUTPUT_DIR" -name "*.apk" -exec ls -la {} \;
|
||||
else
|
||||
echo "❌ Failed to copy packages"
|
||||
echo "Checking what's in the container..."
|
||||
docker exec "$CONTAINER_NAME" find /home/builder -name "*.apk" -exec ls -la {} \; 2>/dev/null || true
|
||||
docker exec "$CONTAINER_NAME" ls -la /home/builder/packages/ 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user