Skip to content

Commit

Permalink
Merge pull request #100 from toms3t/enhancement/refactoring
Browse files Browse the repository at this point in the history
Merge enchancement/refactoring into Master - 2
  • Loading branch information
toms3t committed Jul 20, 2019
2 parents 83cae4d + 4f028e6 commit a4764e4
Show file tree
Hide file tree
Showing 17 changed files with 874 additions and 485 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -54,6 +54,7 @@ coverage.xml
debug.log*
local_settings.py
secret.py
Secret.py
propalyzer_site/propalyzer_app/migrations

# Flask stuff:
Expand Down
41 changes: 41 additions & 0 deletions Dockerfile
@@ -0,0 +1,41 @@
FROM ubuntu:latest

COPY requirements_docker.txt /

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt-get --assume-yes install python3-pip

RUN apt-get --assume-yes install git-all

RUN pip3 install --trusted-host pypi.python.org -r requirements_docker.txt

RUN git clone -b enhancement/refactoring --single-branch https://github.com/toms3t/Propalyzer.git

COPY secret.py /Propalyzer/propalyzer_site/propalyzer_app/

COPY settings.py /Propalyzer/propalyzer_site/propalyzer_site/

COPY wsgi.py /Propalyzer/propalyzer_site/propalyzer_site/

RUN cd Propalyzer/propalyzer_site

RUN git config --global user.email tomset@gmail.com

RUN git config --global user.name "Tom Setliffe"

EXPOSE 80

WORKDIR Propalyzer/propalyzer_site

COPY startup.sh /Propalyzer/propalyzer_site/

RUN python3 manage.py makemigrations propalyzer_app

RUN python3 manage.py migrate

RUN python3 manage.py collectstatic

CMD ["./startup.sh"]
63 changes: 27 additions & 36 deletions README.md
@@ -1,4 +1,7 @@
# Propalyzer

[![Build Status](https://tomset.visualstudio.com/Propalyzer/_apis/build/status/toms3t.Propalyzer?branchName=master)](https://tomset.visualstudio.com/Propalyzer/_build/latest?definitionId=7&branchName=master)

Production site can be found at http://propalyzer.info to try functionality

**Time to get up and running = less than 10 minutes**
Expand All @@ -10,44 +13,44 @@ Web app that helps investors evaluate investment property opportunities. The use
- Debt Coverage Ratio
- Monthly Cash Flow
- Scoring of area Livability, Crime, Cost of Living, Education, Employment, Housing, Weather relative to local and national averages
- Localized natural disaster information
- Local School information
- Local natural disaster information
- Local school information

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites (MacOS and Linux Users)

- Install Python 3.6.0
- Install Python 3.6
```
https://www.python.org/downloads/
```
- Obtain a Zillow account and Zillow API Key (REQUIRED)
```
https://www.zillow.com/webservice/Registration.htm
```
- Obtain a GreatSchools API Key (NOT REQUIRED)
- Obtain a GreatSchools API Key (NOT REQUIRED, BUT RECOMMENDED)
```
https://www.greatschools.org/api/request-api-key/
```

- Create and configure virtualenv
```
$ mkdir [directory name]
$ pip install virtualenv
$ cd [directory name]
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 env
$ mkdir Propalyzer
$ python3.6 -m pip install virtualenv
$ cd Propalyzer
$ python3.6 -m venv env
```
- Git dialed in!
```
$ git init
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global user.name "Your Name"
$ git config --global user.email Your_email_address
$ git clone https://github.com/toms3t/Propalyzer.git
```
**The project includes two "secret.py" files - one for the API keys and the other for the settings.py secret key.
The secret.py files are included in the .gitignore file so don't worry about accidentally uploading your API keys**
**The project includes a secret.py file to store API keys on your machine.
secret.py is referenced in the .gitignore file to prevent the secret.py file from being uploaded to GitHub by accident**

- Create a secret.py file in the 'Propalyzer/propalyzer_site/propalyzer_app' folder and enter the following:
```
Expand All @@ -56,17 +59,12 @@ class Secret():
GSCHOOL_API_KEY = '[enter your GreatSchools key here without brackets]'
## now save the file ##
```
- Create a second secret.py file in the 'Propalyzer/propalyzer_site/propalyzer_site' folder and enter the following:
```
class Secret():
SECRET_KEY = '[enter a secret key here without brackets - any random string of characters will work!]'
## now save the file ##
```

- Install packages from requirements.txt file

```
$ source env/bin/activate (run this from the directory you created to activate the virtual environment)
$ pip install -r Propalyzer/requirements.txt
$ source env/bin/activate (run this from the directory with 'env' folder)
$ python -m pip install -r requirements.txt
```
- Prep the SQLite database
```
Expand Down Expand Up @@ -97,33 +95,33 @@ https://conda.io/miniconda.html
```
https://www.zillow.com/webservice/Registration.htm
```
- Obtain a GreatSchools API Key (NOT REQUIRED)
- Obtain a GreatSchools API Key (NOT REQUIRED BUT RECOMMENDED)
```
https://www.greatschools.org/api/request-api-key/
```

- Create and configure virtualenv (Use Windows PowerShell, Command Prompt, or a Terminal Emulator such as ConEmu)
```
> Hit start and type "anaconda" to find the anaconda prompt -- launch the "anaconda prompt"
> mkdir [directory name]
> cd [directory name]
> mkdir Propalyzer
> cd Propalyzer
> conda create --name [virtual environment name]
> activate [virtual environment name]
```
- Git dialed in!
```
> git init
> git config --global user.name "John Doe"
> git config --global user.email johndoe@example.com
> git config --global user.name "Your Name"
> git config --global user.email Your_email_address
> git clone https://github.com/toms3t/Propalyzer.git
```
- Install packages from requirements.txt file

```
> pip install -r Propalyzer/requirements.txt
> python3.6 -m pip install -r Propalyzer/requirements.txt
```
**The project includes two "secret.py" files - one for the API keys and the other for the settings.py secret key.
The secret.py files are included in the .gitignore file so don't worry about accidentally uploading your API keys**
**The project includes a "secret.py" file to store API keys on your machine.
secret.py is referenced in the .gitignore file so don't worry about accidentally uploading your API keys**

- Create a secret.py file in the 'Propalyzer/propalyzer_site/propalyzer_app' folder and enter the following:
```
Expand All @@ -132,13 +130,6 @@ class Secret():
GSCHOOL_API_KEY = '[enter your GreatSchools key here without brackets]'
## now save the file ##
```
- Create a second secret.py file in the 'Propalyzer/propalyzer_site/propalyzer_site' folder and enter the following:
```
class Secret():
SECRET_KEY = '[enter a secret key here without brackets]'
## now save the file ##
```

- Prep the SQLite database
```
> cd Propalyzer/propalyzer_site
Expand All @@ -160,7 +151,7 @@ Log in with your superuser credentials

## Deployment

Not yet deployed in a live environment.
http://propalyzer.info

## Built With

Expand Down
108 changes: 108 additions & 0 deletions azure-pipelines.yml
@@ -0,0 +1,108 @@
# Python Django
# Test a Django project on multiple versions of Python.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
pool:
vmImage: 'Ubuntu 16.04'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: 3.6
architecture: 'x64'

- task: DownloadSecureFile@1
name: secret
displayName: 'Download secret.py file'
inputs:
secureFile: 'secret.py'

- task: DownloadSecureFile@1
name: settings
displayName: 'Download settings.py file'
inputs:
secureFile: 'settings.py'

- task: DownloadSecureFile@1
name: startup
displayName: 'Download startup.sh file'
inputs:
secureFile: 'startup.sh'

- task: DownloadSecureFile@1
name: wsgi
displayName: 'Download wsgi.py file'
inputs:
secureFile: 'wsgi.py'

- task: DownloadSecureFile@1
name: req_docker
displayName: 'Download requirements file'
inputs:
secureFile: 'requirements_docker.txt'

- task: DownloadSecureFile@1
name: dockerfile
displayName: 'Download Dockerfile'
inputs:
secureFile: 'Dockerfile'

- task: PythonScript@0
displayName: 'Export project path'
inputs:
scriptSource: 'inline'
script: |
"""Search all subdirectories for `manage.py`."""
from glob import iglob
from os import path
# Python >= 3.5
manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
if not manage_py:
raise SystemExit('Could not find a Django project')
project_location = path.dirname(path.abspath(manage_py))
print('Found Django project in', project_location)
print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))
- script: |
cp $(secret.secureFilePath) /home/vsts/work/1/s/secret.py
cp $(settings.secureFilePath) /home/vsts/work/1/s/settings.py
cp $(startup.secureFilePath) /home/vsts/work/1/s/startup.sh
cp $(wsgi.secureFilePath) /home/vsts/work/1/s/wsgi.py
cp $(req_docker.secureFilePath) /home/vsts/work/1/s/requirements_docker.txt
cp $(dockerfile.secureFilePath) /home/vsts/work/1/s/Dockerfile
displayName: 'Copy files to build agent'

- task: ShellScript@2
inputs:
scriptPath: filecopy.sh
cwd: '/'

- script: |
python -m pip install --upgrade pip setuptools wheel django
pip install -r requirements_docker.txt
pip install unittest-xml-reporting
displayName: 'Install prerequisites'

- script: |
pushd '$(projectRoot)'
python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input
condition: succeededOrFailed()
displayName: 'Run tests'

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: "**/TEST-*.xml"
testRunTitle: 'Python $(PYTHON_VERSION)'

- task: Docker@2
displayName: Login to Azure Container Registry
inputs:
command: login
containerRegistry: MyContainerRegistry

- task: Docker@2
displayName: Build and Push to ACR
inputs:
command: buildAndPush
repository: prop_dev_repo
7 changes: 7 additions & 0 deletions filecopy.sh
@@ -0,0 +1,7 @@
#!/bin/bash
echo "Start file copy..."
cp /home/vsts/work/1/s/settings.py /home/vsts/work/1/s/propalyzer_site/propalyzer_site/
cat /home/vsts/work/1/s/propalyzer_site/propalyzer_site/settings.py
cp /home/vsts/work/1/s/wsgi.py /home/vsts/work/1/s/propalyzer_site/propalyzer_site/
cp /home/vsts/work/1/s/secret.py /home/vsts/work/1/s/propalyzer_site/propalyzer_app/
echo "Done!"

0 comments on commit a4764e4

Please sign in to comment.