Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
🌅
Browse files Browse the repository at this point in the history
  • Loading branch information
regisb committed Jul 11, 2019
0 parents commit c893745
Show file tree
Hide file tree
Showing 27 changed files with 1,262 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.*.swp
!.gitignore
TODO
__pycache__
*.egg-info/
/build/
/dist/
10 changes: 10 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pypi:
script:
- apk add --no-cache make
- pip3 install -U setuptools twine
- python3 setup.py sdist
- twine upload --skip-existing dist/tutor-ecommerce*.tar.gz
only:
- tags
tags:
- private
661 changes: 661 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include tutorecommerce/patches *
87 changes: 87 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Ecommerce plugin for `Tutor <https://docs.tutor.overhang.io>`_
===============================================================

This is a plugin for `Tutor <https://docs.tutor.overhang.io>`_ that integrates the `Ecommerce <https://github.com/edx/ecommerce/>`__ application in an Open edX platform.

.. image:: https://overhang.io/images/clients/e-ducation.jpg
:alt: E-ducation
:target: https://www.e-ducation.cn/

This plugin was developed and open sourced to the community thanks to the generous support of `E-ducation <https://www.e-ducation.cn/>`_. Thank you!

Installation
------------

This plugin requires tutor>=3.6.0 and the Discovery plugin `tutor-discovery <https://github.com/overhangio/tutor-discovery>`__. Also, you should have installed tutor from source, and not from a pre-compiled binary.

::

pip install tutor-ecommerce

Then, to enable this plugin, run::

tutor plugins enable ecommerce

Services will have to be re-configured and restarted, so you are probably better off just running quickstart again::

tutor local quickstart

Note that this plugins is compatible with `Kubernetes integration <http://docs.tutor.overhang.io/k8s.html>`__, so if deploying to a Kubernetes cluster, run instead::

tutor k8s quickstart

Operations
----------

Creating a user
~~~~~~~~~~~~~~~

The ecommerce user interface will be available at http://ecommerce.localhost for a local instance, and at ``ECOMMERCE_HOST`` (by default: ``http(s)://ecommerce.<your lms host>) in production. In order to run commands from the UI, a user with admin rights must be created::

tutor local run ecommerce ./manage.py createsuperuser

Local development
~~~~~~~~~~~~~~~~~

For developing locally, it is necessary to configure the ecommerce service to be served from localhost::

tutor config save --set ECOMMERCE_HOST=ecommerce.localhost

Configuration
~~~~~~~~~~~~~

- ``ECOMMERCE_HOST`` (default: ``"ecommerce.{{ LMS_HOST }}"``)
- ``ECOMMERCE_PAYMENT_PROCESSORS`` (default: ``{cybersource: {}, paypal: {}}``)
- ``ECOMMERCE_ENABLED_PAYMENT_PROCESSORS``: (default: ``["cybersource", "paypal"]``)
- ``ECOMMERCE_ENABLED_CLIENT_SIDE_PAYMENT_PROCESSORS`` (default: ``["cybersource"]``)
- ``ECOMMERCE_EXTRA_PAYMENT_PROCESSOR_CLASSES`` (default: ``[]``)
- ``ECOMMERCE_MYSQL_PASSWORD``: ``"{{ 8|random_string }}"``)
- ``ECOMMERCE_SECRET_KEY`` (default: ``"{{ 20|random_string }}"``)
- ``ECOMMERCE_OAUTH2_SECRET`` (default: ``"{{ 8|random_string }}"``)
- ``ECOMMERCE_API_KEY`` (default: ``"{{ 20|random_string }}"``)
- ``ECOMMERCE_DOCKER_IMAGE`` (default: ``"overhangio/openedx-ecommerce:{{ TUTOR_VERSION }}"``)
- ``ECOMMERCE_WORKER_DOCKER_IMAGE`` (default: ``"overhangio/openedx-ecommerce-worker:{{ TUTOR_VERSION }}"``)
- ``ECOMMERCE_MYSQL_DATABASE`` (default: ``"ecommerce"``)
- ``ECOMMERCE_MYSQL_USERNAME`` (default: ``"ecommerce"``)
- ``ECOMMERCE_MYSQL_USERNAME`` (default: ``"ecommerce"``)
- ``ECOMMERCE_OAUTH2_KEY`` (default: ``"ecommerce"``)
- ``ECOMMERCE_API_TIMEOUT`` (default: ``5``)
- ``ECOMMERCE_WORKER_JWT_ISSUER`` (default: ``"ecommerce_worker"``)
- ``ECOMMERCE_EXTRA_PIP_REQUIREMENTS`` (default: ``[]``)

Image customisation
~~~~~~~~~~~~~~~~~~~

Ecommerce implementations vary a lot from one country to another. If all you need are the Paypal, Cybersource and Stripe payment processors, then it should not be necessary to customize the tutor-ecommerce docker image, which contains the vanilla Ecommerce platform. However, if you need to run a fork of Ecommerce, or install extra requirements, then you should re-build the docker image. To do so, first set the appropriate settings::

tutor config save \
--set 'ENABLED_PAYMENT_PROCESSORS=["myprocessor"]' \
--set 'ENABLED_CLIENT_SIDE_PAYMENT_PROCESSORS=["myprocessor"]' \
--set 'ECOMMERCE_EXTRA_PAYMENT_PROCESSOR_CLASSES=["myextension.payment.MyProcessor"]' \
--set 'ECOMMERCE_EXTRA_PIP_REQUIREMENTS=["git+https://github.com/myusername/myplugin"]'

Then, build the image, pointing to your fork if necessary::

tutor images build ecommerce \
-a ECOMMERCE_REPOSITORY=https://github.com/myusername/ecommerce \
-a ECOMMERCE_VERSION=my/tag
41 changes: 41 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import io
import os
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))

with io.open(os.path.join(here, "README.rst"), "rt", encoding="utf8") as f:
readme = f.read()


setup(
name="tutor-ecommerce",
version="0.1.0",
url="https://docs.tutor.overhang.io/",
project_urls={
"Documentation": "https://docs.tutor.overhang.io/",
"Code": "https://github.com/overhangio/tutor-ecommerce",
"Issue tracker": "https://github.com/overhangio/tutor/issues",
"Community": "https://discuss.overhang.io",
},
license="AGPLv3",
author="Overhang.io",
author_email="[email protected]",
description="A Tutor plugin for Open edX Ecommerce",
long_description=readme,
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.5",
install_requires=["tutor-openedx", "tutor-discovery"],
entry_points={"tutor.plugin.v0": ["ecommerce = tutorecommerce.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.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
)
66 changes: 66 additions & 0 deletions tutorecommerce/patches/k8s-deployments
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce
labels:
app.kubernetes.io/name: ecommerce
spec:
selector:
matchLabels:
app.kubernetes.io/name: ecommerce
template:
metadata:
labels:
app.kubernetes.io/name: ecommerce
spec:
containers:
- name: ecommerce
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_DOCKER_IMAGE }}
ports:
- containerPort: 8000
env:
- name: DJANGO_SETTINGS_MODULE
value: ecommerce.settings.tutor
volumeMounts:
- mountPath: /openedx/ecommerce/ecommerce/settings/tutor.py
name: settings
subPath: tutor.py
volumes:
- name: settings
configMap:
name: ecommerce-settings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce_worker
labels:
app.kubernetes.io/name: ecommerce_worker
spec:
selector:
matchLabels:
app.kubernetes.io/name: ecommerce_worker
template:
metadata:
labels:
app.kubernetes.io/name: ecommerce_worker
spec:
containers:
- name: ecommerce_worker
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_WORKER_DOCKER_IMAGE }}
ports:
- containerPort: 8000
env:
- name: WORKER_CONFIGURATION_MODULE
value: ecommerce_worker.configuration.tutor_worker
- name: C_FORCE_ROOT
value: "1"
volumeMounts:
- mountPath: /openedx/ecommerce_worker/ecommerce_worker/configuration/tutor_worker.py:ro
name: settings
subPath: tutor_worker.py
volumes:
- name: settings
configMap:
name: ecommerce_worker-settings
6 changes: 6 additions & 0 deletions tutorecommerce/patches/k8s-deployments-nginx-init-containers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: init-ecommerce-staticfiles
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_DOCKER_IMAGE }}
args: ['cp', '-r', '/openedx/ecommerce/assets/', '/var/www/ecommerce/assets']
volumeMounts:
- mountPath: /var/www/ecommerce/
name: ecommerce-staticfiles
2 changes: 2 additions & 0 deletions tutorecommerce/patches/k8s-deployments-nginx-volumes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: ecommerce-staticfiles
emptyDir: {}
18 changes: 18 additions & 0 deletions tutorecommerce/patches/k8s-ingress-certificates
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
name: {{ ECOMMERCE_HOST|replace(".", "-") }}
spec:
secretName: {{ ECOMMERCE_HOST }}-tls
issuerRef:
name: letsencrypt
commonName: {{ ECOMMERCE_HOST }}
dnsNames:
- {{ ECOMMERCE_HOST }}
acme:
config:
- http01:
ingress: web
domains:
- {{ ECOMMERCE_HOST }}
6 changes: 6 additions & 0 deletions tutorecommerce/patches/k8s-ingress-rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- host: {{ ECOMMERCE_HOST }}
http:
paths:
- backend:
serviceName: nginx
servicePort: {% if ACTIVATE_HTTPS %}443{% else %}80{% endif %}
1 change: 1 addition & 0 deletions tutorecommerce/patches/k8s-ingress-tls-hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- {{ ECOMMERCE_HOST }}
12 changes: 12 additions & 0 deletions tutorecommerce/patches/k8s-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: Service
metadata:
name: ecommerce
spec:
type: NodePort
ports:
- port: 8000
protocol: TCP
selector:
app.kubernetes.io/name: ecommerce
6 changes: 6 additions & 0 deletions tutorecommerce/patches/kustomization-configmapgenerator
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: ecommerce-settings
files:
- plugins/ecommerce/apps/settings/tutor.py
- name: ecommerce_worker-settings
files:
- plugins/ecommerce/apps/settings/tutor_worker.py
1 change: 1 addition & 0 deletions tutorecommerce/patches/local-docker-compose-nginx-volumes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- ../../data/ecommerce:/var/www/ecommerce:ro
29 changes: 29 additions & 0 deletions tutorecommerce/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ecommerce:
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_DOCKER_IMAGE }}
environment:
DJANGO_SETTINGS_MODULE: ecommerce.settings.tutor
restart: unless-stopped
volumes:
- ../plugins/ecommerce/apps/tutor.py:/openedx/ecommerce/ecommerce/settings/tutor.py:ro
- ../../data/ecommerce/media:/openedx/ecommerce/course_ecommerce/media
depends_on:
{% if ACTIVATE_LMS %}- lms{% endif %} # TODO decomment this
{% if ACTIVATE_MYSQL %}- mysql{% endif %}
- discovery

ecommerce_worker:
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_WORKER_DOCKER_IMAGE }}
environment:
WORKER_CONFIGURATION_MODULE: ecommerce_worker.configuration.tutor_worker
C_FORCE_ROOT: "1"
restart: unless-stopped
volumes:
- ../plugins/ecommerce/apps/tutor_worker.py:/openedx/ecommerce_worker/ecommerce_worker/configuration/tutor_worker.py:ro
depends_on:
- ecommerce

ecommerce-assets:
image: {{ DOCKER_REGISTRY }}{{ ECOMMERCE_DOCKER_IMAGE }}
volumes:
- ../../data/ecommerce:/var/www/ecommerce
command: sh -c "rm -rf /var/www/ecommerce/assets && cp -r /openedx/ecommerce/assets/ /var/www/ecommerce/"
40 changes: 40 additions & 0 deletions tutorecommerce/patches/nginx-extra
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Ecommerce
upstream ecommerce-backend {
server ecommerce:8000 fail_timeout=0;
}
{% if ACTIVATE_HTTPS %}
server {
server_name {{ ECOMMERCE_HOST }};
listen 80;
return 301 https://$server_name$request_uri;
}
{% endif %}
server {
{% if ACTIVATE_HTTPS %}listen 443 {{ "" if WEB_PROXY else "ssl" }};{% else %}listen 80;{% endif %}
server_name ecommerce.localhost {{ ECOMMERCE_HOST }};

{% if ACTIVATE_HTTPS and not WEB_PROXY %}
ssl_certificate /etc/letsencrypt/live/{{ ECOMMERCE_HOST }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ ECOMMERCE_HOST }}/privkey.pem;
{% endif %}

# Disables server version feedback on pages and in headers
server_tokens off;

client_max_body_size 10m;

location / {
{% if not WEB_PROXY %}
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $remote_addr;
{% endif %}
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://ecommerce-backend;
}

location /static {
alias /var/www/ecommerce/assets;
}
}
5 changes: 5 additions & 0 deletions tutorecommerce/patches/openedx-lms-common-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ECOMMERCE_PUBLIC_URL_ROOT = "http://ecommerce:8000"
ECOMMERCE_API_URL = ECOMMERCE_PUBLIC_URL_ROOT + "/api/v2"
ECOMMERCE_API_TIMEOUT = {{ ECOMMERCE_API_TIMEOUT }}
EDX_API_KEY = "{{ ECOMMERCE_API_KEY }}"
ECOMMERCE_API_SIGNING_KEY = "{{ JWT_COMMON_SECRET_KEY }}"
Loading

0 comments on commit c893745

Please sign in to comment.