baktainer/.forgejo/workflows/build.yml

80 lines
2.4 KiB
YAML
Raw Normal View History

Add Forgejo Actions workflows for CI/CD ## Forgejo Actions Setup ### Directory Structure - `.forgejo/workflows/` - Forgejo Actions workflows directory - `ci.yml` - Main CI pipeline (test + build + notify) - `test.yml` - Test-only workflow for development - `build.yml` - Build-only workflow for releases - `docker.yml` - Advanced Docker workflow with caching - `README.md` - Comprehensive documentation ### Key Features #### 1. Main CI Pipeline (ci.yml) - Runs RSpec tests in Ruby 3.3 Alpine container - Builds and pushes Docker images to Docker Hub - Supports version tagging and latest tags - Provides pipeline status notifications #### 2. Test Workflow (test.yml) - Dedicated testing workflow for PRs - Runs unit and integration tests separately - Generates coverage reports - Uploads test artifacts #### 3. Build Workflow (build.yml) - Standalone Docker build workflow - Triggers on main branch and version tags - Includes build status notifications #### 4. Advanced Docker Workflow (docker.yml) - Uses Docker Buildx for advanced builds - Implements Docker layer caching - Automatic metadata extraction and tagging ### Forgejo vs GitHub Actions Differences #### Technical Adaptations - **Directory**: `.forgejo/workflows/` vs `.github/workflows/` - **Runners**: `runs-on: docker` with container specification - **Dependencies**: Explicit Alpine package installation - **Caching**: Adapted for Forgejo environment - **Execution**: Optimized for Docker container runtime #### Compatibility - Uses same action references (`actions/checkout@v4`, etc.) - Same secret management (`${{ secrets.* }}`) - Same environment variables (`${{ github.* }}`) - Maintains workflow syntax compatibility ### Required Configuration - Enable Repository Actions in Forgejo settings - Configure Docker Hub secrets (DOCKER_USERNAME, DOCKER_PASSWORD, DOCKER_IMAGE_NAME) - Ensure Forgejo Runner is installed and configured - Set up action repository sources ### Benefits - **Dual CI/CD**: Can run alongside GitHub Actions - **Self-hosted**: Full control over CI/CD infrastructure - **Docker-native**: Optimized for containerized workflows - **Feature parity**: Maintains same functionality as GitHub Actions This enables Baktainer to run on Forgejo instances with full CI/CD capabilities while maintaining compatibility with existing GitHub Actions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 11:02:58 -04:00
name: Build Docker Image
on:
push:
branches:
- main
tags:
- 'v*.*.*'
jobs:
build:
runs-on: docker
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
steps:
- name: Install Node.js for actions
run: |
# Detect package manager and install Node.js
if command -v apk >/dev/null 2>&1; then
apk add --no-cache nodejs npm
elif command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y nodejs npm
elif command -v yum >/dev/null 2>&1; then
yum install -y nodejs npm
elif command -v dnf >/dev/null 2>&1; then
dnf install -y nodejs npm
else
echo "Package manager not found. Installing Node.js manually..."
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs || echo "Failed to install Node.js"
fi
Add Forgejo Actions workflows for CI/CD ## Forgejo Actions Setup ### Directory Structure - `.forgejo/workflows/` - Forgejo Actions workflows directory - `ci.yml` - Main CI pipeline (test + build + notify) - `test.yml` - Test-only workflow for development - `build.yml` - Build-only workflow for releases - `docker.yml` - Advanced Docker workflow with caching - `README.md` - Comprehensive documentation ### Key Features #### 1. Main CI Pipeline (ci.yml) - Runs RSpec tests in Ruby 3.3 Alpine container - Builds and pushes Docker images to Docker Hub - Supports version tagging and latest tags - Provides pipeline status notifications #### 2. Test Workflow (test.yml) - Dedicated testing workflow for PRs - Runs unit and integration tests separately - Generates coverage reports - Uploads test artifacts #### 3. Build Workflow (build.yml) - Standalone Docker build workflow - Triggers on main branch and version tags - Includes build status notifications #### 4. Advanced Docker Workflow (docker.yml) - Uses Docker Buildx for advanced builds - Implements Docker layer caching - Automatic metadata extraction and tagging ### Forgejo vs GitHub Actions Differences #### Technical Adaptations - **Directory**: `.forgejo/workflows/` vs `.github/workflows/` - **Runners**: `runs-on: docker` with container specification - **Dependencies**: Explicit Alpine package installation - **Caching**: Adapted for Forgejo environment - **Execution**: Optimized for Docker container runtime #### Compatibility - Uses same action references (`actions/checkout@v4`, etc.) - Same secret management (`${{ secrets.* }}`) - Same environment variables (`${{ github.* }}`) - Maintains workflow syntax compatibility ### Required Configuration - Enable Repository Actions in Forgejo settings - Configure Docker Hub secrets (DOCKER_USERNAME, DOCKER_PASSWORD, DOCKER_IMAGE_NAME) - Ensure Forgejo Runner is installed and configured - Set up action repository sources ### Benefits - **Dual CI/CD**: Can run alongside GitHub Actions - **Self-hosted**: Full control over CI/CD infrastructure - **Docker-native**: Optimized for containerized workflows - **Feature parity**: Maintains same functionality as GitHub Actions This enables Baktainer to run on Forgejo instances with full CI/CD capabilities while maintaining compatibility with existing GitHub Actions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 11:02:58 -04:00
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract version tag
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Set image tags
id: tags
run: |
IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }}
TAGS="${IMAGE_NAME}:latest"
if [ -n "${{ steps.version.outputs.VERSION_TAG }}" ]; then
TAGS="$TAGS,${IMAGE_NAME}:${{ steps.version.outputs.VERSION_TAG }}"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
notify:
needs: build
runs-on: docker
if: always()
steps:
- name: Notify build status
run: |
if [ "${{ needs.build.result }}" == "success" ]; then
echo "✅ Docker image built and pushed successfully"
echo "🏷️ Tags: ${{ needs.build.outputs.tags }}"
else
echo "❌ Docker image build failed"
exit 1
fi