voirs 0.1.0-alpha.2

Advanced voice synthesis and speech processing library for Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# VoiRS Examples CI/CD Docker Image
# ==================================
#
# Multi-stage Docker image for building and testing VoiRS examples in CI/CD pipelines.
# Provides a consistent environment across different platforms and CI systems.
#
# Usage:
#   docker build -f Dockerfile.ci -t voirs-ci .
#   docker run -v $(pwd):/workspace voirs-ci
#
# Build arguments:
#   RUST_VERSION - Rust version to use (default: 1.75)
#   TARGET_ARCH - Target architecture (default: x86_64-unknown-linux-gnu)
#   BUILD_PROFILE - Build profile (default: release)

# Build stage - Install dependencies and build tools
FROM rust:1.75-slim as builder

# Build arguments
ARG RUST_VERSION=1.75
ARG TARGET_ARCH=x86_64-unknown-linux-gnu
ARG BUILD_PROFILE=release

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV RUST_BACKTRACE=1
ENV CARGO_TERM_COLOR=always
ENV RUSTFLAGS="-D warnings"

# Install system dependencies
RUN apt-get update && apt-get install -y \
    # Build essentials
    build-essential \
    pkg-config \
    cmake \
    git \
    curl \
    # Audio libraries
    libasound2-dev \
    libpulse-dev \
    libportaudio2 \
    libportaudio-dev \
    # FFmpeg for audio processing
    ffmpeg \
    libavcodec-dev \
    libavformat-dev \
    libavutil-dev \
    # System monitoring tools
    htop \
    iotop \
    nethogs \
    # Python for build scripts
    python3 \
    python3-pip \
    python3-venv \
    # Utilities
    jq \
    wget \
    unzip \
    && rm -rf /var/lib/apt/lists/*

# Install Rust components
RUN rustup component add rustfmt clippy
RUN rustup target add $TARGET_ARCH

# Install cargo tools
RUN cargo install \
    cargo-audit \
    cargo-watch \
    cargo-cache \
    cargo-tarpaulin

# Install Python dependencies for build system
RUN pip3 install --no-cache-dir \
    toml \
    psutil \
    matplotlib \
    numpy \
    pandas

# Create workspace directory
WORKDIR /workspace

# Production stage - Runtime environment
FROM ubuntu:22.04 as runtime

# Runtime dependencies
RUN apt-get update && apt-get install -y \
    # Runtime libraries
    libasound2 \
    libpulse0 \
    libportaudio2 \
    # FFmpeg runtime
    ffmpeg \
    # System tools
    curl \
    git \
    jq \
    python3 \
    python3-pip \
    # Monitoring tools
    htop \
    && rm -rf /var/lib/apt/lists/*

# Copy Rust toolchain from builder
COPY --from=builder /usr/local/cargo /usr/local/cargo
COPY --from=builder /usr/local/rustup /usr/local/rustup

# Set up environment
ENV PATH="/usr/local/cargo/bin:$PATH"
ENV RUST_BACKTRACE=1
ENV CARGO_TERM_COLOR=always

# Create workspace and user
RUN groupadd -r voirs && useradd -r -g voirs -m voirs
WORKDIR /workspace
RUN chown -R voirs:voirs /workspace

# Switch to non-root user
USER voirs

# CI/CD stage - Full development environment
FROM builder as ci

# Set up CI-specific environment
ENV CI=true
ENV CARGO_INCREMENTAL=0
ENV CARGO_PROFILE_RELEASE_DEBUG=1

# Install additional tools for CI
RUN cargo install \
    cargo-deny \
    cargo-machete \
    cargo-udeps

# Install Python CI tools
RUN pip3 install --no-cache-dir \
    pytest \
    coverage \
    black \
    flake8 \
    mypy

# Create CI user and workspace
RUN groupadd -r ci && useradd -r -g ci -m ci
RUN mkdir -p /ci-workspace /ci-reports /ci-artifacts
RUN chown -R ci:ci /ci-workspace /ci-reports /ci-artifacts

# Copy CI scripts
COPY tools/ /ci-tools/
RUN chmod +x /ci-tools/*.sh /ci-tools/*.py

# Switch to CI user
USER ci
WORKDIR /ci-workspace

# Entry point script
COPY <<'EOF' /entrypoint.sh
#!/bin/bash
set -euo pipefail

# Configuration
WORKSPACE_DIR="${WORKSPACE_DIR:-/ci-workspace}"
REPORTS_DIR="${REPORTS_DIR:-/ci-reports}"
ARTIFACTS_DIR="${ARTIFACTS_DIR:-/ci-artifacts}"
BUILD_PROFILE="${BUILD_PROFILE:-ci}"
PARALLEL_JOBS="${PARALLEL_JOBS:-$(nproc)}"
TEST_TIMEOUT="${TEST_TIMEOUT:-300}"

# Create directories
mkdir -p "$REPORTS_DIR" "$ARTIFACTS_DIR"

# Change to workspace
cd "$WORKSPACE_DIR"

# Validate environment
echo "๐Ÿ” Validating CI environment..."
echo "  Workspace: $WORKSPACE_DIR"
echo "  Reports: $REPORTS_DIR"
echo "  Artifacts: $ARTIFACTS_DIR"
echo "  Profile: $BUILD_PROFILE"
echo "  Parallel Jobs: $PARALLEL_JOBS"
echo "  Rust Version: $(rustc --version)"
echo "  Cargo Version: $(cargo --version)"

# Check if we have VoiRS examples
if [[ ! -f "examples/Cargo.toml" ]]; then
    echo "โŒ VoiRS examples not found. Please mount the repository to $WORKSPACE_DIR"
    exit 1
fi

# Run CI pipeline based on arguments
case "${1:-full}" in
    "build")
        echo "๐Ÿ”จ Running build-only pipeline..."
        cd examples
        /ci-tools/enhanced_build_system.py \
            --build-only \
            --parallel "$PARALLEL_JOBS" \
            --report "$REPORTS_DIR/build_report.json"
        ;;
    
    "test")
        echo "๐Ÿงช Running test-only pipeline..."
        cd examples
        /ci-tools/enhanced_build_system.py \
            --test-only \
            --parallel "$PARALLEL_JOBS" \
            --timeout "$TEST_TIMEOUT" \
            --report "$REPORTS_DIR/test_report.json"
        ;;
    
    "quality")
        echo "๐Ÿ“Š Running quality checks..."
        cd examples
        cargo fmt --all -- --check
        cargo clippy --all-targets --all-features -- -D warnings
        cargo audit
        ;;
    
    "benchmark")
        echo "๐Ÿƒ Running performance benchmarks..."
        cd examples
        /ci-tools/enhanced_build_system.py \
            --parallel "$PARALLEL_JOBS" \
            --timeout 600 \
            --examples "*benchmark*,*performance*" \
            --report "$REPORTS_DIR/benchmark_report.json"
        ;;
    
    "full"|*)
        echo "๐Ÿš€ Running full CI/CD pipeline..."
        
        # Quality checks
        echo "๐Ÿ“Š Step 1/4: Quality checks..."
        cd examples
        cargo fmt --all -- --check
        cargo clippy --all-targets --all-features -- -D warnings
        cargo audit
        
        # Build
        echo "๐Ÿ”จ Step 2/4: Building examples..."
        /ci-tools/enhanced_build_system.py \
            --build-only \
            --parallel "$PARALLEL_JOBS" \
            --report "$REPORTS_DIR/build_report.json"
        
        # Test
        echo "๐Ÿงช Step 3/4: Testing examples..."
        /ci-tools/enhanced_build_system.py \
            --test-only \
            --parallel "$PARALLEL_JOBS" \
            --timeout "$TEST_TIMEOUT" \
            --report "$REPORTS_DIR/test_report.json"
        
        # Generate final report
        echo "๐Ÿ“‹ Step 4/4: Generating final report..."
        python3 << 'PYTHON_EOF'
import json
import os
from datetime import datetime

reports_dir = os.environ['REPORTS_DIR']
artifacts_dir = os.environ['ARTIFACTS_DIR']

# Collect all reports
final_report = {
    'timestamp': datetime.utcnow().isoformat(),
    'pipeline': 'full',
    'environment': {
        'rust_version': os.popen('rustc --version').read().strip(),
        'platform': os.popen('uname -a').read().strip(),
        'parallel_jobs': os.environ['PARALLEL_JOBS']
    },
    'reports': {}
}

# Load individual reports
for report_file in ['build_report.json', 'test_report.json', 'benchmark_report.json']:
    report_path = os.path.join(reports_dir, report_file)
    if os.path.exists(report_path):
        try:
            with open(report_path, 'r') as f:
                final_report['reports'][report_file] = json.load(f)
        except Exception as e:
            print(f"Warning: Could not load {report_file}: {e}")

# Save final report
final_report_path = os.path.join(reports_dir, 'final_report.json')
with open(final_report_path, 'w') as f:
    json.dump(final_report, f, indent=2)

print(f"โœ… Final report saved to: {final_report_path}")

# Generate summary
build_report = final_report['reports'].get('build_report.json', {})
test_report = final_report['reports'].get('test_report.json', {})

build_results = build_report.get('build_results', {})
test_results = test_report.get('test_results', {})

print("\n" + "="*50)
print("CI/CD Pipeline Summary")
print("="*50)
print(f"Build: {build_results.get('successful', 0)}/{build_results.get('total', 0)} successful")
print(f"Test: {test_results.get('successful', 0)}/{test_results.get('total', 0)} successful")

# Check if pipeline succeeded
build_success = build_results.get('successful', 0) == build_results.get('total', 0)
test_success = test_results.get('successful', 0) == test_results.get('total', 0)

if build_success and test_success:
    print("โœ… Pipeline completed successfully!")
    exit(0)
else:
    print("โŒ Pipeline failed!")
    exit(1)
PYTHON_EOF
        ;;
esac

echo "๐ŸŽ‰ CI/CD pipeline completed!"
EOF

RUN chmod +x /entrypoint.sh

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD cargo --version && rustc --version || exit 1

# Default entry point
ENTRYPOINT ["/entrypoint.sh"]
CMD ["full"]

# Testing stage - Lightweight image for quick tests
FROM runtime as test

# Install minimal testing dependencies
RUN pip3 install --no-cache-dir pytest

# Copy only essential tools
COPY tools/enhanced_build_system.py /test-tools/
RUN chmod +x /test-tools/*.py

USER voirs
WORKDIR /workspace

# Quick test entry point
COPY <<'EOF' /test-entrypoint.sh
#!/bin/bash
set -euo pipefail

cd /workspace/examples
python3 /test-tools/enhanced_build_system.py \
    --parallel $(nproc) \
    --timeout 60 \
    --examples "${TEST_EXAMPLES:-*}" \
    --report "/tmp/test_report.json" \
    "$@"
EOF

RUN chmod +x /test-entrypoint.sh

ENTRYPOINT ["/test-entrypoint.sh"]

# Benchmark stage - Optimized for performance testing
FROM ci as benchmark

# Install performance monitoring tools
RUN apt-get update && apt-get install -y \
    perf-tools-unstable \
    sysstat \
    && rm -rf /var/lib/apt/lists/*

# Performance-optimized configuration
ENV CARGO_PROFILE_RELEASE_LTO=true
ENV CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
ENV RUSTFLAGS="-C target-cpu=native -C opt-level=3"

# Benchmark entry point
COPY <<'EOF' /benchmark-entrypoint.sh
#!/bin/bash
set -euo pipefail

cd /ci-workspace/examples

echo "๐Ÿƒ Starting performance benchmarks..."
echo "CPU Info: $(nproc) cores, $(grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2)"
echo "Memory: $(free -h | grep 'Mem:' | awk '{print $2}')"

# Run system monitoring in background
iostat -x 1 > /ci-reports/iostat.log 2>&1 &
IOSTAT_PID=$!

# Run benchmarks
/ci-tools/enhanced_build_system.py \
    --parallel $(nproc) \
    --timeout 1800 \
    --examples "*benchmark*,*performance*" \
    --report "/ci-reports/benchmark_report.json" \
    --verbose

# Stop monitoring
kill $IOSTAT_PID 2>/dev/null || true

echo "โœ… Benchmarks completed!"
EOF

RUN chmod +x /benchmark-entrypoint.sh

ENTRYPOINT ["/benchmark-entrypoint.sh"]

# Labels for metadata
LABEL maintainer="VoiRS Team"
LABEL description="VoiRS Examples CI/CD Environment"
LABEL version="1.0"
LABEL rust.version="1.75"