ualberta-smr / LibraryMetricScripts

Scripts to collect metrics from software libraries.
MIT License
4 stars 2 forks source link

Create Dockerfile for LibraryMetricScripts and Pull librarycomparisonswebsite images from Docker Hub #43

Open XiaoleZ opened 3 years ago

XiaoleZ commented 3 years ago

What it does?

Create Dockerfile for LibraryMetricScripts and Pull librarycomparisonswebsite images from Docker Hub

Why it is import?

It makes the database setup more easier and it allows the user to run librarycomparisonswebsite locally

How to test it?

Follow the updated Readme.md file.

Docker Local Development Setup

This is a simple way to get a local librarycomparison web development server set up.

You'll need to have Docker and Docker Compose installed.

Creating the image

1. Builds/Rebuilds the image (not start the containers) in the docker-compose.yml file:

docker-compose build --no-cache

2. Starts the containers

Starts the containers && Start the server

docker-compose up

Run metric script:

docker-compose run metric-script

(Optional) Open librarycomparisons website command shell:

docker-compose run --service-ports web

To access the website, use http://127.0.0.1:8000/comparelibraries/

3. Stops containers and removes containers, networks, volumes, and images created by up

docker-compose down

Remove volume: docker-compose down -v. Warning: this will permanently delete the contents in the db_data volume, wiping out any previous database you had there

4. Setup Metric Table if you create the docker volumn for the first time

docker exec  librarymetricscripts_db_1 /bin/sh -c  'mysql -uroot -p"mypwd"  libcomp  < docker-entrypoint-initdb.d/metric-setup.sql'

Accessing docker container mysql databases

  1. docker exec -it MyContainer mysql -uroot -pMyPassword eg: docker exec -it librarymetricscripts_db_1 mysql -uroot -p"mypwd"
  2. Show MySQL Databases: show databases;
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | libcomp            |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
  3. Show MySQL Tables:
    use libcomp;
    show tables;
  4. Show Table's schema
    describe libcomp.Metric;
  5. Show the values of Metric table
    select * from libcomp.Metric;
snadi commented 3 years ago

hi @XiaoleZ As discussed, I've created a dockerhub organization https://hub.docker.com/orgs/ualbertasmr and added you as an owner. I've linked the ualberta-smr organization account to it. Can you see if you are able to push the container there now instead of using your personal account? Let me know if there are any issues!

XiaoleZ commented 3 years ago

@snadi Thank you. I will put the images in the org docker hub

snadi commented 3 years ago

Why are we changing output_path to ../home/scripts/ ?

snadi commented 3 years ago

I get this error when creating the metrics

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/main/scripts/__main__.py", line 4, in <module>
    app.run()
  File "/main/scripts/app.py", line 26, in run
    addlibraries()
  File "/main/scripts/addlibraries.py", line 27, in addlibraries
    if not domain.exists():
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 809, in exists
    return self.query.has_results(using=self.db)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/query.py", line 535, in has_results
    return compiler.has_results()
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1126, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'libcomp.Domain' doesn't exist")

I think that the domain tables haven't been created yet. So does this mean that the steps need to be done in reverse? That you need to run the migrate for the website first?

XiaoleZ commented 3 years ago

Update the PR: Tested for 2 library and display the charts successfully. Screen Shot 2021-03-11 at 4 33 37 PM Screen Shot 2021-03-11 at 4 30 47 PM

XiaoleZ commented 3 years ago

Why are we changing output_path to ../home/scripts/ ?

Because the charts is in ../home/scripts/ (not in the metricscript or web container). The views.py read the charts from ../home/scripts/ . So the charts can be display on the web.'

I move this change in the code. output_path = ../home/scripts/ is for the docker. If we want to run locally we need to change to the file we store the charts