Skip to content

Bare Repository Strategy

This guide details the process of deploying a Raydium-based WordPress site using GitHub and GitHub Actions with a bare repository strategy. Although GitHub and GitHub Actions are used in this example, similar steps can be applied to other platforms like GitLab CI, Jenkins, or Bitbucket Pipelines.

Prerequisites

  • A GitHub account.
  • A remote server with SSH access.
  • Git installed on both your local machine and the remote server.
  • Basic knowledge of Git, SSH, and Raydium's WPFramework.

Step-by-Step Guide

1. Set Up Your Local Raydium Project

  1. Initialize a Raydium Project:

    bash
    composer create-project devuri/raydium my-project
    cd my-project
  2. Initialize a Git Repository:

    bash
    git init
    git add .
    git commit -m "Initial commit"
  3. Create a Repository on GitHub:

    • Go to GitHub and create a new repository.
    • Follow the instructions to add the remote repository to your local Git setup:
      bash
      git remote add origin https://github.com/yourusername/your-repo.git
      git branch -M main
      git push -u origin main

2. Set Up the Bare Repository on the Remote Server

  1. Connect to Your Remote Server:

    bash
    ssh user@yourserver.com
  2. Create a Bare Repository:

    bash
    mkdir -p /path/to/bare-repo
    cd /path/to/bare-repo
    git init --bare

3. Create a Post-Receive Hook

The post-receive hook will automate the deployment by copying files from the bare repository to your web directory.

  1. Navigate to the Hooks Directory:

    bash
    cd /path/to/bare-repo/repo.git/hooks
  2. Create the Post-Receive Hook:

    bash
    touch post-receive
    nano post-receive
  3. Add the Following Script to the Hook:

    bash
    #!/bin/bash
    # Set variables
    TARGET="/path/to/your/web/directory"
    GIT_DIR="/path/to/bare-repo/repo.git"
    WORK_DIR="/path/to/tmp/work/directory"
    
    # Create the work directory if it doesn't exist
    mkdir -p $WORK_DIR
    
    # Checkout the latest code into the work directory
    git --work-tree=$WORK_DIR --git-dir=$GIT_DIR checkout -f
    
    # Copy the files to the target directory
    rsync -av --delete $WORK_DIR/ $TARGET/
    
    # Set permissions (optional, adjust as needed)
    chown -R www-data:www-data $TARGET
  4. Make the Hook Executable:

    bash
    chmod +x post-receive

4. Set Up GitHub Actions

  1. Create a GitHub Actions Workflow: In your repository, create a directory for GitHub Actions workflows:

    bash
    mkdir -p .github/workflows
  2. Create a Deployment Workflow File:

    bash
    nano .github/workflows/deploy.yml
  3. Add the Following Workflow Configuration:

    yaml
    name: Deploy to Server
    
    on:
      push:
        branches:
          - main
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
    
        - name: Set up SSH
          uses: webfactory/ssh-agent@v0.5.3
          with:
            ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
    
        - name: Deploy to Server
          run: |
            ssh user@yourserver.com 'cd /path/to/bare-repo/repo.git && git pull origin main'
  4. Add Your SSH Key to GitHub Secrets:

    • Set up SSH keys for your deployment.
    • Go to your GitHub repository settings.
    • Navigate to "Secrets and variables" > "Actions".
    • Add a new secret named SSH_PRIVATE_KEY and paste your private SSH key.

5. Push Your Code and Deploy

  1. Push Your Code to GitHub:

    bash
    git add .
    git commit -m "Set up deployment"
    git push origin main

    The GitHub Actions workflow will run, connecting to your remote server and triggering the post-receive hook to copy the files to your web directory.

6. Verify the Deployment

  1. Check the Target Directory: Ensure that the files have been copied correctly to the target directory on the remote server.

  2. Visit Your Website: Open your web browser and navigate to your website to confirm that it is working as expected.

Additional Tips

  • Automate with Other CI/CD Tools: If you're using GitLab CI, Jenkins, or Bitbucket Pipelines, adapt the workflow to the specific platform. The general steps remain the same: configure SSH access, set up a deployment script, and trigger the deployment on code push.
  • Environment Configuration: Use Raydium’s environment configuration features to manage different environments (development, staging, production).
  • Security: Ensure your SSH keys are secure and your server permissions are correctly set to prevent unauthorized access.
  • Raydium-Specific Configuration: Utilize Raydium’s WPFramework for additional configuration and optimization to leverage its full potential.

This will setup a robust deployment process tailored to Raydium using GitHub and GitHub Actions. This method leverages Git’s powerful version control system and Raydium’s capabilities, ensuring your WordPress site is always up-to-date and consistent across environments.