chamilo / chamilo-lms

Chamilo is a learning management system focused on ease of use and accessibility
https://chamilo.org
GNU General Public License v3.0
798 stars 480 forks source link

Chamilo automatic deployment - Ansible #2502

Open bruno911 opened 6 years ago

bruno911 commented 6 years ago

Hi,

I am starting to test Chamilo as an alternative to moodle.

I would like to use automatic deployment, I am currently using Ansible + ansistrano.

Basically the setup is as follow:

This way I can have rollbacks etc. Let's assume I want to create a new them, or customize part of Chamilo and can do it, merge and then redeploy.

There are a couple of issues, the first one is that after deploy I always get the first installation popup, I find out it is due to the file app/configuration that is missing, so I will copy that file after it is generated and merge it into my private repository.

Second issue, when I run the first install after deploying automatically, I get: "A test course has been created successfully": no. While all other are yes, not sure why.

Third issue, is that every time I deploy I will delete the courses as the whole folder is replace with the repository one, the normal fix for this is to use share paths, so I could define for example if all courses were stored in ./main/course I could create that as a symbolic link to /data/chamilo/course and every time I deploy I have the courses always accessible.

I was wondering if anyone has managed to install chamilo using automatic deployments, or if I could be given some hints, for example which folders should be shared between instances and if is possible to set the app/configuration.php manually.

Thank you!

ywarnier commented 6 years ago

Hi @bruno911 First of all: great idea Second: are you expecting to contribute this back to us (the ansible scripts for example) to the project or are you held by some kind of intellectual property rule? (we manage the project as a meritocracy, so the more you share, the more we will help) Third: automation is already working for Softaculous, Installatron and Chamihost, so it's all a matter of detail of what you want to achieve.

bruno911 commented 6 years ago

Sure, I can contribute! I have already managed to do the scripts, and I believe I could contribute in other ways too, like php and cleaning up the issues list :)

I guess somewhere there should be the contribution rules, I will read when I have time and create the first pull request.

bruno911 commented 6 years ago

In the mean time let put the script here, just in case someone finds it interesting.

Ansistrano + ansible + Chamilo.

- name: deploy
  hosts: all
  remote_user: sudo_ad
  vars:
    ansistrano_deploy_from: "/home/bruno/workspace_eclipse/training" # Where my local project is (relative or absolute path)
    ansistrano_deploy_to: "/var/www/training" # Base path to deploy to.
    ansistrano_version_dir: "releases" # Releases folder name
    ansistrano_current_dir: "current" # Softlink name. You should rarely changed it.
    ansistrano_current_via: "symlink" # Deployment strategy who code should be deployed to current path. Options are symlink or rsync
    ansistrano_keep_releases: 0 # Releases to keep after a new deployment. See "Pruning old releases".

  # Arrays of directories and files to be shared.
  # The following arrays of directories and files will be symlinked to the current release directory after the 'update-code' step and its callbacks
  # Notes:
  # * Paths are relative to the /shared directory (no starting /)
  # * If your items are in a subdirectory, write the entire path to each shared directory
  #
  # Example:
  # ansistrano_shared_paths:
  #   - path/to/first-dir
  #   - path/next-dir
  # ansistrano_shared_files:
  #   - my-file.txt
  #   - path/to/file.txt
    ansistrano_shared_paths: ["app/courses","app/home","app/upload"]
    ansistrano_shared_files: []

  # Shared paths and basedir shared files creation.
  # By default the shared paths directories and base directories for shared files are created automatically if not exists. But in some scenarios those paths could be symlinks to another directories in the filesystem, and the deployment process would fails. With these variables you can disable the involved tasks. If you have two or three shared paths, and don't need creation only for some of them, you always could disable the automatic creation and add a custom task in a hook.
    ansistrano_ensure_shared_paths_exist: yes
    ansistrano_ensure_basedirs_shared_files_exist: yes

    ansistrano_deploy_via: "git" # Method used to deliver the code to the server. Options are copy, rsync, git, svn, s3 or download. Copy, download and s3 have an optional step to unarchive the downloaded file which can be used by adding _unarchive. You can check all the options inside tasks/update-code folder!
    ansistrano_allow_anonymous_stats: yes

  # Variables used in the Git deployment strategy
    ansistrano_git_repo: git@bitbucket.org:bquintana911/traning.git # Location of the git repository
    ansistrano_git_branch: master # What version of the repository to check out. This can be the full 40-character SHA-1 hash, the literal string HEAD, a branch name, or a tag name
    ansistrano_git_repo_tree: "" # If specified the subtree of the repository to deploy
    ansistrano_git_identity_key_path: "keys/bruno" # If specified this file is copied over and used as the identity key for the git commands, path is relative to the playbook in which it is used
    ansistrano_git_identity_key_remote_path: "" # If specified this file on the remote server is used as the identity key for the git commands, remote path is absolute
    # Optional variables, omitted by default
    # ansistrano_git_refspec: ADDITIONAL_GIT_REFSPEC # Additional refspec to be used by the 'git' module. Uses the same syntax as the 'git fetch' command.
    ansistrano_git_ssh_opts: "-o StrictHostKeyChecking=no" # Additional ssh options to be used in Git
    ansistrano_git_depth: 1 # Additional history truncated to the specified number or revisions

  # Hooks: custom tasks if you need them
  # ansistrano_before_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-setup-tasks.yml"
  # ansistrano_after_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-setup-tasks.yml"
  # ansistrano_before_update_code_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-update-code-tasks.yml"
  # ansistrano_after_update_code_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-update-code-tasks.yml"
    ansistrano_before_symlink_shared_tasks_file: "{{ playbook_dir }}/inventory/vars/training/before-symlink.yml"
  # ansistrano_after_symlink_shared_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-symlink-shared-tasks.yml"
  # ansistrano_before_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-symlink-tasks.yml"
  #  ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/inventory/vars/training/my-after-symlink-tasks.yml"
  # ansistrano_before_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-cleanup-tasks.yml"
  # ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-cleanup-tasks.yml"
  roles:
    - carlosbuenosvinos.ansistrano-deploy
#File: inventory/vars/training/before-symlink.yml
---

- name: Install composer dependencies
  shell: /opt/plesk/php/7.0/bin/php composer.phar install
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Make config read only
  file:
    path: "{{ ansistrano_release_path.stdout }}/app/config"
    mode: 0555

- name: Delete install folder
  shell: rm -rf "{{ ansistrano_release_path.stdout }}/training/main/install"

Also as I wanted to save some space in bitbucket I have emptied the vendor folder, and I kept the composer.lock so composer install in server will keep always the same version.

And I had changed the .gitignore too, like this:

# Cache directories

app/cache/*
!app/cache/.gitkeep

app/logs/*
!app/logs/.gitkeep

# Chamilo configuration
#/app/config/parameters.yml
#/app/config/add_course.conf.php
#/app/config/auth.conf.php
#/app/config/course_info.conf.php
#/app/config/events.conf.php
#/app/config/mail.conf.php
#/app/config/portfolio.conf.php
#/app/config/profile.conf.php
#/app/config/configuration.php

# Courses
app/courses/*

# Home
app/home/*

# Upload content
app/upload/*

.php_cs.cache

# Logs and databases #
*.log

# IDE settings
.idea
.idea/*
.idea/dictionaries/*
.idea/cssxfire.xml

*.orig
nbproject/*

# Plugins config files
# plugin/bbb/config.vm.php

# Cron temp files
main/cron/incoming/*
plugin/vchamilo/templates/*

# Stuff updated through composer - Remove just before release
vendor
web/assets/*

Basically my steps were, installed Chamilo on the remote server following installation guide, Then I have created a bitbucket repository, I have rsync the files from the server locally and committed that to bitbucket, cleaned up the vendor folder, changed gitignore, committing again, and then I deployed using ansistrano, I've created one course and redeployed, just to make sure courses weren't deleted, everything works as expected although it is not the cleanest of the process and not really straingh forward, but after done once you don't have to think about it anymore.

jmontoyaa commented 6 years ago

We use chash to install chamilo 1.11.x via cli

chash + chamilo + travis

https://github.com/chamilo/chamilo-lms/blob/1.11.x/.travis.yml

ywarnier commented 6 years ago

And chash is here: https://github.com/chamilo/chash ;-)

ywarnier commented 6 years ago

@bruno911 I'm not yet very familiar with Ansible, but as far as I understand we could add a small Ansible script at the root (or somewhere near) of Chamilo. I think Ansible needs more than just one script, so if you would like to contribute that, would you like me to open a chamilo-ansible project that you can clone and send everything you need as Pull Request contributions? I'm trying to close most pending issues of 1.11.8 over the next 10 days, so let me know before that if you would like me to make a note of anything like that in the changelog of 1.11.8.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.