Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .env.example

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
CELERY_BROKER_URL: redis://localhost:6379/4
CELERY_RESULT_BACKEND: redis://localhost:6379/4
TIKA_CLIENT_ONLY: "True"
MITOPEN_BASE_URL: http://localhost:8063/
MITOPEN_APP_BASE_URL: http://localhost:8062/
MAILGUN_KEY: fake_mailgun_key
MAILGUN_SENDER_DOMAIN: other.fake.site
OPENSEARCH_INDEX: testindex
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Webpack build
run: yarn run build
env:
MITOPEN_AXIOS_BASE_PATH: https://api.mitopen-test.odl.mit.edu
MITOPEN_API_BASE_URL: https://api.mitopen-test.odl.mit.edu

- name: Lints
run: yarn run lint-check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
POSTHOG_PROJECT_ID: ${{ secrets.POSTHOG_PROJECT_ID_PROD }}
POSTHOG_PROJECT_API_KEY: ${{ secrets.POSTHOG_PROJECT_API_KEY_PROD }}
MITOPEN_AXIOS_WITH_CREDENTIALS: true
MITOPEN_AXIOS_BASE_PATH: https://api.mitopen.odl.mit.edu
MITOPEN_API_BASE_URL: https://api.mitopen.odl.mit.edu
MITOPEN_SUPPORT_EMAIL: mitopen-support@mit.edu

- uses: akhileshns/heroku-deploy@581dd286c962b6972d427fcf8980f60755c15520
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
POSTHOG_PROJECT_ID: ${{ secrets.POSTHOG_PROJECT_ID_RC }}
POSTHOG_PROJECT_API_KEY: ${{ secrets.POSTHOG_PROJECT_API_KEY_RC }}
MITOPEN_AXIOS_WITH_CREDENTIALS: true
MITOPEN_AXIOS_BASE_PATH: https://api.mitopen-rc.odl.mit.edu
MITOPEN_API_BASE_URL: https://api.mitopen-rc.odl.mit.edu
MITOPEN_SUPPORT_EMAIL: odl-mitopen-rc-support@mit.edu

- uses: akhileshns/heroku-deploy@581dd286c962b6972d427fcf8980f60755c15520
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ __pycache__/

# Distribution / packaging
.Python
env/
build/
build-exports/
develop-eggs/
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ MIT Open follows the same [initial setup steps outlined in the common OL web app
Run through those steps **including the addition of `/etc/hosts` aliases and the optional step for running the
`createsuperuser` command**.

### Configure required `.env` settings
### Configuration

Configuration can be put in the following filess which are gitignored:

```
mit-open/
├── env/
│ ├── shared.local.env (provided to both frontend and backend containers)
│ ├── frontend.local.env (provided only to frontend containers)
│ └── backend.local.env (provided only to frontend containers)
└── .env (legacy file)
```

The following settings must be configured before running the app:

- `COMPOSE_PROFILES`

Controls which docker containers run. To run them all, use `COMPOSE_PROFILES=backend,frontend`. See [Frontend Development](./frontends/README.md) for more.

- `INDEXING_API_USERNAME`

At least to start out, this should be set to the username of the superuser
you created above.
This can be set either in a top-level `.env` that `docker compose` [automatically ingests](https://docs.docker.com/compose/environment-variables/envvars/#compose_env_files) or through any other method of setting an environment variable in your shell (e.g. `direnv`).

- `MAILGUN_KEY` and `MAILGUN_SENDER_DOMAIN`

Expand Down Expand Up @@ -216,7 +223,7 @@ Once these are set (and you've restarted the app), you should see events flowing
A Javascript bundle of exported frontend components can be generated for use in external websites that have CORS allowance into a given instance of `mit-open`. There are a few settings you might want to change in order to get the expected results.

- `MITOPEN_AXIOS_WITH_CREDENTIALS` - This sets `withCredentials: true` when initializing the Axios API, which tells the end user's browser to send along any browser level cookies for the current domain when making CORS requests
- `MITOPEN_AXIOS_BASE_PATH` - This sets the base path used for API requests, which will need to be set to a fully qualified url pointing to an instance of `mit-open` (i.e. https://mitopen.odl.mit.edu) in order for requests from the external site to reach the proper destination
- `MITOPEN_API_BASE_URL` - This sets the base url used for API requests, which will need to be set to a fully qualified url pointing to an instance of `mit-open` (i.e. https://mitopen.odl.mit.edu) in order for requests from the external site to reach the proper destination
- `CORS_ALLOWED_ORIGINS`, `CSRF_TRUSTED_ORIGINS` - On the instance of `mit-open` that the externally hosted components will access via the API, the domains of any sites that need CORS access need to be here as a list of strings

To build the bundle of exported components, run:
Expand Down
18 changes: 2 additions & 16 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
{
"url": "https://github.com/heroku/heroku-buildpack-apt"
},
{
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
},
{
"url": "https://github.com/moneymeets/python-poetry-buildpack"
},
Expand Down Expand Up @@ -172,9 +169,6 @@
"description": "Prefix path for cached images generated by imagekit",
"required": false
},
"INDEXING_API_USERNAME": {
"description": "Username used for indexing"
},
"INDEXING_ERROR_RETRIES": {
"description": "Number of times to retry an indexing operation on failure",
"required": false
Expand Down Expand Up @@ -298,20 +292,12 @@
"description": "List of pluggy plugins to use for authentication",
"required": false
},
"MITOPEN_AXIOS_WITH_CREDENTIALS": {
"description": "When building the Axios API, set defaults.withCredentials to this value",
"required": false
},
"MITOPEN_AXIOS_BASE_PATH": {
"description": "The base path to use when making API requests",
"required": false
},
"MITOPEN_LEARNING_RESOURCES_PLUGINS": {
"description": "List of pluggy plugins to use for learning resources",
"required": false
},
"MITOPEN_BASE_URL": {
"description": "Base url to link users to in emails"
"MITOPEN_APP_BASE_URL": {
"description": "Base url to create links to the app"
},
"MITOPEN_COOKIE_NAME": {
"description": "Name of the cookie for the JWT auth token"
Expand Down
6 changes: 2 additions & 4 deletions channels/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Models for channels"""

from urllib.parse import urljoin

from django.conf import settings
from django.contrib.auth.models import Group
from django.core.validators import RegexValidator
from django.db import models
Expand All @@ -18,6 +15,7 @@
LearningResourceTopic,
)
from main.models import TimestampedModel
from main.utils import frontend_absolute_url
from profiles.utils import avatar_uri, banner_uri
from widgets.models import WidgetList

Expand Down Expand Up @@ -99,7 +97,7 @@ class Meta:
@property
def channel_url(self) -> str:
"""Return the channel url"""
return urljoin(settings.SITE_BASE_URL, f"/c/{self.channel_type}/{self.name}/")
return frontend_absolute_url(f"/c/{self.channel_type}/{self.name}/")


class ChannelTopicDetail(TimestampedModel):
Expand Down
7 changes: 3 additions & 4 deletions channels/serializers_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Tests for channels.serializers"""

from types import SimpleNamespace
from urllib.parse import urljoin

import pytest
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile

from channels.constants import CHANNEL_ROLE_MODERATORS, ChannelType
Expand Down Expand Up @@ -37,6 +35,7 @@
)
from learning_resources.serializers import LearningResourceOfferorDetailSerializer
from main.factories import UserFactory
from main.utils import frontend_absolute_url

# pylint:disable=redefined-outer-name
pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -124,8 +123,8 @@ def test_serialize_channel( # pylint: disable=too-many-arguments
"updated_on": mocker.ANY,
"created_on": mocker.ANY,
"id": channel.id,
"channel_url": urljoin(
settings.SITE_BASE_URL, f"/c/{channel.channel_type}/{channel.name}/"
"channel_url": frontend_absolute_url(
f"/c/{channel.channel_type}/{channel.name}/"
),
"lists": [
LearningPathPreviewSerializer(channel_list.channel_list).data
Expand Down
42 changes: 0 additions & 42 deletions config/nginx.conf

This file was deleted.

38 changes: 2 additions & 36 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,15 @@ http {
default_type application/octet-stream;
sendfile on;

server {
server_name lemelsonx.mit.edu;
listen <%= ENV["PORT"] %>;
return 301 https://open.mit.edu/c/lemelsoneducators;
}

server {
server_name themove.mit.edu;
listen <%= ENV["PORT"] %>;
return 301 https://open.mit.edu/c/themove;
}

server {
server_name discussions.odl.mit.edu;
listen <%= ENV["PORT"] %>;
return 301 https://open.mit.edu$request_uri;
}

server {
listen <%= ENV["PORT"] %> default_server;
server_name _;
root /app;

location / {
expires max;
try_files /frontends/mit-open/build/static$uri /frontends/mit-open/build$uri @index;
}

location ~ ^/program_letter/([0-9]+)/view$ {
expires 1m;
try_files /frontends/mit-open/build/index.html =404;
}

location @index {
expires 1m;
try_files /frontends/mit-open/build/index.html =404;
}

location = /.well-known/dnt-policy.txt {
return 204;
}

location ~ ^/(api|login|complete/ol-oidc|logout|admin|static/admin|static/rest_framework|static/hijack|_/features/|hijack/|scim/|o/|disconnect/|podcasts/rss_feed|__debug__/|media/|profile/|program_letter/([0-9]+)/) {
location / {
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
Expand All @@ -98,7 +64,7 @@ http {
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
uwsgi_param X-Forwarded-Port $http_x_forwarded_port;
uwsgi_param X-Forwarded-Host $http_x_forwarded_host;
uwsgi_pass unix:/tmp/nginx.socket;
uwsgi_pass <%= ENV["NGINX_UWSGI_PASS"] || "unix:/tmp/nginx.socket" %>;
uwsgi_pass_request_headers on;
uwsgi_pass_request_body on;
client_max_body_size 25M;
Expand Down
10 changes: 10 additions & 0 deletions config/static-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is the version used ONLY for e2e tests because we statically compile to production mode
server {
listen 8063 $APP_BASE_URL;
root /src/frontends/mit-open/build;

location / {
try_files /index.html =404;
}

}
12 changes: 10 additions & 2 deletions docker-compose-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ services:
- web
volumes:
- ./config/nginx.conf:/etc/nginx/conf.d/web.conf
- ./config/static-app.conf:/etc/nginx/templates/static-app.template
- ./frontends/mit-open/build:/src/frontends/mit-open/build
env_file:
- path: ./env/shared.env
networks:
default:
aliases:
- "open.odl.local"
- "api.open.odl.local"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8063"]
interval: 30s
Expand All @@ -48,7 +56,7 @@ services:
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/e2e_postgres # pragma: allowlist secret
PORT: 8061
env_file: .env.ci
env_file: env/ci.env
depends_on:
db:
condition: service_healthy
Expand All @@ -72,7 +80,7 @@ services:
context: e2e_testing
environment:
- CI=true
- BASE_URL=http://nginx:8063
- BASE_URL=http://open.odl.local:8063
depends_on:
nginx:
condition: service_healthy
Expand Down
Loading