Saturday, November 21, 2020

٢. الاعتمادات

 

II. Dependencies

٢. الاعتمادات

Explicitly declare and isolate dependencies

تعريف وعزل الاعتمادات صراحة

Most programming languages offer a packaging system for distributing support libraries, such as CPAN for Perl or Rubygems for Ruby. Libraries installed through a packaging system can be installed system-wide (known as “site packages”) or scoped into the directory containing the app (known as “vendoring” or “bundling”).

معظم لغات البرمجة تقدم نظام تحزيم للمكتبات الداعمة، مثل Rubygems للغة روبي

المكتبات المثبتة من خلال نظام تحزيم يمكن تثبيتها علي مستوي النظام بالكامل، او في نطاق المجلد الذي يحتوي التطبيق فقط

A twelve-factor app never relies on implicit existence of system-wide packages. It declares all dependencies, completely and exactly, via a dependency declaration manifest. Furthermore, it uses a dependency isolation tool during execution to ensure that no implicit dependencies “leak in” from the surrounding system. The full and explicit dependency specification is applied uniformly to both production and development.

التطبيق المطابق للقواعد ١٢ لابد الا يعتمد علي المكتبات المثبتة علي مستوي النظام بشكل ضمني. وانما يقوم بتعريف الاعتمادات صراحة وكلية عبر بيان تعريف الاعتمادات. واكثر من ذلك فانه يجب ان يستخدم اداة لعزل الاعتمادات اثناء التنفيذ لضمان عدم التأثر الخارجي من النظام المحيط. بيان الاعتمادات الكامل يجب ان يكون مطبقا بشكل رسمي اثناء التشغيل والتطوير ايضا

For example, Bundler for Ruby offers the Gemfile manifest format for dependency declaration and bundle exec for dependency isolation. In Python there are two separate tools for these steps – Pip is used for declaration and Virtualenv for isolation. Even C has Autoconf for dependency declaration, and static linking can provide dependency isolation. No matter what the toolchain, dependency declaration and isolation must always be used together – only one or the other is not sufficient to satisfy twelve-factor.

علي سبيل المثال، اداة bundler في لغة روبي تقدم ملف Gemfile كنموذج لبيان الاعتمادات، و اداة bundle exec لعزل الاعتمادات
في لغة بايثون هناك اداتين مختلفتين، pip مستخدم في التعريف، و Virtualenv للعزل. حتي لغة C لديها Autoconf لتعريف الاعتمادات، والربط الاستاتيكي يقوم بدور عزل الاعتمادات. ايا كانت الادوات، فان تعريف وعزل الاعتمادات يجب استخدامهما سويا، استخدام واحد منهما دون الاخر لا يجعل التطبيق مطابقا للقواعد ال١٢

One benefit of explicit dependency declaration is that it simplifies setup for developers new to the app. The new developer can check out the app’s codebase onto their development machine, requiring only the language runtime and dependency manager installed as prerequisites. They will be able to set up everything needed to run the app’s code with a deterministic build command. For example, the build command for Ruby/Bundler is bundle install, while for Clojure/Leiningen it is lein deps.

احدي فوائد التعريف الصريح للاعتمادات هو تسهيل التنصيب للمطور المستجد، المطور المستجد يمكنه استكشاف كود التطبيق وتحميله علي جهازه، معتمدا فقط علي بيئة التشغيل ومدير الاعتمادات كمطلب أولي. بعدها يكون قادرا علي تنصيب كل شئ مطلوب لتشغيل التطبيق من خلال أمر بناء محد. مثلا فإن امر البناد للغة روبي هو bundle install, بينما في لغة clojure هو lein deps

Twelve-factor apps also do not rely on the implicit existence of any system tools. Examples include shelling out to ImageMagick or curl. While these tools may exist on many or even most systems, there is no guarantee that they will exist on all systems where the app may run in the future, or whether the version found on a future system will be compatible with the app. If the app needs to shell out to a system tool, that tool should be vendored into the app.

التطبيق المطابق للقواعد ال١٢ لا يعتمد علي افتراض وجود ادوات النظام ضمنيا.ادوات مثل ImageMagick او curl. ادوات كهذه ربما تكون موجودة علي معظم الاجهزة، الا انه لا يوجد ضمان لوجودها في كل النظم التي سيعمل عليها النظام مستقبلا، او ان الاصدارات ستكون ملائمة للتطبيق. اذا كان التطبيق سيحتاج الي احدي ادوات النظام فلابد ان تكون هذه الاداة معبئة مع التطبيق

١. الكود

 

I. Codebase

الكود

One codebase tracked in revision control, many deploys

كود واحد مدرج في نظام المراجعة، وعدة اطلاقات

A twelve-factor app is always tracked in a version control system, such as GitMercurial, or Subversion. A copy of the revision tracking database is known as a code repository, often shortened to code repo or just repo.

التطبيق يجب ان يكون مدرجا في نظام مراجعة مثل git او subversion
ويكون هناك قاعدة بيانات لمراجعات الكود تسمي مستودع الكود، يمكن تسميتها اختصارا : مستودع

codebase is any single repo (in a centralized revision control system like Subversion), or any set of repos who share a root commit (in a decentralized revision control system like Git).

كود التطبيق هو اي مستودع (سواء كان نظام المراجعة مركزيا آو لا)

One codebase maps to many deploys

There is always a one-to-one correlation between the codebase and the app:

  • If there are multiple codebases, it’s not an app – it’s a distributed system. Each component in a distributed system is an app, and each can individually comply with twelve-factor.
  • Multiple apps sharing the same code is a violation of twelve-factor. The solution here is to factor shared code into libraries which can be included through the dependency manager.

هناك دائما ارتباط وثيق بين الكود والتطبيق

- لو كان هناك اكثر من كود-بيز فهذا ليس بتطبيق، وانما هو نظام موزع. حيث يكون كل مكون من مكونات النظام الموزعهو تطبيق مستقل يمكن اخضاعه الي قواعد ال١٢ عامل

- وجود عدة تطبيقات تتشارك في نفس الكودبيز هو خرق لقواعد ال١٢ عامل. والحل في هذه الحالة هو اعادة هيكلة الكود الي مكتبات يمكن ادراجها الي تلك التطبيقات بواسطة مدير الاعتماد

There is only one codebase per app, but there will be many deploys of the app. A deploy is a running instance of the app. This is typically a production site, and one or more staging sites. Additionally, every developer has a copy of the app running in their local development environment, each of which also qualifies as a deploy.

يجب ان يكون هناك كودبيز واحد فقط للتطبيق، ولكن يمكن ان يكون هناك عدة اطلاقات للتطبيق. الاطلاقة هي نسخة عاملة من التطبيق. نعني بذلك وجود نسخة قيد الاستخدام، ونسخة او اكثر لتجريب ما قبل الاستخدام. بالاضافة الي امتلاك كل مطور لنسخة قيد التطوير، كل منها يمكن اعتبارها اطلاقة بذاتها

The codebase is the same across all deploys, although different versions may be active in each deploy. For example, a developer has some commits not yet deployed to staging; staging has some commits not yet deployed to production. But they all share the same codebase, thus making them identifiable as different deploys of the same app.

الكودبيز هو واحد في الاصل عبر كل الاطلاقات، مع الاخذ في الاعتبار احتمالية اختلاف النسخ عبر الاطلاقات المختلفة. علي سبيل المثال، يمكن ان يكون المبرمج لديه بعض المساهمات لو يتم اطلاقها في نسخة تجريب ما قبل الاستخدام، ونسخة التجريب ما قبل الاستخدام فيها بعض المساهمات لم يتم اطلاقها في النسخة قيد الاستخدام. لكن في النهاية كلها تتشارك في أصل الكودبيز، وبالتالي يمكن اعتبارها نسخ/اطلاقات مختلفة من نفس التطبيق

Thursday, September 13, 2018

Software Technical Tips : How to open multiple files in Vi editor

Software Technical Tips : How to open multiple files in Vi editor: Suppose if you want to open multiple files in Vi editor than do the following commands CTRL + W + s - That means it will open the same ...