Portal MEC
License
Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre Departamento de Informatica - Universidade Federal do Parana
This file is part of portalmec.
portalmec is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
portalmec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with portalmec. If not, see http://www.gnu.org/licenses/.
Setup with Docker Compose
Requirements
docker >= 20.10.5
git
- ElasticSearch instance
- PostgreSQL
Steps
(Dependending in your docker version, you may need to use docker-compose
instead of docker compose
)
-
Clone the repository.
-
In the root of the repository run
docker compose build
. This will build the necessary images for running PortalMEC. If this command fails, check if you are behind a HTTP Proxy. If that's the case, clean any built images withdocker compose down --rmi all --remove-orphans
and then use-
docker compose build --build-arg HTTP_PROXY="<http proxy url here> --build-arg HTTPS_PROXY="<https proxy url here>"
.
-
-
Make a copy of the
.env.dev
file named.env
and change the necessary configuration. You will need to change at least:PORTALMEC_DB_HOST
PORTALMEC_DB_NAME
PORTALMEC_DB_USERNAME
PORTALMEC_DB_PASSWORD
PORTALMEC_ELASTICSEARCH_HOST
PORTALMEC_ELASTICSEARCH_LOGIN
PORTALMEC_ELASTICSEARCH_PASSWORD
PORTALMEC_ELASTICSEARCH_INDEX_PREFIX
RAILS_ENV
-
This step is only needed if you don't have a database. Run
docker compose run --entrypoint sh app
. This will instantiate a container from theapp
image built in the previous step and run a shell inside it. In the new shell:- Run
bundle exec rake db:create
to create the database.- If you have a database dump, you should use it now. Run in the host:
psql -U <database user> -d <database name> < <dump name>.sql
- If you have a database dump, you should use it now. Run in the host:
- Run
bundle exec rake db:migrate
to create the database schema. - Run
bundle exec rake db:seed
to populate the database with default data. - Run
bundle exec rake searchkick:reindex:all
to index the data in ElasticSearch. - Run
exit
to exit the shell.
- Run
-
Run
docker compose up
.
Local specific configuration
The URL host.docker.internal
inside a docker container is configured to point to the host machine. When you need to use a service running in the host machine (for example a local PostgresSQL installation), you should use this address instead of localhost
.
Old Setup
Requirements
- rvm
- Using rvm you will install ruby "3.0.1"
- ruby "3.0.1"
- Dspace server "6.x"
- Postgres "13"
- Elasticsearch "6.8.13"
- Redis ">=5.0"
- nvm
- Using nvm you will install Node.js "14.15.1"
NVM and Node.js
For install NVM and Node.js, use this follwing commands:
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
$ nvm install 14.15.1
Postgres
After the first install, you can run this commands:
sudo passwd postgres
su postgres
psql -c "ALTER USER postgres WITH PASSWORD '$PASSWORD'" -d template1
createuser -h localhost -U postgres -d $USER_DB
psql -c "ALTER USER $USER_DB WITH PASSWORD '$PASSWORD'" -d template1
Note: You can ask for the database dump for someone in the project.
You need to modify the file "/etc/postgresql/11/main/pg_hba.conf", the modification is
* comment the 1st and 2nd lines with "peer" and copy them replacing "peer" with "md5".
After this, run this command:
systemctl restart postgresql
Rvm
After finish the installer, you will need to add in your ~/.bashrc this commands:
export PATH="$PATH:$HOME/.rvm/bin"
source /home/Your_user/.rvm/scripts/rvm
After this, run the command source ~/.bashrc
.
Note
: If does not work, you can try modify the commands above, for this:
export PATH="$PATH:/usr/share/rvm/bin"
source /usr/share/rvm/scripts/rvm
Setup
First of all, you need to configure the dspace, elasticsearch and redis servers. Create an user for postgres database. After this setup, open the configuration files inside the project repository and update the following files:
* config/database.yml: change your postgres credentials for development and test environment.
* config/dspace.yml: change your dspace host and credentials for development and test environment.
* config/sidekiq.yml: change your redis hosts and ports.
* config/initializers/elasticsearch.rb: inside elsif Rails.env.test? change url 'elasticsearch:9200' to 'localhost:9200'.
* config/initializers/gitlab.rb: change your gitlab host for bug reports and set env var with private token. ( $ export GITLAB_PORTALMEC_PRIVATE_TOKEN=131237128937128937 )
Install
After installed the requeriments, the first you will need to do is run:
bundle install
This command will install all required gems for the project.
Note
: Sometimes some gems throw errors. That is because there is a chance that you do not have all the required dependecies for the installation of the gem that failed to install. Please install the dependencies and try again.
After all gems were installed succesfuly. Please create the database using the following commands:
rake db:create
- If you have the dump of the database, use it before db:migrate.
- To use the dump, run this commands:
psql -U $DATABASE_USER -d $DATABASE_NAME < $DATABASE_PATH/dump_name.sql
- To use the dump, run this commands:
rake db:migrate
- Then run
rake db:seed
.
Note
: You need to load the dump in the database_dev.
This procedure will create and configure all table in the project database
For the search mechanism to works, execute the CMD in the portalmec directory rake searchkick:reindex:all
.
Once finished, your application is read to be used. To acess it, run CMD:
bundle exec rails s
For tests, run this commands:
-
export DSPACE_LOGIN=your_login
-
export DSPACE_PASS=your_password
-
source ~/.bashrc
-
bundle exec rake spec:acceptance
Production environment
When working in the production environment, the environment variables must be set in the file config/env_vars.sh. After setting the variables in the file, you must include the following line into your user's .bashrc file:
source /home/portalmec/portalmec/config/env_vars.sh
You will also need to make some other configurations:
* Redis vars need to be set on config/sidekiq.yml
* In config/initializers/devise.rb, change the e-mail addresses. (Ex.: config.mailer_sender = 'suporte@suporte.com')
* In app/services/learning_object_publisher.rb, in the create_dspace_item change the DSpace collection where the items are gonna be created.
* Change the paths in the *.sh and *.service files in the root of the project to the absolute path of the project in the production server.
* As root, copy the *.service files to the server's systemd directory (Ex.: /lib/systemd/system), then run systemctl enable portalmec and systemctl enable portalmec-sidekiq.
* As root, copy the sidekiq_log.conf file to the rsyslog directory (/etc/rsyslog.d/) and give the shared/logs/sidekiq.log file the same permissions and ownership as the /var/log/syslog file.
Now that your application is ready, you can run it with:
systemctl start portalmec portalmec-sidekiq