Skip to content

Commit

Permalink
Add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Mar 27, 2024
1 parent a0caaf2 commit 68db9dc
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 58 deletions.
53 changes: 0 additions & 53 deletions .editorconfig

This file was deleted.

4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"flake8.cwd": "${workspaceFolder}",
"flake8.args": ["--config=pyproject.toml"],
}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
ARG PLONE_VERSION=6.0.9
ARG PLONE_VERSION
ARG SEED=1000
FROM plone/server-builder:${PLONE_VERSION} as builder

Expand All @@ -15,8 +15,8 @@ COPY . src/kitconcept.voltolighttheme
RUN <<EOT
set -e
mv src/kitconcept.voltolighttheme/requirements-docker.txt ./requirements.txt
mv src/kitconcept.voltolighttheme/scripts/create_site.py ./scripts/create_site.py
mv src/kitconcept.voltolighttheme/scripts/default.json ./scripts/default.json
mv src/kitconcept.voltolighttheme/scripts/* ./scripts/.
# mv src/kitconcept.voltolighttheme/docker-entrypoint.sh ./docker-entrypoint.sh
bin/pip install -r requirements.txt
bin/python /compile_mo.py
rm -Rf src/ /compile_mo.py compile_mo.log
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ include *.yml
include *.md
exclude *-mxdev.txt
exclude Dockerfile
exclude docker-entrypoint.sh
recursive-exclude .vscode *
exclude mx.ini
exclude Makefile
recursive-exclude frontend *
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ DISTRIBUTIONS="voltolighttheme"
IMAGE_NAME=ghcr.io/kitconcept/voltolighttheme
IMAGE_TAG=latest

PLONE6=6.0.9
PLONE_VERSION=6.0.9
PLONE6=6
PLONE_VERSION=6
SEED=$$(date +'%Y%m%d-%H%M%S')

# Python checks
Expand Down
130 changes: 130 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
set -e

if [ -z "${PIP_PARAMS}" ]; then
PIP_PARAMS=""
fi

# Only in build time we should have a secret with
# admin password
if [ -f "/run/secrets/ADMIN_PASSWORD" ]; then
echo "Found /run/secrets/ADMIN_PASSWORD file, using it as secret"
ADMIN_PASSWORD=$(cat /run/secrets/ADMIN_PASSWORD);
export ADMIN_PASSWORD=${ADMIN_PASSWORD}
fi

# CLIENT HOME
CLIENT_HOME="/data/$(hostname)/$(hostid)"
export CLIENT_HOME=$CLIENT_HOME

USER="$(id -u)"

# Create directories to be used by Plone
mkdir -p /data/filestorage /data/blobstorage /data/cache /data/log $CLIENT_HOME
if [ "$USER" = '0' ]; then
find /data -not -user plone -exec chown plone:plone {} \+
sudo="gosu plone"
else
sudo=""
fi

# MAIN ENV Vars
[ -z ${SECURITY_POLICY_IMPLEMENTATION+x} ] && export SECURITY_POLICY_IMPLEMENTATION=C
[ -z ${VERBOSE_SECURITY+x} ] && export VERBOSE_SECURITY=off
[ -z ${DEFAULT_ZPUBLISHER_ENCODING+x} ] && export DEFAULT_ZPUBLISHER_ENCODING=utf-8
[ -z ${DEBUG_MODE+x} ] && export DEBUG_MODE=off
[ -z ${ZOPE_FORM_MEMORY_LIMIT+x} ] && export ZOPE_FORM_MEMORY_LIMIT=50MB

# ZODB ENV Vars
[ -z ${ZODB_CACHE_SIZE+x} ] && export ZODB_CACHE_SIZE=50000

if [[ -v RELSTORAGE_DSN ]]; then
MSG="Using Relstorage configuration"
CONF=relstorage.conf
# Relstorage ENV Vars
[ -z ${RELSTORAGE_NAME+x} ] && export RELSTORAGE_NAME=storage
[ -z ${RELSTORAGE_READ_ONLY+x} ] && export RELSTORAGE_READ_ONLY=off
[ -z ${RELSTORAGE_KEEP_HISTORY+x} ] && export RELSTORAGE_KEEP_HISTORY=true
[ -z ${RELSTORAGE_COMMIT_LOCK_TIMEOUT+x} ] && export RELSTORAGE_COMMIT_LOCK_TIMEOUT=30
[ -z ${RELSTORAGE_CREATE_SCHEMA+x} ] && export RELSTORAGE_CREATE_SCHEMA=true
[ -z ${RELSTORAGE_SHARED_BLOB_DIR+x} ] && export RELSTORAGE_SHARED_BLOB_DIR=false
[ -z ${RELSTORAGE_BLOB_CACHE_SIZE+x} ] && export RELSTORAGE_BLOB_CACHE_SIZE=100mb
[ -z ${RELSTORAGE_BLOB_CACHE_SIZE_CHECK+x} ] && export RELSTORAGE_BLOB_CACHE_SIZE_CHECK=10
[ -z ${RELSTORAGE_BLOB_CACHE_SIZE_CHECK_EXTERNAL+x} ] && export RELSTORAGE_BLOB_CACHE_SIZE_CHECK_EXTERNAL=false
[ -z ${RELSTORAGE_BLOB_CHUNK_SIZE+x} ] && export RELSTORAGE_BLOB_CHUNK_SIZE=1048576
[ -z ${RELSTORAGE_CACHE_LOCAL_MB+x} ] && export RELSTORAGE_CACHE_LOCAL_MB=10
[ -z ${RELSTORAGE_CACHE_LOCAL_OBJECT_MAX+x} ] && export RELSTORAGE_CACHE_LOCAL_OBJECT_MAX=16384
[ -z ${RELSTORAGE_CACHE_LOCAL_COMPRESSION+x} ] && export RELSTORAGE_CACHE_LOCAL_COMPRESSION=none
[ -z ${RELSTORAGE_CACHE_DELTA_SIZE_LIMIT+x} ] && export RELSTORAGE_CACHE_DELTA_SIZE_LIMIT=100000
elif [[ -v ZEO_ADDRESS ]]; then
MSG="Using ZEO configuration"
CONF=zeo.conf
# Check ZEO variables
[ -z ${ZEO_SHARED_BLOB_DIR+x} ] && export ZEO_SHARED_BLOB_DIR=off
[ -z ${ZEO_READ_ONLY+x} ] && export ZEO_READ_ONLY=false
[ -z ${ZEO_CLIENT_READ_ONLY_FALLBACK+x} ] && export ZEO_CLIENT_READ_ONLY_FALLBACK=false
[ -z ${ZEO_STORAGE+x} ] && export ZEO_STORAGE=1
[ -z ${ZEO_CLIENT_CACHE_SIZE+x} ] && export ZEO_CLIENT_CACHE_SIZE=128MB
[ -z ${ZEO_DROP_CACHE_RATHER_VERIFY+x} ] && export ZEO_DROP_CACHE_RATHER_VERIFY=false
else
MSG="Using default configuration"
CONF=zope.conf
fi

# Handle CORS
$sudo /app/bin/python /app/scripts/cors.py

# Handle ADDONS installation
if [[ -v ADDONS ]]; then
echo "======================================================================================="
echo "Installing ADDONS ${ADDONS}"
echo "THIS IS NOT MEANT TO BE USED IN PRODUCTION"
echo "Read about it: https://github.com/plone/plone-backend/#extending-from-this-image"
echo "======================================================================================="
/app/bin/pip install ${ADDONS} ${PIP_PARAMS}
fi

# Handle development addons
if [[ -v DEVELOP ]]; then
echo "======================================================================================="
echo "Installing DEVELOPment addons ${DEVELOP}"
echo "THIS IS NOT MEANT TO BE USED IN PRODUCTION"
echo "Read about it: https://github.com/plone/plone-backend/#extending-from-this-image"
echo "======================================================================================="
/app/bin/pip install --editable ${DEVELOP} ${PIP_PARAMS}
fi

if [[ "$1" == "start" ]]; then
# Handle Site creation
if [[ -v SITE ]]; then
export TYPE=${TYPE:-volto}
echo "======================================================================================="
echo "Creating Plone ${TYPE} SITE: ${SITE}"
echo "Additional profiles: ${PROFILES}"
echo "THIS IS NOT MEANT TO BE USED IN PRODUCTION"
echo "Read about it: https://github.com/plone/plone-backend/#extending-from-this-image"
echo "======================================================================================="
export SITE_ID=${SITE}
$sudo /app/bin/zconsole run etc/${CONF} /app/scripts/create_site.py
fi
echo $MSG
exec $sudo /app/bin/runwsgi -v etc/zope.ini config_file=${CONF}
elif [[ "$1" == "create-classic" ]]; then
export TYPE=classic
exec $sudo /app/bin/zconsole run etc/${CONF} /app/scripts/create_site.py
elif [[ "$1" == "create-volto" ]]; then
export TYPE=volto
exec $sudo /app/bin/zconsole run etc/${CONF} /app/scripts/create_site.py
elif [[ "$1" == "create-site" ]]; then
export TYPE=volto
exec $sudo /app/bin/zconsole run etc/${CONF} /app/scripts/create_site.py
elif [[ "$1" == "console" ]]; then
exec $sudo /app/bin/zconsole debug etc/${CONF}
elif [[ "$1" == "run-maintenance" ]]; then
exec $sudo /app/bin/zconsole run etc/${CONF} /app/scripts/run_maintenance.py ${@:2}
elif [[ "$1" == "run" ]]; then
exec $sudo /app/bin/zconsole run etc/${CONF} ${@:2}
else
# Custom
exec "$@"
fi
5 changes: 5 additions & 0 deletions src/kitconcept/voltolighttheme/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def migrate_backgroundColor(portal):
obj = brain.getObject()
blocks = obj.blocks
logger.info(f"Processing {obj.absolute_url()}")
output += f"Processing {obj.absolute_url()}\n"
for block in visit_blocks(obj, blocks):
if block.get("styles", False) and block["styles"].get(
"backgroundColor", False
Expand All @@ -53,6 +54,7 @@ def migrate_backgroundColor(portal):
logger.info(
f'{obj.absolute_url()} - Updated "backgroundColor" to "backgroundColor:noprefix"'
)
output += f'{obj.absolute_url()} - Updated "backgroundColor" to "backgroundColor:noprefix"\n'

obj.blocks = blocks
modified(obj)
Expand All @@ -73,6 +75,7 @@ def migrate_button_block_width(portal):
obj = brain.getObject()
blocks = obj.blocks
logger.info(f"Processing {obj.absolute_url()}")
output += f"Processing {obj.absolute_url()}\n"
for block in visit_blocks(obj, blocks):
if (
block.get("@type", False)
Expand All @@ -89,6 +92,7 @@ def migrate_button_block_width(portal):
block.clear()
block.update(new_block)
logger.info(f'{obj.absolute_url()} - Updated "width"')
output += f'{obj.absolute_url()} - Updated "width"\n'

obj.blocks = blocks
modified(obj)
Expand All @@ -106,4 +110,5 @@ def __call__(self):
output = ""
output += migrate_backgroundColor(self.context) + "\n"
output += migrate_button_block_width(self.context) + "\n"
self.request.response.setHeader("Content-Type", "text/plain")
return output

0 comments on commit 68db9dc

Please sign in to comment.