-
Notifications
You must be signed in to change notification settings - Fork 2
Create Dockerfile for LibraryMetricScripts and Pull librarycomparisonswebsite images from Docker Hub #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XiaoleZ
wants to merge
47
commits into
master
Choose a base branch
from
create-dockerfile
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create Dockerfile for LibraryMetricScripts and Pull librarycomparisonswebsite images from Docker Hub #43
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
1afc1e1
create docker-compose file for LibraryMetricScripts and librarycompar…
e26a48b
update
4042cb8
enable the docker for combinding two repos
12eb56c
mysql problem to connect the host
45a1a64
run web successfully
85a4a25
update the readme
b53c425
update the readme
2c01a39
update readme
533beaf
update readme
8812cc5
revert the changes
fe02889
revert the changes
fd925a7
create the shared folder
b11ab27
create a shared folder in home/scripts/charts
0701eb9
update the app.py
ddb6be1
add the readme
2bc7e44
update readme
f78550b
update readme
0917ebc
update readme
f0d3db9
add openJDK (java) in docker
bc081e6
finish testing
ddec4b5
udpate the readme
643a3b6
Update libraries that changed repo urls
snadi 181d84d
Address Issue #36 popularity calculation
snadi 09eb866
Add git stash first
d089e21
Fix thousands number format
15a0f57
create docker-compose file for LibraryMetricScripts and librarycompar…
7d8dadf
update
295fc4a
enable the docker for combinding two repos
b0e6835
mysql problem to connect the host
af31859
run web successfully
f4871cd
update the readme
68fb526
update the readme
487d853
update readme
8a9f137
update readme
1e50747
revert the changes
ba276b9
revert the changes
4db6569
create the shared folder
fa24571
create a shared folder in home/scripts/charts
a6d8608
add the readme
f03cf2c
update readme
3ee8560
update readme
08cbb82
update readme
6d98a2e
add openJDK (java) in docker
83388ce
finish testing
1f4d1d0
udpate the readme
cb001b5
Sync with master
snadi 6e55a04
Add WIP notes for testing containers
snadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| use libcomp; | ||
| alter table Metric add unique (name); | ||
| insert into Metric(name) value("popularity"); | ||
| insert into Metric(name) value("release frequency"); | ||
| insert into Metric(name) value("last discussed on so"); | ||
| insert into Metric(name) value("last modification date"); | ||
| insert into Metric(name) value("breaking changes"); | ||
| insert into Metric(name) value("issue response"); | ||
| insert into Metric(name) value("issue closing"); | ||
| insert into Metric(name) value("issue classification"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| version: "3.9" | ||
| services: | ||
| metric-script: | ||
| build: | ||
| context: . | ||
| dockerfile: ./docker/Dockerfile | ||
| restart: always | ||
| stdin_open: true | ||
| tty: true | ||
| volumes: | ||
| - shared_data:/home/scripts | ||
| container_name: "metric-script" | ||
| depends_on: | ||
| - "db" | ||
| web: | ||
| image: ualbertasmr/librarycomparisons_web:latest | ||
| hostname: web | ||
| restart: always | ||
| stdin_open: true | ||
| tty: true | ||
| ports: | ||
| - "8000:8000" | ||
| volumes: | ||
| - shared_data:/home/scripts | ||
| networks: | ||
| default: | ||
| container_name: "librarycomparisons_web" | ||
| depends_on: | ||
| - "db" | ||
| db: | ||
| image: ualbertasmr/librarycomparisons_db:latest | ||
| hostname: db | ||
| restart: always | ||
| command: | ||
| --default-authentication-plugin=mysql_native_password | ||
| ports: | ||
| - "3306:3306" | ||
| volumes: | ||
| - ./database:/docker-entrypoint-initdb.d | ||
| - db_data:/var/lib/mysql | ||
| networks: | ||
| default: | ||
| environment: | ||
| MYSQL_HOST: localhost | ||
| MYSQL_PORT: 3306 | ||
| MYSQL_DATABASE: "libcomp" | ||
| MYSQL_PASSWORD: "mypwd" | ||
| MYSQL_ROOT_PASSWORD: "mypwd" | ||
|
|
||
| volumes: | ||
| db_data: | ||
| shared_data: | ||
|
|
||
| networks: | ||
| default: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| FROM python:3.8.0-slim | ||
|
|
||
| # Install OpenJDK 11 | ||
| ENV DEBIAN_FRONTEND=noninteractive | ||
| RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2 | ||
| RUN apt-get update && apt-get install -y --no-install-recommends openjdk-11-jre | ||
| # Prints installed java version, just for checking | ||
| RUN java --version | ||
|
|
||
| WORKDIR /main | ||
|
|
||
| COPY . /main | ||
|
|
||
| ENV PYTHONPATH="/main/scripts:${PYTHONPATH}" | ||
|
|
||
| RUN apt-get update; \ | ||
| apt-get -y install sudo; \ | ||
| sudo apt-get -y install default-libmysqlclient-dev \ | ||
| gcc \ | ||
| default-mysql-client \ | ||
| default-mysql-server \ | ||
| git \ | ||
| libpangocairo-1.0-0; \ | ||
| pip install --trusted-host pypi.python.org -r requirements.txt; | ||
|
|
||
| ENTRYPOINT [ "bash", "./docker/start.sh" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| Temp notes for updating ReadMe: | ||
|
|
||
| - had to run the down with -v to delete data | ||
| - followed exact instructions... but noticed that you have to run createmetrics from inside the script in docker-compose step (seems in parallel with leaving the other things running). Need to clarify that in instructions | ||
| - Had a problem with the SO key because my key was on old version of API. Had to do it for API V2.0 | ||
| - Next step is to check: if I exit metrics container, is data still saved in DB? Can I import the DB dump in DB and have it reflect in website? Can I trigger update in the container from localhost? Right now, the release data is taking time to be calculated. | ||
| - Remove note about MAXSIZE since it's not used anymore | ||
| - Add note that for testing, reduce num of libs in the lib file | ||
|
|
||
| # How to calculate metrics & run visualization website using docker | ||
|
|
||
| This is a simple way to run the metrics and also get a local website setup to view the metrics (similar to [https://smr.cs.ualberta.ca/comparelibraries/](https://smr.cs.ualberta.ca/comparelibraries/) | ||
|
|
||
| You'll need to have [docker](https://docs.docker.com/get-docker/) and [docker-compose](https://docs.docker.com/compose/install/) installed. | ||
|
|
||
| - After cloning this repo, you first need to set up some of the configuration parameters in the file `scripts/Config.json`: | ||
| - Change the value of `TOKEN` to your own GitHub generated token. ([How to create Github TOKEN](https://github.com/ualberta-smr/LibraryMetricScripts/wiki/Creating-access-tokens#github-token)). | ||
| - Change the value of `SO_TOKEN` to your stack exchange key. ([How to create StackOverflow TOKEN](https://github.com/ualberta-smr/LibraryMetricScripts/wiki/Creating-access-tokens#stackoverflow-token)). Please make sure to create a token for v2.0 of the API. | ||
| - Change `"OUTPUT_PATH"` to `"../home/scripts/"`. | ||
|
|
||
| - You can update the `MAXSIZE` to 100 in `Config.json` for testing purpose. | ||
|
|
||
| ## 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 && Starts the website** | ||
| ``` | ||
| docker-compose up | ||
| ``` | ||
| To access the website, use http://127.0.0.1:8000/comparelibraries/ | ||
|
|
||
| **Run metric script:** | ||
| The above step will have the website running, but right now, there is no data in the DB yet to be displayed. To calculate the metrics, run: | ||
|
|
||
| ``` | ||
| docker-compose run metric-script | ||
| ``` | ||
|
|
||
| This will open an interactive shell into the container and you can then invoke `createmetrics` to calculate the Metrics: | ||
|
|
||
| ``` | ||
| root@e7c767ab1a70:/main# createmetrics | ||
| ``` | ||
|
|
||
| **(Optional) Open librarycomparisons website command shell:** | ||
| ``` | ||
| docker-compose run --service-ports web | ||
| ``` | ||
| - `start`: Starts the Django server. The librarycomparison web will run in the `8000` port by default. | ||
| - `migrate`: Runs Django migrations | ||
| - `make`: Runs Django makemigrations | ||
| - `createsuperuser`: Runs Django createsuperuser | ||
|
|
||
| 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; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/bash | ||
|
|
||
| echo "alias createmetrics='python -m scripts'" >> ~/.bashrc | ||
| echo "alias updatemetrics='./updatemetrics.sh'" >> ~/.bashrc | ||
|
|
||
| /bin/bash | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ cairosvg | |
| gitpython | ||
| mysqlclient>=1.4.6 | ||
| djangorestframework>=3.11 | ||
| beautifulsoup4>=4.9.3 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import requests | ||
| from bs4 import BeautifulSoup | ||
| import re | ||
| import json | ||
| from scripts.CommonUtilities import Common_Utilities | ||
| from scripts.SharedFiles.utility_tool import read_json_file | ||
|
|
||
| """Gets number of dependent repos as calculated by github dependency graph https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-the-dependency-graph#:~:text=The%20dependency%20graph%20is%20a,packages%20that%20depend%20on%20it | ||
|
|
||
| Parameters | ||
| ---------- | ||
| repo : str | ||
| Github repo represented as user/repo | ||
|
|
||
| Returns | ||
| ------- | ||
| num_dependents | ||
| number of dependents | ||
| """ | ||
| def get_num_dependents(repo): | ||
| #inspired from Bertrand Martel's answer on https://stackoverflow.com/questions/58734176/how-to-use-github-api-to-get-a-repositorys-dependents-information-in-github | ||
| url = 'https://github.com/{}/network/dependents'.format(repo) | ||
| dependent_href = '/{}/network/dependents?dependent_type=REPOSITORY'.format(repo) | ||
| r = requests.get(url) | ||
| soup = BeautifulSoup(r.content, "html.parser") | ||
|
|
||
| if len(soup.body.findAll("We haven’t found any dependents for this repository yet.")) != 0: | ||
| return 0 | ||
|
|
||
| dependents = soup.find('a', href= dependent_href) #returns, for example, "1,234,000 Repositories" | ||
| #regex from https://www.regexpal.com/98336 | ||
| num_dependents = re.search(r'(\d{0,3},)?(\d{3},)?\d{0,3}', dependents.text.strip()).group(0) | ||
| print(num_dependents) | ||
| return num_dependents | ||
|
|
||
| def read_libraries(file_path): | ||
| libdict = {} | ||
| f = read_json_file(file_path) | ||
| for line in f: | ||
| libdict[line['Package']]=line['FullRepoName'] | ||
|
|
||
| return libdict | ||
|
|
||
| def send_totals_to_file(output_file, keyword, num_found): | ||
| output_file = open(output_file, "a") | ||
| output_file.write(keyword + ":" + str(num_found) + "\n") | ||
| output_file.close() | ||
|
|
||
| def get_popularity(): | ||
| print("Getting popularity") | ||
| config_dict = Common_Utilities.read_config_file() # read all config data | ||
|
|
||
| library_dict = read_libraries(config_dict["LIBRARY_LIST"]) # read all libraries to search against | ||
|
|
||
| output_file_name = config_dict["POPULARITY_OUTPUT_FILE"] # this is the output file that we are going to send libraries with their total counts to | ||
|
|
||
| output_file = open(output_file_name, "w") | ||
| output_file.close() | ||
|
|
||
| for keyword,repo in library_dict.items(): | ||
| print("for lib", repo) | ||
| num_dependents = get_num_dependents(repo) | ||
| send_totals_to_file(output_file_name, repo, num_dependents) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| get_popularity() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.