Skip to content

Commit

Permalink
changed directory structure and creating default backend for webapp w…
Browse files Browse the repository at this point in the history
…ith an html template
  • Loading branch information
cym-yuval committed Jan 19, 2024
1 parent 090303b commit 89d1b65
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: Application/
context: Application/webapp
push: true
load: false
# tags: yuvals41/discordbot:${{ github.run_number }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
pycache
venv
mongo-data
3 changes: 0 additions & 3 deletions Application/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions Application/code.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions Application/pymongo.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.gitignore
Jenkinsfile
*.md
*.md
mongo-data
File renamed without changes.
33 changes: 33 additions & 0 deletions Application/webapp/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.8"

services:
webapp:
build:
context: "."
dockerfile: Dockerfile
container_name: webapp
restart: always
env_file: .env
networks:
- webapp
ports:
- 5000:5000

mongodb:
image: mongo:6.0.13-jammy
container_name: mongodb
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
networks:
- webapp
ports:
- 27017:27017
volumes:
- ./mongo-data:/data/db


networks:
webapp:

16 changes: 16 additions & 0 deletions Application/webapp/pymongo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pymongo import MongoClient
from flask import Flask

app = Flask(__name__)

client = MongoClient("mongodb://admin:admin@localhost","27017")

db = client["yuval"]


if "githubRepos" not in db.list_collection_names():
db.create_collection("githubRepos")

collection = db.get_collection("githubRepos")

collection.insert_one()
File renamed without changes.
55 changes: 55 additions & 0 deletions Application/webapp/templates/error_html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
text-align: center;
padding: 50px;
}
.error-container {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
display: inline-block;
}
.error-container h1 {
color: #333;
font-size: 24px;
}
.error-container p {
color: #666;
}
.error-container a {
display: inline-block;
padding: 10px 15px;
background-color: #007bff;
color: #fff;
border-radius: 5px;
text-decoration: none;
margin-top: 20px;
}
.error-container a:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="error-container">
<h1>Oops! Something went wrong.</h1>
<p>We're sorry, but something went wrong. Please try again later.</p>
<a href="/">Go Back Home</a>
<h3>Available Routes:</h3>
<ul>
{% for route in available_routes %}
<li><a href="{{ route }}">{{ route }}</a></li>
{% endfor %}
</ul>
</div>
</body>
</html>
10 changes: 6 additions & 4 deletions Application/webapp.py → Application/webapp/webapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, jsonify, request
from flask import Flask, jsonify, request, render_template
import requests
from dotenv import load_dotenv
import json
Expand All @@ -10,6 +10,7 @@

GITHUB_USER = os.environ.get("GITHUB_USER") or "yuvals41"
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
available_routes = ["/create-repo", "/ready", "/get-repos", "/check-repos-private"]

if not GITHUB_TOKEN:
logging.error("GitHub token not set. Exiting.")
Expand Down Expand Up @@ -106,9 +107,6 @@ def create_git_repo():
return e, 500





@app.route('/check-repos-private')
def check_private():
return check_private_repos()
Expand All @@ -127,6 +125,10 @@ def ready():
def create_repo():
return create_git_repo()

@app.errorhandler(404)
def page_not_found(error):
return render_template("error_html.html",available_routes=available_routes)


if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)

0 comments on commit 89d1b65

Please sign in to comment.