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
Initialize a Raydium Project:
bashcomposer create-project devuri/raydium my-project cd my-project
Initialize a Git Repository:
bashgit init git add . git commit -m "Initial commit"
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
Connect to Your Remote Server:
bashssh user@yourserver.com
Create a Bare Repository:
bashmkdir -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.
Navigate to the Hooks Directory:
bashcd /path/to/bare-repo/repo.git/hooks
Create the Post-Receive Hook:
bashtouch post-receive nano post-receive
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
Make the Hook Executable:
bashchmod +x post-receive
4. Set Up GitHub Actions
Create a GitHub Actions Workflow: In your repository, create a directory for GitHub Actions workflows:
bashmkdir -p .github/workflows
Create a Deployment Workflow File:
bashnano .github/workflows/deploy.yml
Add the Following Workflow Configuration:
yamlname: 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'
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
Push Your Code to GitHub:
bashgit 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
Check the Target Directory: Ensure that the files have been copied correctly to the target directory on the remote server.
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.