Django+Wagtail+CRX+Puput の移設1(移設 - CRX0.25)
2023/02 の作業
別のインスタンスに移す事にした。
・ついでに、各種パッケージを新バージョンにする。
・構成、サイト名等は全く同じで作成し、現環境のインスタンスは終了する予定。
新環境にできるだけ最新のパッケージを入れて、モジュールやデータを持って行ったが、失敗。
同一バージョンで一旦作成し、バージョンアップする事にする。
最終的には、それぞれ以下の様なバージョンに更新
PostgreSQL 13.7 -> 14.7 Python 3.9.10 -> 3.9.16 Django 3.2.12 -> 3.2.18 wagtail 2.14.2 -> 3.0.3 coderedcms 0.22.3 -> 1.0.1 puput 1.1.3 -> 1.2.0
現環境のデータを吸い上げ
PostgreSQLのデータをダンプ:
$ sudo su - postgres $ pg_dump workdb > dump.sql
現環境を固める:
$ sudo su - work_user $ tar --exclude "*.pyc" --exclude "*.djcache" -zcvf workesite.tar.gz ./workesite
インストールするモジュール一覧の情報を取得:
$ sudo su - work_user $ source work_venv/bin/activate $ pip freeze > requirements.txt
新環境へパッケージのインストール
・PostgreSQL(14)インストール (参考:PostgreSQLを入れる)
・DB作成 (参考:PostgreSQLにDBを作る)
・pythonインストール (参考:Pythonインストール)
・venv作成 (参考:Django・Wagtail・CodeRed・Puput インストール)
・現環境で取得したモジュール一覧をインストール(コンパイルしているみたいなので、psycopg2以外)
・psycopg2をインストール (参考:psycopg2を入れる)
現環境のデータをインポート
PostgreSQLのデータをロード:
$ sudo su - postgres $ psql -d workdb -f dump.sql
現環境で取得したのモジュールを展開:
$ sudo su - work_user $ tar xvfz workesite.tar.gz
新環境に移設した内容を一旦動作確認
・s3 のstatic や media にアクセスできる様にcorsのアクセス許可してあげる。
prod.py のアクセスホストを許可してあげる:
・・・・ #ALLOWED_HOSTS = ['w1.massolezume.ga'] ALLOWED_HOSTS = ['*'] ・・・・
起動:
$ sudo su - work_user $ source work_venv/bin/activate $ python manage.py runserver --settings workesite.settings.prod
アクセスして、同じように表示されればそのままの移設は完了。
coderedcms を 0.25.* に一旦アップデート
coderedcmsのバージョンが1.0にアップデートされていて、v1.0.0 release notes (https://docs.coderedcorp.com/wagtail-crx/releases/v1.0.0.html) にバージョンアップ方法が書いてある。
1.0にアップデートする場合は、一旦0.25にしてからがよいと書いてある。
0.25にアップデート:
$ sudo su - work_user $ source work_venv/bin/activate $ pip install -U coderedcms==0.25.* ・・・・ Successfully installed coderedcms-0.25.2 django-bootstrap4-22.1 django-taggit-2.1.0 icalendar-4.1.0 wagtail-2.16.3
更新したのでマイグレーション:
$ python manage.py makemigrations --settings workesite.settings.prod Migrations for 'website': website/migrations/0003_auto_20230202_1736.py - Alter field body on articleindexpage ・・・・ $ python manage.py migrate --settings workesite.settings.prod Operations to perform: Apply all migrations: admin, auth, coderedcms, contenttypes, puput, sessions, taggit, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, wagtailseo, wagtailusers, website Running migrations: Applying taggit.0004_alter_taggeditem_content_type_alter_taggeditem_tag... OK ・・・・
変更点の確認:
$ wagtail updatemodulepaths --list Checked 20 .py files, 0 files to update.
特に変更はしなくてよい。
Wagtail CRX 0.25にアップデート後の動作確認
s3 は現環境で使っているので、一旦動作確認様に、static、media 等をローカルで動かすように prod.py を変更。
static、media の s3 の設定をコメントアウトして、デバッグ用の設定を入れる:
・・・・ #DEBUG = False DEBUG = True ・・・・ STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ] ・・・・ STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' ・・・・
static を集め直す:
$ python manage.py collectstatic --settings workesite.settings.prod You have requested to collect static files at the destination location as specified in your settings. This will overwrite existing files! Are you sure you want to do this? Type 'yes' to continue, or 'no' to cancel: yes Found another file with the destination path 'colorful/arrow.gif'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path. Found another file with the destination path 'colorful/colorPicker.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path. 474 static files copied, 7 unmodified.
media を s3 から持ってくる:
$ export AWS_ACCESS_KEY_ID=アクセスキーID $ export AWS_SECRET_ACCESS_KEY=シークレットアクセスキー $ export AWS_DEFAULT_REGION=リージョン $ $ aws s3 cp s3://work-bucket/media . --recursive Completed 8.4 KiB/~4.7 MiB (58.7 KiB/s) with ~50 file(s) remaining (calculating...)download: s3://work-bucket/media/images/001_ec2_instance.max-165x165.png to images/001_ec2_instance.max-165x165.png ・・・・
起動:
$ sudo su - work_user $ source work_venv/bin/activate $ python manage.py runserver --settings workesite.settings.prod
アクセスして、同じように表示されれば0.25へのアップデートは完了。