Skip to content

Latest commit

 

History

History
138 lines (100 loc) · 4.63 KB

wpgit.md

File metadata and controls

138 lines (100 loc) · 4.63 KB

CLI::Wordpress Git Details

Commands

Three rawp commands are provided to help manage the Wordpress files in /var/www/html with github

  • rawp git get the git service connection string sudo docker exec -it --workdir /var/www/html git "/bin/bash"
  • rawp git-setup installs the git cli and git credentials manager
  • rawp git-chown adjusts file permissions to www-data:www-data in the wordpress service

Operation

This typical sequence of git operations can be performed from the command line of your Wordpress host server:

  • rawp ps <= check that the git service is Up
  • rawp git <= use the result to connect to the git service, then for example...
    • export GPG_TTY=$(tty) <= tell the gpg key which tty we are using
    • echo 'test' > test
    • git add test
    • git status
    • git pull
    • git commit -m 'note'
    • git push
  • exit <= when done return to the main Wordpress server prompt
  • rawp git-chown <= fix up Wordpress file permissions (IMPORTANT)

You may need to provide your gpg key passphrase for commands that write to github and to complete manual credential entry (first time) like this...

Select an authentication method for 'https://github.com/':
  1. Device code (default)
  2. Personal access token
option (enter for default): 2
---
Enter GitHub personal access token for 'https://github.com/'...
Token: 

Setup

When you rawp launch a Wordpress installation, it uses the docker-compose.yaml file which contains a git service (see below). Before the first use of rawp git, the following additional steps are needed at the Wordpress host server prompt:

  • rawp git-setup
  • gpg --gen-key <= start manual GNU GPG keygen procedure
  • pass init your_name

Handy Examples

Pull (modified) Wordpress files from a GitHub repo

The default rawp Wordpress installation is based on the wordpress:php8.0-fpm-alpine Docker image which is available as a base github repo here

You are welcome to fork this base repo (via github web), or to overwrite one of your own via these steps at the git server prompt:

First, rawp git <= connect to the git service, then...

export GPG_TTY=$(tty)
rm -rf * && rm .htaccess
git init .
git remote add -t \* -f origin https://github.com/librasteve/wordpress-6.2-php8.0-fpm-alpine.git
git checkout main

Finally, rawp git-chown when you exit.

Push (modified) Wordpress files to a (new) GitHub repo

First, make an empty repo via GitHub web

Then, rawp git <= connect to the git service, and...

export GPG_TTY=$(tty)
git init .
git branch -m main
git config --global --add safe.directory /var/www/html
git add --all
git commit -m "clone from image"
git remote add origin https://github.com/librasteve/wordpress-6.2-php8.0-fpm-alpine.git
git push -u origin main

This is the sequence used to build the base repo from the Docker image install set

Underlying Mechanisms

This section is for informational purposes only... this is the bit that CLI::Wordpress automates for you.

Configuration Details

The git service is a vanilla ubuntu VM which has access to the shared volume containing the Wordpress files:

#`/wordpress/docker-compose.yaml EXTRACT
# ...
git:
  depends_on:
  - wordpress
  image: ubuntu:latest
  container_name: git
  restart: unless-stopped
  command: tail -f /dev/null
  volumes:
  - wordpress:/var/www/html
  networks:
  - app-network
# ...

Setup Details

After the Wordpress installation is launched and running, rawp git-setup will load dependency apt-get modules, install git command line and github credential manager and configure the git service:

apt-get update && apt-get upgrade -y
apt-get install vim git curl wget libicu-dev gnupg pass -y
wget https://github.com/git-ecosystem/git-credential-manager/releases/download/v2.0.935/gcm-linux_amd64.2.0.935.tar.gz
tar -xvf gcm-linux_amd64.2.0.935.tar.gz -C /usr/local/bin
git-credential-manager configure
git config --global credential.credentialStore gpg
git config --global init.defaultBranch main
git config --global --add safe.directory /var/www/html
echo 'GPG_TTY=$(tty)' >> ~/.bashrc

Permissions Details

The rawp git-chown command applies these operation on the wordpress docker service

chown -R www-data:www-data *
chown -R www-data:www-data .htaccess