diff --git a/.forgejo/workflows/build-zerotier-alpine.yml b/.forgejo/workflows/build-zerotier-alpine.yml new file mode 100644 index 0000000..c4ef3f5 --- /dev/null +++ b/.forgejo/workflows/build-zerotier-alpine.yml @@ -0,0 +1,286 @@ +name: Build ZeroTier One for Alpine Linux + +on: + # Run on workflow dispatch (manual trigger) + workflow_dispatch: + inputs: + zerotier_version: + description: 'ZeroTier version to build (leave empty for latest)' + required: false + default: '' + type: string + + # Run every Friday at 8 AM UTC + schedule: + - cron: '0 8 * * 5' + # Run when this workflow file is modified + push: + paths: + - '.forgejo/workflows/build-zerotier-alpine.yml' + +jobs: + build-zerotier: + runs-on: [ "docker", "amd64" ] + container: + image: alpine:latest + + steps: + - name: Checkout workflow repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Setup Alpine environment and install dependencies + run: | + # Update package manager + apk update + + # Install build dependencies + apk add \ + git \ + make \ + gcc \ + g++ \ + linux-headers \ + openssl-dev \ + curl \ + tar \ + gzip \ + file \ + pkgconfig \ + musl-dev + + # Install Rust and Cargo + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + source "$HOME/.cargo/env" + + # Add Rust to PATH for subsequent steps + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + # Enable TUN module (if available in container) + modprobe tun || echo "TUN module not available in container (expected)" + + - name: Clone ZeroTier One repository + run: | + # Determine version to build + if [ -n "${{ github.event.inputs.zerotier_version }}" ]; then + VERSION="${{ github.event.inputs.zerotier_version }}" + echo "Building specified version: $VERSION" + git clone --depth 1 --branch "$VERSION" https://github.com/zerotier/ZeroTierOne.git zerotier-src + else + echo "Building latest version" + git clone --depth 1 https://github.com/zerotier/ZeroTierOne.git zerotier-src + fi + + cd zerotier-src + + # Get the actual version/commit info + ZEROTIER_VERSION=$(git describe --tags --always) + echo "ZEROTIER_VERSION=$ZEROTIER_VERSION" >> $GITHUB_ENV + echo "Building ZeroTier version: $ZEROTIER_VERSION" + + - name: Build ZeroTier One + run: | + cd zerotier-src + + # Source Rust environment + source "$HOME/.cargo/env" + + # Build ZeroTier + echo "Starting build process..." + make clean || true + make -j$(nproc) + + # Verify build succeeded + if [ -f "zerotier-one" ]; then + echo "Build successful!" + ./zerotier-one -v + else + echo "Build failed - zerotier-one binary not found" + exit 1 + fi + + - name: Create package structure + run: | + cd zerotier-src + + # Create package directory structure + PKG_DIR="../zerotier-one-alpine" + mkdir -p "$PKG_DIR/usr/sbin" + mkdir -p "$PKG_DIR/usr/bin" + mkdir -p "$PKG_DIR/etc/init.d" + mkdir -p "$PKG_DIR/var/lib/zerotier-one" + mkdir -p "$PKG_DIR/usr/share/doc/zerotier-one" + + # Copy binaries + cp zerotier-one "$PKG_DIR/usr/sbin/" + ln -sf ../sbin/zerotier-one "$PKG_DIR/usr/bin/zerotier-cli" + + # Create OpenRC init script + cat > "$PKG_DIR/etc/init.d/zerotier-one" << 'EOF' + #!/sbin/openrc-run + + depend() { + after network-online + want cgroups + } + + supervisor=supervise-daemon + name=zerotier-one + command="/usr/sbin/zerotier-one" + command_args=" >>/var/log/zerotier-one.log 2>&1" + + output_log=/var/log/zerotier-one.log + error_log=/var/log/zerotier-one.log + + pidfile="/var/run/zerotier-one.pid" + respawn_delay=5 + respawn_max=0 + EOF + + # Make init script executable + chmod +x "$PKG_DIR/etc/init.d/zerotier-one" + + # Copy documentation + cp README.md "$PKG_DIR/usr/share/doc/zerotier-one/" || true + cp LICENSE.txt "$PKG_DIR/usr/share/doc/zerotier-one/" || true + + # Create package info + cat > "$PKG_DIR/PACKAGE_INFO" << EOF + Package: zerotier-one-alpine + Version: $ZEROTIER_VERSION + Architecture: $(uname -m) + Built-Date: $(date -u +"%Y-%m-%dT%H:%M:%SZ") + Built-On: Alpine Linux $(cat /etc/alpine-release) + Description: ZeroTier One - Software Defined Networking + Homepage: https://zerotier.com + Source: https://github.com/zerotier/ZeroTierOne + EOF + + echo "Package structure created in $PKG_DIR" + + - name: Create package archive + run: | + ARCH=$(uname -m) + PACKAGE_NAME="zerotier-one-${ZEROTIER_VERSION}-alpine-${ARCH}" + + # Create tarball + tar -czf "${PACKAGE_NAME}.tar.gz" -C . zerotier-one-alpine + + # Create checksum + sha256sum "${PACKAGE_NAME}.tar.gz" > "${PACKAGE_NAME}.tar.gz.sha256" + + # Store package info for upload + echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV + echo "PACKAGE_FILE=${PACKAGE_NAME}.tar.gz" >> $GITHUB_ENV + + # Show package contents + echo "Package contents:" + tar -tzf "${PACKAGE_NAME}.tar.gz" | head -20 + + # Show file sizes + ls -lh "${PACKAGE_NAME}.tar.gz"* + + - name: Upload package to Forgejo + env: + FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} + FORGEJO_URL: ${{ vars.FORGEJO_URL || 'https://forgejo.example.com' }} + run: | + if [ -z "$FORGEJO_TOKEN" ]; then + echo "ERROR: FORGEJO_TOKEN secret not set!" + echo "Please set the FORGEJO_TOKEN secret with your Forgejo API token." + exit 1 + fi + + REPO_OWNER="${{ github.repository_owner }}" + REPO_NAME="${{ github.event.repository.name }}" + + echo "Uploading package to Forgejo packages..." + echo "Repository: $REPO_OWNER/$REPO_NAME" + echo "Package: $PACKAGE_FILE" + + # Upload the package file + curl -X PUT \ + -H "Authorization: token $FORGEJO_TOKEN" \ + -H "Content-Type: application/gzip" \ + --data-binary "@$PACKAGE_FILE" \ + "$FORGEJO_URL/api/packages/$REPO_OWNER/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE" + + # Upload the checksum file + curl -X PUT \ + -H "Authorization: token $FORGEJO_TOKEN" \ + -H "Content-Type: text/plain" \ + --data-binary "@$PACKAGE_FILE.sha256" \ + "$FORGEJO_URL/api/packages/$REPO_OWNER/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE.sha256" + + echo "Package upload completed!" + echo "Package URL: $FORGEJO_URL/api/packages/$REPO_OWNER/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE" + + - name: Create release notes + run: | + cat > release-notes.md << EOF + # ZeroTier One Alpine Linux Build + + **Version:** \`$ZEROTIER_VERSION\` + **Architecture:** \`$(uname -m)\` + **Built on:** \`$(date -u +"%Y-%m-%d %H:%M:%S UTC")\` + **Alpine Version:** \`$(cat /etc/alpine-release)\` + + ## Installation Instructions + + 1. Download the package: + \`\`\`bash + wget "$FORGEJO_URL/api/packages/${{ github.repository_owner }}/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE" + \`\`\` + + 2. Verify checksum (optional): + \`\`\`bash + wget "$FORGEJO_URL/api/packages/${{ github.repository_owner }}/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE.sha256" + sha256sum -c "$PACKAGE_FILE.sha256" + \`\`\` + + 3. Extract and install: + \`\`\`bash + tar -xzf "$PACKAGE_FILE" + sudo cp -r zerotier-one-alpine/* / + sudo chmod +x /etc/init.d/zerotier-one + sudo rc-update add zerotier-one default + sudo rc-service zerotier-one start + \`\`\` + + 4. Check status: + \`\`\`bash + sudo rc-service zerotier-one status + zerotier-cli status + \`\`\` + + ## Package Contents + + - \`/usr/sbin/zerotier-one\` - Main ZeroTier daemon + - \`/usr/bin/zerotier-cli\` - Command line interface (symlink) + - \`/etc/init.d/zerotier-one\` - OpenRC init script + - \`/usr/share/doc/zerotier-one/\` - Documentation + + Built from source: https://github.com/zerotier/ZeroTierOne + EOF + + echo "Release notes created:" + cat release-notes.md + + - name: Summary + run: | + echo "## 📦 ZeroTier One Alpine Build Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY + echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY + echo "| **Version** | \`$ZEROTIER_VERSION\` |" >> $GITHUB_STEP_SUMMARY + echo "| **Architecture** | \`$(uname -m)\` |" >> $GITHUB_STEP_SUMMARY + echo "| **Package Name** | \`$PACKAGE_FILE\` |" >> $GITHUB_STEP_SUMMARY + echo "| **Alpine Version** | \`$(cat /etc/alpine-release)\` |" >> $GITHUB_STEP_SUMMARY + echo "| **Build Date** | \`$(date -u +"%Y-%m-%d %H:%M:%S UTC")\` |" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### 📥 Download Package" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY + echo "wget \"$FORGEJO_URL/api/packages/${{ github.repository_owner }}/generic/zerotier-one-alpine/$ZEROTIER_VERSION/$PACKAGE_FILE\"" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY