Skip to content

Commit

Permalink
feat: wordpress instance management
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithEmad committed Dec 10, 2024
1 parent 50a87a7 commit f60218d
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# https://github.com/actions/setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9
cache: "pip"
- name: Upgrade pip and setuptools
# https://pypi.org/project/pip/
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.12']
python-version: ['3.7', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -20,6 +20,15 @@ jobs:
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
if [ "${{ matrix.python-version }}" = "3.7" ]; then
pip install "tutor==15.0.0" pylint black mypy types-setuptools
else
pip install -U tutor
fi
echo "Installing tutor-contrib-wordpress"
pip install .[dev]
echo "Enable wordpress plugin and save configuration"
tutor plugins enable wordpress
tutor config save
- name: Test lint, types, and format
run: make test
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

<a id='changelog-1.1.0'></a>
## v1.1.0 (2024-11-27)

- [Feature] Added comprehensive WordPress integration for Open edX including:
- Full WordPress installation and configuration management
- Integration with Open edX Commerce WordPress Plugin and WooCommerce
- Configurable WordPress settings including version, host, ports, and database options
(by @CodeWithEmad)

<a id='changelog-1.0.1'></a>
## v1.0.1 (2024-07-27)

Expand Down
97 changes: 64 additions & 33 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,23 @@ WordPress Plugin for `Tutor`_
:target: https://www.gnu.org/licenses/agpl-3.0.en.html

Overview
--------
********

This is a `Tutor`_ plugin for integrating the `Open edX Commerce WordPress Plugin`_ with your Open edX instance.
The plugin allows seamless synchronization and interaction between your WordPress site and Open edX platform,
providing a cohesive e-commerce experience. If you don't know how to install the WordPress plugin, check out
this `installation guide`_.
This is a `Tutor`_ plugin that provides complete WordPress integration with your Open edX instance. It includes:

Before you start
----------------
- Full WordPress installation and management
- Integration with the `Open edX Commerce WordPress Plugin`_

This plugin does **not** create or manage a WordPress instance at the moment. It is designed to assist with the
configuration and integration of the Open edX platform with an existing WordPress site. If you need this feature,
feel free to open an issue or better yet, a PR.
If you need help installing the WordPress plugin, check out this `installation guide`_.

Prerequisites
-------------
*************

- A running WordPress site with the `Open edX Commerce WordPress Plugin`_ installed.
- Installation of Tutor version >= 15.0.0.
- Installation of Tutor version >= 15.0.0
- MySQL database (can use the same one as Open edX)

Installation
------------
************

Ensure you are using Tutor v15+ (Olive onwards). First, install the plugin by running:

Expand All @@ -51,59 +46,95 @@ Alternatively, if you already have a running Open edX instance, just run the nec
.. code-block:: bash
tutor dev|local|k8s do init --limit=wordpress
tutor dev|local|k8s start wordpress
Configuration
-------------
*************

Inside your WordPress admin panel, you will need to configure the following values:
The plugin automatically installs WordPress with the Open edX Commerce and Woocommerce plugins. Inside your WordPress
admin panel, go to Settings -> Open edX Sync plugin, and configure:

- **Open edX Domain**
- **Client ID**
- **Client Secret**

To verify the connection, click on "Generate JWT Token". If the process is successful, a new token will be generated.

.. image:: https://raw.githubusercontent.com/codewithemad/tutor-contrib-wordpress/master/images/openedx-sync-plugin-settings.png
:alt: Open edX Sync Plugin Settings in your WordPress Settings


You can retrieve these configuration values by running:

.. code-block:: bash
tutor wordpress config
tutor dev|local|k8s do wordpress config
This command will output the current configurations, including the Client ID, Client Secret, Open edX Domain,
and WordPress Domain. Here is an example of the output:

.. code-block:: text
===============================================
WordPress Plugin Configurations
WordPress Plugin Configurations
===============================================
Open edX Domain: http://local.edly.io
Client ID: qjCayDktffXrU09N17NrslKyWQ2EwzWn
Client ID (dev): JDx6Uy0hN67VUfacxKcLyYQz7HK9liVx
Client Secret: P4w82huaZQdyz4qolknsIHYneGEoIggc
Client ID: vvpTamiepPwjZhr0uOQGr5PhYBzp2hQw
Client ID (dev): MlbXk1V3wB7nWPAAyLF3McyfBBMqExa4
Client Secret: MdrgbtU8Q94He3gejF6Zf5MDookoeozO
Open edX Domain: http://local.edly.io:8000
Wordpress Domain: http://site.local.edly.io:8080
Or by using Tutor to print them individually:
Variables
*********

.. code-block:: bash
The plugin supports the following configuration variables:

- ``WORDPRESS_VERSION``: Plugin version
- ``WORDPRESS_HOST``: WordPress site hostname
- ``WORDPRESS_PORT``: WordPress port (default: 8080)
- ``WORDPRESS_DOCKER_IMAGE``: Docker image for WordPress
- ``WORDPRESS_OPENEDX_PLUGIN``: URL to the Open edX Commerce plugin
- ``WORDPRESS_WOOCOMMERCE_PLUGIN``: (default: "https://downloads.wordpress.org/plugin/woocommerce.9.4.2.zip")
The WooCommerce plugin zip file URL. You can specify a different version if needed.
- ``WORDPRESS_OFFICIAL_IMAGE``: (default: "wordpress:6.7.1-php8.1")
The official WordPress Docker image used as the base for building the plugin's custom image.
This image includes PHP and Apache server. You can specify a different version or PHP variant
if needed.

Database Settings
=================

- ``WORDPRESS_MYSQL_HOST``: MySQL host
- ``WORDPRESS_MYSQL_PORT``: MySQL port
- ``WORDPRESS_MYSQL_DATABASE``: Database name (default: wordpress)
- ``WORDPRESS_MYSQL_USERNAME``: Database username
- ``WORDPRESS_MYSQL_PASSWORD``: Database password (auto-generated)
- ``WORDPRESS_TABLE_PREFIX``: Table prefix (default: wp_)

tutor config printvalue LMS_HOST
tutor config printvalue WORDPRESS_OAUTH2_SECRET
tutor config printvalue WORDPRESS_OAUTH2_KEY_SSO
tutor config printvalue WORDPRESS_OAUTH2_KEY_SSO_DEV
Storage Settings
================

- ``WORDPRESS_DATA_VOLUME_SIZE``: Size of WordPress persistent volume (default: 5Gi)

OAuth2 Settings
===============

- ``WORDPRESS_OAUTH2_SECRET``: OAuth2 secret key (auto-generated)
- ``WORDPRESS_OAUTH2_KEY_SSO``: OAuth2 client ID (auto-generated)
- ``WORDPRESS_OAUTH2_KEY_SSO_DEV``: OAuth2 development client ID (auto-generated)

Contributing
------------
************

We welcome all contributions! Feel free to open a Pull Request.
We welcome all contributions! Feel free to open a Pull Request or an Issue.

License
-------
*******

This software is licensed under the terms of the `AGPLv3`_.

.. _Tutor: https://docs.tutor.edly.io
.. _installation guide: https://docs.openedx.org/projects/wordpress-ecommerce-plugin/en/latest/plugin_quickstart.html
.. _Open edX Commerce WordPress Plugin: https://github.com/openedx/openedx-wordpress-ecommerce
.. _AGPLv3: https://github.com/codewithemad/tutor-contrib-wordpress/blob/master/LICENSE.txt
.. _installation guide: https://docs.openedx.org/projects/wordpress-ecommerce-plugin/en/latest/plugin_quickstart.html
Binary file modified images/openedx-sync-plugin-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ def load_about():
license="AGPLv3",
author="Emad Rad",
author_email="codewithemad@gmail.com",
description="Tutor plugin for WooCommerce",
description="Tutor plugin for WordPress.",
long_description=load_readme(),
long_description_content_type="text/x-rst",
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.8",
install_requires=["tutor>=14.0.0,<19.0.0"],
python_requires=">=3.7",
install_requires=[
"tutor>=15.0.0,<19.0.0",
"importlib_resources", # for older versions of tutor
],
extras_require={
"dev": [
"tutor[dev]>=14.0.0,<19.0.0",
]
},
entry_points={
"tutor.plugin.v1": [
"wordpress = tutorwordpress.plugin"
"tutor[dev]>=15.0.0,<19.0.0",
]
},
entry_points={"tutor.plugin.v1": ["wordpress = tutorwordpress.plugin"]},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
5 changes: 5 additions & 0 deletions tutorwordpress/patches/caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WordPress
{{ WORDPRESS_HOST }}{$default_site_port} {

import proxy "wordpress:{{ WORDPRESS_PORT }}"
}
51 changes: 51 additions & 0 deletions tutorwordpress/patches/k8s-deployments
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
labels:
app.kubernetes.io/name: wordpress
spec:
selector:
matchLabels:
app.kubernetes.io/name: wordpress
template:
metadata:
labels:
app.kubernetes.io/name: wordpress
spec:
initContainers:
- name: init-wordpress
image: {{ WORDPRESS_DOCKER_IMAGE }}
command: ['sh', '-c', 'chown -R www-data:www-data /var/www/html/wp-content']
volumeMounts:
- name: wordpress-data
mountPath: /var/www/html/wp-content
securityContext:
runAsUser: 0
containers:
- name: wordpress
image: {{ WORDPRESS_DOCKER_IMAGE }}
ports:
- containerPort: 8080
env:
- name: WORDPRESS_DB_HOST
value: {{ WORDPRESS_MYSQL_HOST }}
- name: WORDPRESS_DB_USER
value: {{ WORDPRESS_MYSQL_USERNAME }}
- name: WORDPRESS_DB_PASSWORD
value: {{ WORDPRESS_MYSQL_PASSWORD }}
- name: WORDPRESS_DB_NAME
value: {{ WORDPRESS_MYSQL_DATABASE }}
- name: WORDPRESS_TABLE_PREFIX
value: {{ WORDPRESS_TABLE_PREFIX }}
volumeMounts:
- name: wordpress-data
mountPath: /var/www/html/wp-content
securityContext:
runAsUser: 33
runAsGroup: 33
volumes:
- name: wordpress-data
persistentVolumeClaim:
claimName: wordpress-data
21 changes: 21 additions & 0 deletions tutorwordpress/patches/k8s-jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: wordpress-job
labels:
app.kubernetes.io/component: job
spec:
template:
spec:
restartPolicy: Never
containers:
- name: wordpress
image: {{ WORDPRESS_DOCKER_IMAGE }}
volumeMounts:
- name: wordpress-data
mountPath: /var/www/html/wp-content
volumes:
- name: wordpress-data
persistentVolumeClaim:
claimName: wordpress-data
13 changes: 13 additions & 0 deletions tutorwordpress/patches/k8s-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: ClusterIP
ports:
- port: {{ WORDPRESS_PORT }}
targetPort: 8080
protocol: TCP
selector:
app.kubernetes.io/name: wordpress
14 changes: 14 additions & 0 deletions tutorwordpress/patches/k8s-volumes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-data
labels:
app.kubernetes.io/component: volume
app.kubernetes.io/name: wordpress-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ WORDPRESS_DATA_VOLUME_SIZE }}
1 change: 1 addition & 0 deletions tutorwordpress/patches/local-docker-compose-caddy-aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- "{{ WORDPRESS_HOST }}"
11 changes: 11 additions & 0 deletions tutorwordpress/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
wordpress:
stdin_open: true
tty: true
ports:
- {{ WORDPRESS_PORT }}:8080
environment:
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
7 changes: 7 additions & 0 deletions tutorwordpress/patches/local-docker-compose-jobs-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
wordpress-job:
image: {{ WORDPRESS_DOCKER_IMAGE }}
volumes:
- ../../data/wordpress:/var/www/html/wp-content
depends_on:
- lms
{% if RUN_MYSQL %}- mysql{% endif %}
16 changes: 16 additions & 0 deletions tutorwordpress/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
wordpress:
image: {{ WORDPRESS_DOCKER_IMAGE }}
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: {{ WORDPRESS_MYSQL_HOST }}
WORDPRESS_DB_USER: {{ WORDPRESS_MYSQL_USERNAME }}
WORDPRESS_DB_PASSWORD: {{ WORDPRESS_MYSQL_PASSWORD }}
WORDPRESS_DB_NAME: {{ WORDPRESS_MYSQL_DATABASE }}
WORDPRESS_TABLE_PREFIX: {{ WORDPRESS_TABLE_PREFIX }}
volumes:
- ../../data/wordpress/wp-content:/var/www/html/wp-content
{%- if RUN_MYSQL %}
depends_on:
- mysql
{% endif -%}

Loading

0 comments on commit f60218d

Please sign in to comment.