diff --git a/.forgejo/README.md b/.forgejo/README.md index 34153a0..69f7dd8 100644 --- a/.forgejo/README.md +++ b/.forgejo/README.md @@ -19,20 +19,49 @@ This directory contains Forgejo Actions workflows for the Baktainer project. For ### 1. `ci.yml` - Main CI Pipeline - **Triggers**: Push to main, tags, and pull requests - **Jobs**: Test → Build → Notify +- **Container**: Ruby 3.3 Alpine with Node.js - **Features**: - - Runs RSpec tests in Ruby 3.3 Alpine container + - Runs RSpec tests with full GitHub Actions support - Builds and pushes Docker images to Docker Hub - Provides status notifications ### 2. `test.yml` - Test-Only Workflow - **Triggers**: Push to main and pull requests - **Jobs**: Test +- **Container**: Ruby 3.3 Alpine with Node.js - **Features**: - Runs unit and integration tests separately - Generates coverage reports - Uploads test artifacts -### 3. `build.yml` - Build-Only Workflow +### 3. `node-ruby.yml` - Node.js + Ruby Workflow +- **Triggers**: Push to main, tags, and pull requests +- **Jobs**: Test → Build → Notify +- **Container**: Node.js 18 Alpine with Ruby +- **Features**: + - Uses Node.js base image with Ruby installed + - Full GitHub Actions compatibility + - Optimized for actions requiring Node.js + +### 4. `simple.yml` - Simple Shell-Based Workflow +- **Triggers**: Push to main, tags, and pull requests +- **Jobs**: Test → Build → Notify +- **Container**: Ruby 3.3 Alpine +- **Features**: + - Uses basic shell commands instead of complex actions + - Manual git cloning and Docker operations + - Minimal dependencies + +### 5. `minimal.yml` - Minimal Test-Only Workflow +- **Triggers**: Push events +- **Jobs**: Test → Build +- **Container**: Ruby 3.3 Alpine +- **Features**: + - Extremely minimal setup + - Basic test execution + - No external action dependencies + +### 6. `build.yml` - Build-Only Workflow - **Triggers**: Push to main and tags - **Jobs**: Build → Notify - **Features**: @@ -40,7 +69,7 @@ This directory contains Forgejo Actions workflows for the Baktainer project. For - Supports versioned tags - Provides build status notifications -### 4. `docker.yml` - Advanced Docker Workflow +### 7. `docker.yml` - Advanced Docker Workflow - **Triggers**: Push to main and tags - **Jobs**: Test → Build - **Features**: @@ -139,21 +168,36 @@ git push origin feature-branch ### Common Issues -1. **Actions not running** +1. **Node.js executable not found error** + ``` + OCI runtime exec failed: exec failed: unable to start container process: + exec: "node": executable file not found in $PATH: unknown + ``` + **Solutions**: + - Use `node-ruby.yml` (Node.js base image with Ruby) + - Use `simple.yml` or `minimal.yml` (shell-based, no Node.js actions) + - Add Node.js to Ruby Alpine: `apk add --no-cache nodejs npm` + +2. **Actions not running** - Check if Repository Actions are enabled - Verify Forgejo Runner is installed and running - Check workflow file syntax -2. **Docker build failures** +3. **Docker build failures** - Verify Docker Hub credentials in secrets - Check Dockerfile syntax - Ensure runner has Docker access -3. **Test failures** +4. **Test failures** - Check Ruby version compatibility - Verify system dependencies in Alpine - Review test output in workflow logs +5. **GitHub Actions compatibility** + - Some actions require Node.js runtime + - Use `node-ruby.yml` for full GitHub Actions support + - Use `simple.yml` for shell-based alternatives + ### Debugging Steps 1. **Check workflow syntax**: diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index a3d0cd8..d23e2b3 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - name: Install system dependencies run: | - apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata + apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata nodejs npm - name: Install bundler run: gem install bundler -v 2.6.7 diff --git a/.forgejo/workflows/minimal.yml b/.forgejo/workflows/minimal.yml new file mode 100644 index 0000000..db6714b --- /dev/null +++ b/.forgejo/workflows/minimal.yml @@ -0,0 +1,59 @@ +name: Minimal CI + +on: [push] + +jobs: + test: + runs-on: docker + container: + image: ruby:3.3-alpine + + steps: + - name: Setup environment + run: | + apk add --no-cache git build-base libffi-dev linux-headers postgresql-dev + + - name: Clone repository + run: | + git clone ${{ github.server_url }}/${{ github.repository }}.git /workspace + cd /workspace + git checkout ${{ github.sha }} + + - name: Install dependencies + run: | + cd /workspace/app + gem install bundler -v 2.6.7 + bundle config path vendor/bundle + bundle install + + - name: Run tests + run: | + cd /workspace/app + bundle exec rspec + + - name: Success + run: echo "✅ Tests completed successfully" + + build: + needs: test + runs-on: docker + if: github.ref == 'refs/heads/main' + + steps: + - name: Setup environment + run: | + apk add --no-cache git docker + + - name: Clone repository + run: | + git clone ${{ github.server_url }}/${{ github.repository }}.git /workspace + cd /workspace + git checkout ${{ github.sha }} + + - name: Build image + run: | + cd /workspace + docker build -t test-image . + + - name: Success + run: echo "✅ Build completed successfully" \ No newline at end of file diff --git a/.forgejo/workflows/node-ruby.yml b/.forgejo/workflows/node-ruby.yml new file mode 100644 index 0000000..dca25cd --- /dev/null +++ b/.forgejo/workflows/node-ruby.yml @@ -0,0 +1,121 @@ +name: Node+Ruby CI Pipeline + +on: + push: + branches: + - main + tags: + - 'v*.*.*' + pull_request: + branches: + - main + +jobs: + test: + runs-on: docker + container: + image: node:18-alpine + defaults: + run: + working-directory: ./app + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata ruby ruby-dev ruby-bundler + + - name: Install bundler + run: gem install bundler -v 2.6.7 + + - name: Cache Ruby gems + uses: actions/cache@v4 + with: + path: app/vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('app/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + + - name: Install Ruby dependencies + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + + - name: Run RSpec tests + run: | + mkdir -p tmp + bundle exec rspec \ + --format progress \ + --format RspecJunitFormatter \ + --out tmp/rspec_results.xml + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: rspec-results + path: app/tmp/rspec_results.xml + + build: + needs: test + runs-on: docker + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - 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: [test, build] + runs-on: docker + if: always() + + steps: + - name: Notify pipeline status + run: | + echo "📊 Pipeline Status Report:" + echo "🧪 Tests: ${{ needs.test.result }}" + if [ "${{ needs.build.result }}" != "skipped" ]; then + echo "🐳 Build: ${{ needs.build.result }}" + fi + + if [ "${{ needs.test.result }}" == "success" ]; then + echo "✅ All tests passed!" + else + echo "❌ Tests failed" + fi \ No newline at end of file diff --git a/.forgejo/workflows/simple.yml b/.forgejo/workflows/simple.yml new file mode 100644 index 0000000..2e2d4b5 --- /dev/null +++ b/.forgejo/workflows/simple.yml @@ -0,0 +1,119 @@ +name: Simple CI Pipeline + +on: + push: + branches: + - main + tags: + - 'v*.*.*' + pull_request: + branches: + - main + +jobs: + test: + runs-on: docker + container: + image: ruby:3.3-alpine + defaults: + run: + working-directory: ./app + + steps: + - name: Checkout repository + run: | + apk add --no-cache git + git clone ${{ github.server_url }}/${{ github.repository }}.git . + git checkout ${{ github.sha }} + + - name: Install system dependencies + run: | + apk add --no-cache build-base libffi-dev linux-headers postgresql-dev curl tzdata + + - name: Install bundler + run: gem install bundler -v 2.6.7 + + - name: Install Ruby dependencies + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + + - name: Run RSpec tests + run: | + mkdir -p tmp + bundle exec rspec --format progress + + - name: Test status + run: | + if [ $? -eq 0 ]; then + echo "✅ All tests passed!" + else + echo "❌ Tests failed" + exit 1 + fi + + build: + needs: test + runs-on: docker + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) + + steps: + - name: Checkout repository + run: | + apk add --no-cache git + git clone ${{ github.server_url }}/${{ github.repository }}.git . + git checkout ${{ github.sha }} + + - name: Install Docker + run: | + apk add --no-cache docker + + - name: Build Docker image + run: | + docker build -t baktainer-test . + + - name: Test Docker image + run: | + docker run --rm baktainer-test ruby --version + + - name: Login to Docker Hub + run: | + echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + - name: Tag and push image + run: | + IMAGE_NAME="${{ secrets.DOCKER_IMAGE_NAME }}" + + # Tag as latest + docker tag baktainer-test "${IMAGE_NAME}:latest" + docker push "${IMAGE_NAME}:latest" + + # Tag with version if it's a tag + if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then + VERSION_TAG="${GITHUB_REF#refs/tags/}" + docker tag baktainer-test "${IMAGE_NAME}:${VERSION_TAG}" + docker push "${IMAGE_NAME}:${VERSION_TAG}" + echo "✅ Pushed ${IMAGE_NAME}:${VERSION_TAG}" + fi + + echo "✅ Docker image pushed successfully" + + notify: + needs: [test, build] + runs-on: docker + if: always() + + steps: + - name: Notify pipeline status + run: | + echo "📊 Pipeline Status Report:" + echo "🧪 Tests: ${{ needs.test.result }}" + if [ "${{ needs.build.result }}" != "skipped" ]; then + echo "🐳 Build: ${{ needs.build.result }}" + fi + + if [ "${{ needs.test.result }}" == "success" ]; then + echo "✅ All tests passed!" + else + echo "❌ Tests failed" + fi \ No newline at end of file diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml index d8a3f06..5e8f15e 100644 --- a/.forgejo/workflows/test.yml +++ b/.forgejo/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Install system dependencies run: | - apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata + apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata nodejs npm - name: Install bundler run: gem install bundler -v 2.6.7