Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cookiecutter and demo-site command #2564

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Tiago-Salles
Copy link
Collaborator

@Tiago-Salles Tiago-Salles commented Jan 13, 2025

In quick words, this PR includes:

  • Add org_dockerhub, nginx_image_name, nginx_image_tag, and elasticsearch_image_name parameters to generate a site factory.
  • Select database engine to run a site.
  • Activate a site and select their supported languages.
  • Improve create_demo_site command script to support multilingual generation.

Purpose

We at NAU identified the necessity to have more flexibility in terms of architecture using Richie.

For our instance we have been maintaining some changes to meet our needs, that we understand valuable to have upstream. Our instance runs with MySQL and the docker images come from our dockerhub.

This PR addresses these requirements, and provide more flexibility in terms of architecture.

How does it works

Since this PR deals with the site factory as well, it is necessary to generate a new site factory and after generate a new site.

Generate the site factory

To run the site-factory generation according to this proposal, execute this command in the root of the project:

docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/app fundocker/cookiecutter gh:Tiago-Salles/richie --directory cookiecutter --checkout Tiago-Salles/issues/274-upstream-cookiecutter

It prompts four questions besides the current question organization:

imagem

  • org_dockerhub: Which will the main dockerhub the project will pull the images, which if not provided it will use the default fundocker.
  • nginx_image_name: the nginx image name, which if not provided it will use the default fundocker/openshift-nginx.
  • nginx_image_tag: the nginx image tag, which if not provided it will use the default 1.13.
  • elasticsearch_image_name: the elasticsearch image name, which if not provided it will use the default fundocker/openshift-elasticsearch:6.6.2.

Generate the new site

In the root of the generated site factory, it is necessary to run make add-site providing the standard information.

In order to have the make demo-site according to the changes made here, replace in the base.txt requirements file the richie package with git+https://github.com/Tiago-Salles/richie@Tiago-Salles/issues/274-upstream-cookiecutter#egg=richie.

Activate the new site

In the root of the site factory it is necessary to run bin/activate so it is possible to select the database. It is worth mentioning that this functionality also provides the possibility of switching the database engine for a running site. Select as well the languages that this site will support.

Fill in the new site

Now, with the richie package replaced with git+https://github.com/Tiago-Salles/richie@Tiago-Salles/issues/274-upstream-cookiecutter#egg=richie in the base.txt of the new site, it is necessary to run make bootstrap and then make demo-site.

What happens in each step

Generate the site factory

All the answers will be used to the define infrastructure resources, from the images to the dockerhub. These answers will be set on the files that manages the site-factory and site, such as Makefile, .circleci folder, site settings.py and the other similars ones.

Generate the new site

This step was not impacted, so it continues being the same.

Activate the new site

This step is focused only in the site. That is, all the content generated here will not impact at the site factory resources.

drawing drawing

Here it sets in the .env the variables:

  • RICHIE_SITE: The site name.

  • ACTIVATED_DB: The site database engine which will be called in the docker-compose.yml file, being included as following

      include:
          - docker-compose-${ACTIVATED_DB}.yml
      services: ...
    

correspoding to the file in the root of the siite factory

drawing

Where in each file is set their business logics as well their dependencies.

  • DB_PORT: Automatically site in according to the ACTIVATED_DB variables, in instance of being mysql its value will be 3306. If the interest is to use another port, feel free to change the value setting a new one in the .env file as DB_PORT={new_port}.

  • LANGUAGES: The site supported languages. It will be called in the settings.py as following

      LANGUAGES = os.getenv("LANGUAGES") or [("en", _("English")), ("fr", _("French"))]
    
      if isinstance(LANGUAGES, str):
          try:
              LANGUAGES = ast.literal_eval(LANGUAGES)
              LANGUAGES = [(code, _(name)) for code, name in LANGUAGES]
          except:
              LANGUAGES = [("en", _("English")), ("fr", _("French"))]
    

Important Observations

It is important to understand that only these mentioned steps are not enough, if on the activate site process was selected the Korean language as one of the languages the site will support, it to must have the ko-KR.json file in the ./sites/{site_name}/src/frontend/i18n/locales/, otherwise the frontend will not provide the possibility to use this language.

By default the backend already provides this language content, but it is worth to check the corresponding language configuration is there as expected, by going to ./sites/{site_name}/src/backend/locale and verifying.

As already mentioned, it is important to replace the richie package with git+https://github.com/Tiago-Salles/richie@Tiago-Salles/issues/274-upstream-cookiecutter#egg=richie in the base.txt of the new site to have all this new features to work.

@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch 5 times, most recently from 38a7369 to 5dfc6d5 Compare January 13, 2025 14:09
@Tiago-Salles Tiago-Salles changed the title Tiago salles/issues/274 upstream cookiecutter (infra) select database to run sites Jan 13, 2025
@Tiago-Salles Tiago-Salles changed the title (infra) select database to run sites 🧱(infra) select database to run sites Jan 13, 2025
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch 8 times, most recently from e687066 to d60d5b8 Compare January 15, 2025 12:08
@Tiago-Salles Tiago-Salles changed the title 🧱(infra) select database to run sites 🧱(architecture) provide architectural flexibility using Richie Jan 15, 2025
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch from d60d5b8 to 602ce7d Compare January 16, 2025 14:53
@igobranco igobranco self-requested a review January 17, 2025 15:14
@Tiago-Salles Tiago-Salles marked this pull request as ready for review January 22, 2025 11:04
@igobranco
Copy link
Collaborator

@Tiago-Salles please include instructions to testing on the PR description.

@igobranco
Copy link
Collaborator

I think the following command execute the cookiecutter of run your PR:

docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/app fundocker/cookiecutter gh:Tiago-Salles/richie --directory cookiecutter --checkout Tiago-Salles/issues/274-upstream-cookiecutter

@Tiago-Salles
Copy link
Collaborator Author

Tiago-Salles commented Jan 24, 2025

I think the following command execute the cookiecutter of run your PR:

docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/app fundocker/cookiecutter gh:Tiago-Salles/richie --directory cookiecutter --checkout Tiago-Salles/issues/274-upstream-cookiecutter

Exactly @igobranco. I used a difference approach to develop, just stepping back and pointing to the directory of the project containing the changes, but this solution you provided is better, as it can be run from any branch. Thank you, I added to the PR description.

@igobranco
Copy link
Collaborator

@Tiago-Salles Please include the "languages" has a cookiecutter question.
So this block will also be generated from those "languages" answer.

LANGUAGES = (("en", _("English")), ("fr", _("French")))
# - Django CMS
CMS_LANGUAGES = {
"default": {
"public": True,
"hide_untranslated": False,
"redirect_on_fallback": True,
"fallbacks": ["en", "fr"],
},
1: [
{
"public": True,
"code": "en",
"hide_untranslated": False,
"name": _("English"),
"fallbacks": ["fr"],
"redirect_on_fallback": False,
},
{
"public": True,
"code": "fr",
"hide_untranslated": False,
"name": _("French"),
"fallbacks": ["en"],
"redirect_on_fallback": False,
},
],
}

@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch from 602ce7d to eef28c1 Compare January 24, 2025 17:33
@igobranco igobranco changed the title 🧱(architecture) provide architectural flexibility using Richie Improve site factory cookiecutter Jan 28, 2025
@igobranco
Copy link
Collaborator

@Tiago-Salles review the commit message:

From:
🧱(infra) select databases to run sites

To:
🧱(cookiecutter) select databases to run sites

Personally, I don't like the logo... why not replace with 🚩? You are just introducing flags... kind of... IMO questions of cookiecutter can be flags!

@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch from 1337c5e to f2de634 Compare January 29, 2025 17:04
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch 9 times, most recently from e6e2931 to 93fd21c Compare February 5, 2025 10:17
- Added org_dockerhub, nginx_image_name, nginx_image_tag
and elasticsearch_image_name parameters to cookiecutter
in order to obtain more flexiblity using the site factory
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch 2 times, most recently from 2d95df6 to 2c29536 Compare February 5, 2025 12:07
- Added in the activate script the possibility to
select the database and the languages that the activating
site will support. It also reflects in changes in the docker
compose file in order to run the site with the selected database.
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch 2 times, most recently from a42a61f to 5ab7558 Compare February 5, 2025 12:15
@Tiago-Salles Tiago-Salles changed the title Improve site factory cookiecutter Improve cookiecutter and demo-site command Feb 5, 2025
- Improved create demo site script to multilingual generation.
@Tiago-Salles Tiago-Salles force-pushed the Tiago-Salles/issues/274-upstream-cookiecutter branch from 5ab7558 to 7d0c48e Compare February 5, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants