Skip to content

Commit

Permalink
Merge pull request #3494 from mathesar-foundation/0.1.6
Browse files Browse the repository at this point in the history
Release 0.1.6
  • Loading branch information
Anish9901 committed Mar 28, 2024
2 parents ee44eab + 5fcf35c commit b99e82c
Show file tree
Hide file tree
Showing 42 changed files with 1,346 additions and 204 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/create-draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build static files and create draft release

on:
push:
tags:
- "*"
workflow_dispatch:


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18

- name: Build frontend static files
working-directory: ./mathesar_ui
run: npm ci && npm run build

- name: Move static files
run: mv ./mathesar/static/mathesar ./static_files

- name: Zip static files
uses: montudor/action-zip@v1
with:
args: zip -qq -r static_files.zip static_files

- name: Create a draft release
id: create_release
uses: shogo82148/actions-create-release@v1
with:
draft: true

- name: Upload assets
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: static_files.zip
6 changes: 4 additions & 2 deletions .github/workflows/test-and-lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ jobs:
needs.all_be_tests_required.outputs.tests_should_run
strategy:
matrix:
pg-version: [13, 14, 15]
py-version: [3.9-bookworm, 3.10-bookworm, 3.11-bookworm, 3.12-bookworm]
pg-version: [13, 14, 15, 16]
steps:
- uses: actions/checkout@v4
- name: Copy env file
Expand All @@ -125,6 +126,7 @@ jobs:
- name: Build the stack
run: docker compose -f docker-compose.dev.yml up --build -d test-service
env:
PYTHON_VERSION: ${{ matrix.py-version }}
PG_VERSION: ${{ matrix.pg-version }}
- name: Run tests with pytest
run: docker exec mathesar_service_test ./run_pytest.sh
Expand All @@ -137,7 +139,7 @@ jobs:
needs.all_be_tests_required.outputs.tests_should_run
strategy:
matrix:
pg-version: [13, 14, 15]
pg-version: [13, 14, 15, 16]
steps:
- uses: actions/checkout@v4
- name: Copy env file
Expand Down
74 changes: 52 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
FROM python:3.9-buster
ARG PYTHON_REQUIREMENTS=requirements.txt
#=========== STAGE: BASE =====================================================#
ARG PYTHON_VERSION=3.9-bookworm
FROM python:$PYTHON_VERSION AS base

ENV PYTHONUNBUFFERED=1
ENV DOCKERIZE_VERSION v0.6.1
ENV NODE_MAJOR 18
ARG BUILD_PG_MAJOR=15
ENV PG_MAJOR=$BUILD_PG_MAJOR

RUN set -eux;

#---------- 1. INSTALL SYSTEM DEPENDENCIES -----------------------------------#

RUN mkdir -p /etc/apt/keyrings;

# Add Postgres source
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - ; \
echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list;

# Add Node.js source
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list;
echo "deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list;

# Install common dependencies
RUN apt-get update && \
Expand All @@ -28,7 +23,6 @@ RUN apt-get update && \
curl \
gnupg \
gettext \
nodejs \
locales \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -42,18 +36,12 @@ RUN apt-get update && \
postgresql-$PG_MAJOR postgresql-client-$PG_MAJOR postgresql-contrib-$PG_MAJOR \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


#---------- 2. CONFIGURE SYSTEM DEPENDENCIES ---------------------------------#

# Postgres

ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin
ENV PGDATA /var/lib/postgresql/mathesar

VOLUME /etc/postgresql/
VOLUME /var/lib/postgresql/


# We set the default STOPSIGNAL to SIGINT, which corresponds to what PostgreSQL
# calls "Fast Shutdown mode" wherein new connections are disallowed and any
# in-progress transactions are aborted, allowing PostgreSQL to stop cleanly and
Expand All @@ -64,17 +52,59 @@ STOPSIGNAL SIGINT

EXPOSE 5432

# Mathesar source
WORKDIR /code/
COPY . .

#---------- 3. SETUP MATHESAR ------------------------------------------------#

WORKDIR /code/
#=========== STAGE: DEVELOPMENT ==============================================#

COPY requirements* ./
RUN pip install --no-cache-dir -r ${PYTHON_REQUIREMENTS}
COPY . .
FROM base AS development

ENV NODE_MAJOR 18

# Install dev requirements
RUN pip install --no-cache-dir -r requirements-dev.txt

# Compile translation files
RUN python manage.py compilemessages

# Add NodeJS source
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list;

# Install node
RUN apt-get update && \
apt-get install -y --no-install-recommends \
nodejs \
&& rm -rf /var/lib/apt/lists/*

# Build frontend source
RUN cd mathesar_ui && npm ci && npm run build

EXPOSE 8000 3000 6006

ENTRYPOINT ["./dev-run.sh"]


#=========== STAGE: PRODUCTION ===============================================#

FROM base AS production

# Install prod requirements
RUN pip install --no-cache-dir -r requirements-prod.txt

# Compile translation files
RUN python manage.py compilemessages

# Copy built frontend static files
COPY --from=development /code/mathesar/static/mathesar ./mathesar/static/mathesar/

# Remove FE source, tests, docs
RUN rm -rf ./mathesar_ui
RUN rm -rf ./mathesar/tests ./db/tests
RUN rm -rf ./docs

EXPOSE 8000

ENTRYPOINT ["./run.sh"]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<img alt="License" src="https://img.shields.io/github/license/mathesar-foundation/mathesar">
<img alt="GitHub closed issues" src="https://img.shields.io/github/issues-closed/mathesar-foundation/mathesar">
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/w/mathesar-foundation/mathesar">
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/mathesar-foundation/mathesar">
</p>

<p align="center">
Expand Down
58 changes: 34 additions & 24 deletions config/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@
def frontend_settings(request):
manifest_data = get_manifest_data()
development_mode = settings.MATHESAR_MODE == 'DEVELOPMENT'
display_language = get_display_language_from_request(request)
fallback_language = settings.FALLBACK_LANGUAGE

i18n_settings = get_i18n_settings(manifest_data, development_mode)
frontend_settings = {
'development_mode': development_mode,
'manifest_data': manifest_data,
'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),
'live_demo_username': getattr(settings, 'MATHESAR_LIVE_DEMO_USERNAME', None),
'live_demo_password': getattr(settings, 'MATHESAR_LIVE_DEMO_PASSWORD', None),
**i18n_settings
'display_language': display_language,
'include_i18n_fallback': display_language != fallback_language,
}
# Only include development URL if we're in development mode.
if frontend_settings['development_mode'] is True:
frontend_settings['client_dev_url'] = settings.MATHESAR_CLIENT_DEV_URL
i18n_settings = get_i18n_settings_dev(display_language)
else:
i18n_settings = get_i18n_settings_prod(display_language, manifest_data)

frontend_settings = {**frontend_settings, **i18n_settings}

return frontend_settings

Expand All @@ -36,30 +43,33 @@ def get_display_language_from_request(request):
return lang_from_locale_middleware


def get_i18n_settings(manifest_data, development_mode):
"""
Hard coding this for now
but will be taken from users model
and cookies later on
"""
display_language = 'en'
fallback_language = 'en'

def get_i18n_settings_dev(display_language):
client_dev_url = settings.MATHESAR_CLIENT_DEV_URL
fallback_language = settings.FALLBACK_LANGUAGE

if development_mode is True:
module_translations_file_path = f'{client_dev_url}/src/i18n/languages/{display_language}/index.ts'
legacy_translations_file_path = f'{client_dev_url}/src/i18n/languages/{display_language}/index.ts'
else:
try:
module_translations_file_path = static(manifest_data[display_language]["file"])
legacy_translations_file_path = static(manifest_data[f"{display_language}-legacy"]["file"])
except KeyError:
module_translations_file_path = static(manifest_data[fallback_language]["file"])
legacy_translations_file_path = static(manifest_data[f"{fallback_language}-legacy"]["file"])
return {
'dev_display_language_url': f'{client_dev_url}/src/i18n/languages/{display_language}/index.ts',
'dev_fallback_language_url': f'{client_dev_url}/src/i18n/languages/{fallback_language}/index.ts',
}


def get_prod_translation_file_urls(language, manifest_data):
prod_module_url = static(manifest_data[f"language_{language}"]["file"])
prod_legacy_url = static(manifest_data[f"language_{language}_legacy"]["file"])

return {
'module': prod_module_url,
'legacy': prod_legacy_url,
}


def get_i18n_settings_prod(display_language, manifest_data):
fallback_language = settings.FALLBACK_LANGUAGE

display_language_urls = get_prod_translation_file_urls(display_language, manifest_data)
fallback_language_urls = get_prod_translation_file_urls(fallback_language, manifest_data)

return {
'module_translations_file_path': module_translations_file_path,
'legacy_translations_file_path': legacy_translations_file_path,
'display_language': display_language
'prod_display_language_urls': display_language_urls,
'prod_fallback_language_urls': fallback_language_urls,
}
7 changes: 4 additions & 3 deletions config/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from decouple import Csv, config as decouple_config
from dj_database_url import parse as db_url
from django.utils.translation import gettext_lazy


# We use a 'tuple' with pipes as delimiters as decople naively splits the global
Expand Down Expand Up @@ -272,11 +271,13 @@ def pipe_delim(pipe_string):

# i18n
LANGUAGES = [
('en', gettext_lazy('English')),
('ja', gettext_lazy('Japanese')),
('en', 'English'),
('ja', 'Japanese'),
]
LOCALE_PATHS = [
'translations'
]
LANGUAGE_COOKIE_NAME = 'display_language'
FALLBACK_LANGUAGE = 'en'

SALT_KEY = SECRET_KEY
8 changes: 8 additions & 0 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
# Override default settings
DEBUG = False
MATHESAR_MODE = 'PRODUCTION'

'''
This tells Django to trust the X-Forwarded-Proto header that comes from our proxy,
and any time its value is 'https', then the request is guaranteed to be secure
(i.e., it originally came in via HTTPS).
'''
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Use a local.py module for settings that shouldn't be version tracked
try:
from .local import * # noqa
Expand Down
3 changes: 2 additions & 1 deletion demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from decouple import config as decouple_config

INSTALLED_APPS += [ # noqa
"demo"
"demo",
"health_check",
]

MIDDLEWARE += [ # noqa
Expand Down
1 change: 1 addition & 0 deletions demo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def permission_denied(_, *args, **kwargs):
re_path(r'^api/ui/v0/users/(?P<pk>[^/.]+)/password_reset/', permission_denied, name='password_reset'),
path('api/ui/v0/users/password_change/', permission_denied, name='password_change'),
path('auth/password_reset_confirm/', RedirectView.as_view(url='/'), name='password_reset'),
path(r'health/', include('health_check.urls')),
path('', include(root_urls)),
]
7 changes: 4 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ services:
image: mathesar/mathesar-dev:latest
build:
context: .
target: development
dockerfile: Dockerfile
args:
PYTHON_REQUIREMENTS: requirements-dev.txt
PYTHON_VERSION: ${PYTHON_VERSION-3.9-bookworm}
environment:
- MODE=${MODE-DEVELOPMENT}
- DEBUG=${DEBUG-True}
Expand All @@ -52,7 +53,6 @@ services:
- POSTGRES_PASSWORD=mathesar
- POSTGRES_HOST=mathesar_dev_db
- POSTGRES_PORT=5432
entrypoint: ./dev-run.sh
volumes:
- .:/code/
- ui_node_modules:/code/mathesar_ui/node_modules/
Expand All @@ -76,9 +76,10 @@ services:
- POSTGRES_PORT=5432
build:
context: .
target: development
dockerfile: Dockerfile
args:
PYTHON_REQUIREMENTS: requirements-dev.txt
PYTHON_VERSION: ${PYTHON_VERSION-3.9-bookworm}
depends_on:
- dev-db
ports:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ services:

# WARNING: MATHESAR_DATABASES is deprecated, and will be removed in a future release.
MATHESAR_DATABASES: ${MATHESAR_DATABASES:-}
entrypoint: ./run.sh
volumes:
- ./msar/static:/code/static
- ./msar/media:/code/media
Expand Down
Loading

0 comments on commit b99e82c

Please sign in to comment.