Skip to content

Commit

Permalink
Reintroduce fixtures for demo site
Browse files Browse the repository at this point in the history
  • Loading branch information
ychab committed Dec 27, 2023
1 parent 782f660 commit 44a0053
Show file tree
Hide file tree
Showing 47 changed files with 21,684 additions and 47 deletions.
56 changes: 42 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.EXPORT_ALL_VARIABLES:

CURRENT_MAKEFILE := $(lastword $(MAKEFILE_LIST))
FIXTURES_FILE_ID = 11smbQZPF-wib-aMRUgR_uPuBzR_7zd1t

include .env

Expand Down Expand Up @@ -44,7 +45,7 @@ fixtures_dump:
sed -i -E 's/"latest_revision": (.+)/"latest_revision": null,/g' folioblog/core/fixtures/pages.json

fixtures_load:
python manage.py fixtures load
python manage.py fixtures load --reset

################
# Docker command
Expand Down Expand Up @@ -133,6 +134,15 @@ apptrans:
docker compose exec app bash -c 'cd folioblog && python ../manage.py makemessages -d djangojs -l en -l es -l fr'
docker compose exec app bash -c 'cd folioblog && python ../manage.py compilemessages -l en -l es -l fr'

appfixturesdump:
docker compose exec app python manage.py fixtures dump
sed -i -E 's/"latest_revision_created_at": (.+)/"latest_revision_created_at": null,/g' folioblog/core/fixtures/pages.json
sed -i -E 's/"live_revision": (.+)/"live_revision": null,/g' folioblog/core/fixtures/pages.json
sed -i -E 's/"latest_revision": (.+)/"latest_revision": null,/g' folioblog/core/fixtures/pages.json

appfixturesload:
docker compose exec app python manage.py fixtures load --reset

apptest:
docker compose exec app bash -c 'DJANGO_SETTINGS_MODULE=folioblog.settings.test python manage.py test --noinput --exclude-tag=slow --parallel=4 folioblog'

Expand All @@ -146,6 +156,37 @@ appcron:
docker compose exec app python manage.py generaterenditions
docker compose exec app python manage.py loadcachepages

##############
# Initial data
##############

initial_media:
rm -Rf media/favicons media/images media/original_images
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=${FIXTURES_FILE_ID}' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=${FIXTURES_FILE_ID}" -O media.tar.gz && rm -rf /tmp/cookies.txt
tar xzf media.tar.gz
rm media.tar.gz

initial_data: initial_media fixtures_load

initial_data_dev: initial_media appfixturesload

initial_data_prod: initial_media appfixturesload
docker compose cp media/. app:${FOLIOBLOG_MEDIA_ROOT}
docker compose exec app python manage.py updatesite --site=1 --hostname=folio.local --port 443

#############
# Certificate
#############

certs:
openssl req -x509 \
-nodes \
-days 365 \
-newkey rsa:2048 \
-keyout ./docker/prod/nginx/ssl/certs/folio-selfsigned.key \
-out ./docker/prod/nginx/ssl/certs/folio-selfsigned.crt \
-config ./docker/prod/nginx/ssl/csr.conf

###############
# Restore tools
###############
Expand Down Expand Up @@ -182,16 +223,3 @@ restore_prod: restore_media restore_db
docker compose exec app python manage.py updatesite --site=1 --hostname=folio.local --port 443
docker compose exec app python manage.py updatesite --site=2 --hostname=blog.folio.local --port 443
docker compose exec app python manage.py updatesite --site=3 --hostname=demo.folio.local --port 443

#############
# Certificate
#############

certs:
openssl req -x509 \
-nodes \
-days 365 \
-newkey rsa:2048 \
-keyout ./docker/prod/nginx/ssl/certs/folio-selfsigned.key \
-out ./docker/prod/nginx/ssl/certs/folio-selfsigned.crt \
-config ./docker/prod/nginx/ssl/csr.conf
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ npm install
npm run dist
python manage.py migrate
python manage.py createsuperuser
make initial_data # OPTIONAL
python manage.py runserver
curl http://127.0.0.1:8000/admin
````
Expand All @@ -120,7 +121,8 @@ Then, you can setup the services with the following command :
cp env/.env.LOCAL .env # Edit it
cp env/.env.DEV .env.dev # Edit if needed
cp folioblog/settings/local.py.dist folioblog/settings/local.py # Edit if needed
make up
make up_wait
make initial_data_dev # OPTIONAL
curl http://127.0.0.1:8000/admin # Connect with admin/admin
````

Expand All @@ -146,7 +148,8 @@ You will have to:
cp env/.env.LOCAL .env # Edit it
cp env/.env.PROD .env.prod # Edit if needed
make certs
make up
make up_wait
make initial_data_prod # OPTIONAL
curl https://folio.local/admin # Connect with YOUR <FOLIOBLOG_ADMIN_USERNAME>/<FOLIOBLOG_ADMIN_PASSWD>
````

Expand All @@ -171,7 +174,8 @@ to add lines like:
127.0.0.1 blog.folio.local
````

Finally, you should be able to hit another site: ``curl https://demo.folio.local``
Finally, create a new site with hostname *demo.folio.local* and you should be
able to hit it: ``curl https://demo.folio.local``

### Local only

Expand Down Expand Up @@ -231,6 +235,25 @@ python manage.py createsuperuser
google-chrome http://127.0.0.1:8000/admin &
````

## Performance

When you hit a new fresh page, it could be very slow due to the generation of
images renditions.

If you want to save some time, you could execute the following commands against
a running instance locally:
````
python manage.py runserver
python manage.py generaterenditions # Generate rendtion for gallery full image
python manage.py loadcachepages # Fetch all pages to generate renditions (and BTW, cache page if active)
````

And of course, against a docker container:
````
docker compose exec app python manage.py generaterenditions
docker compose exec app python manage.py loadcachepages
````

## Cron

There is some cron tasks you may need to set up.
Expand Down
25 changes: 21 additions & 4 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ deploy_local() {
echo -e "\n-> Restore DB and media\n"
poetry run make restore_local
else
echo -e "\n-> Up containers\n"
FOLIOBLOG_HEALTHCHECK_INTERVAL=10s docker compose up --detach --wait
echo -e "\n-> Up containers and restore initial data\n"
make up_wait
poetry run python manage.py migrate --noinput
poetry run python manage.py createadmin --username=admin --password=${FOLIOBLOG_ADMIN_PASSWD:-admin}
poetry run make initial_data
fi

echo -e "\nBUILD finished!\n"
Expand Down Expand Up @@ -117,9 +120,13 @@ deploy_dev() {
echo -e "\n-> Cleanup containers\n"
make down_clean

# Rebuild image just in case
echo -e "\n-> Rebuild DEV image\n"
make build

# Create container and init it for the first time (NPM build)
echo -e "\n-> Up containers\n"
FOLIOBLOG_HEALTHCHECK_INTERVAL=10s docker compose up --detach --wait
make up_wait

# Restore containers
if [ $HAS_RESTORE = 1 ]; then
Expand All @@ -129,6 +136,9 @@ deploy_dev() {

echo -e "\n-> Restore DB and media\n"
make restore_dev
else
echo -e "\n-> Restore initial data\n"
make initial_data_dev
fi

echo -e "\nBUILD finished!\n"
Expand Down Expand Up @@ -170,9 +180,13 @@ deploy_prod() {
echo -e "\n-> Cleanup containers\n"
make down_clean

# Rebuild image just in case
echo -e "\n-> Rebuild PROD image\n"
make build

# Create container and init it (superuser & co).
echo -e "\n-> Up containers\n"
FOLIOBLOG_HEALTHCHECK_INTERVAL=10s docker compose up --detach --wait
make up_wait

# Restore containers OR up
if [ $HAS_RESTORE = 1 ]; then
Expand All @@ -182,6 +196,9 @@ deploy_prod() {

echo -e "\n-> Restore DB and media\n"
make restore_prod
else
echo -e "\n-> Restore initial data\n"
make initial_data_prod
fi

echo -e "\nBUILD finished!\n"
Expand Down
8 changes: 3 additions & 5 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN apt update --yes --quiet && apt install --yes --quiet --no-install-recommend
wget \
curl \
tar \
git \
xz-utils

# Then install nodeJS with NPM.
Expand All @@ -34,12 +35,9 @@ RUN rm /opt/node.tar.xz
# Create an app user.
RUN useradd --create-home --shell /bin/bash appuser

# Fetch source code from GitHub archives.
RUN mkdir /app
RUN wget -O /app/folioblog.tar.gz https://github.com/ychab/wagtail_folioblog/archive/refs/tags/${FOLIOBLOG_RELEASE}.tar.gz
RUN tar xzf /app/folioblog.tar.gz -C /app/ --no-same-owner --strip-components=1
# Fetch source with git for simplicity
RUN git clone --depth=1 --branch=${FOLIOBLOG_RELEASE} https://github.com/ychab/wagtail_folioblog.git /app
RUN chown -R appuser:appuser /app
RUN rm /app/folioblog.tar.gz

# Create virtualenv and install backend dependencies with gunicorn.
RUN python -m venv ${VIRTUAL_ENV}
Expand Down
Empty file removed folioblog/blog/fixtures/.gitkeep
Empty file.
101 changes: 101 additions & 0 deletions folioblog/blog/fixtures/blogcategories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"model": "blog.blogcategory",
"pk": 7,
"fields": {
"translation_key": "165b7f6f-25b4-414d-ace2-d4f0e9f58e07",
"locale": 1,
"site": 1,
"name": "France",
"slug": "france"
}
},
{
"model": "blog.blogcategory",
"pk": 8,
"fields": {
"translation_key": "52b6436e-ad06-49f7-8968-5a37ffc734a8",
"locale": 1,
"site": 1,
"name": "Colombie",
"slug": "colombie"
}
},
{
"model": "blog.blogcategory",
"pk": 9,
"fields": {
"translation_key": "ffe3e8c8-7a4b-4ef2-963f-649b1f9ab0a3",
"locale": 1,
"site": 1,
"name": "États-unis",
"slug": "etats-unis"
}
},
{
"model": "blog.blogcategory",
"pk": 10,
"fields": {
"translation_key": "a47a7b4c-7faa-4bf1-bd0a-70202106cc0a",
"locale": 2,
"site": 1,
"name": "France",
"slug": "france"
}
},
{
"model": "blog.blogcategory",
"pk": 11,
"fields": {
"translation_key": "41da8a72-62bf-48e3-b373-ea6a4c8e8764",
"locale": 2,
"site": 1,
"name": "United States",
"slug": "united-states"
}
},
{
"model": "blog.blogcategory",
"pk": 12,
"fields": {
"translation_key": "aae60c64-11a1-4b0c-ad6a-f51e0cdf866e",
"locale": 2,
"site": 1,
"name": "Colombia",
"slug": "colombia"
}
},
{
"model": "blog.blogcategory",
"pk": 13,
"fields": {
"translation_key": "ecb1f053-1023-440c-849f-7285ff184367",
"locale": 3,
"site": 1,
"name": "Colombia",
"slug": "colombia"
}
},
{
"model": "blog.blogcategory",
"pk": 14,
"fields": {
"translation_key": "a51f8b29-4b22-4a57-ab54-c312f50f4f30",
"locale": 3,
"site": 1,
"name": "Francia",
"slug": "francia"
}
},
{
"model": "blog.blogcategory",
"pk": 15,
"fields": {
"translation_key": "128348d4-0203-4ca6-a5d8-978c7b8fed14",
"locale": 3,
"site": 1,
"name": "Estados Unidos",
"slug": "estados-unidos"
}
}
]
29 changes: 29 additions & 0 deletions folioblog/blog/fixtures/blogindex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"model": "blog.blogindexpage",
"pk": 94,
"fields": {
"subheading": "Exemple de villes par ChatGPT",
"image": 274,
"image_alt": "Paysage"
}
},
{
"model": "blog.blogindexpage",
"pk": 118,
"fields": {
"subheading": "Example of cities by ChatGPT",
"image": 274,
"image_alt": "Landscape"
}
},
{
"model": "blog.blogindexpage",
"pk": 142,
"fields": {
"subheading": "Ejemplo de ciudades por ChatGPT",
"image": 274,
"image_alt": "Paisaje"
}
}
]
Loading

0 comments on commit 44a0053

Please sign in to comment.