Skip to content

Commit

Permalink
added changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cym-yuval committed Jan 17, 2024
1 parent 534b0b6 commit 72ba2f2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
username: yuvals41
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: Application/
Expand Down
4 changes: 2 additions & 2 deletions Application/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM python:3.9.18-slim-bookworm as builder

WORKDIR /app
# Installing dumb-init for better process handling, usually application like Python or Node shouldnt run as process 1
# Didnt installed gcc because there was no need for it
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
dumb-init \
&& rm -rf /var/lib/apt/lists/*
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
Expand Down
47 changes: 40 additions & 7 deletions Application/webapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, jsonify
from flask import Flask, jsonify, request
import requests
from dotenv import load_dotenv
import json
Expand Down Expand Up @@ -30,6 +30,7 @@ def request_github_api(url: str, headers: dict):


def get_repo_names():
repo_names = {}
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {GITHUB_TOKEN}"
Expand All @@ -46,15 +47,14 @@ def get_repo_names():
repo_num = i + 1
# repo_names.update({f"repo-name{i}": name["name"]})
repo_names[f"repo-name{repo_num}"] = data["name"]
repo_names = json.dumps(repo_names)

logging.info("created repos json")

return repo_names,200
return jsonify(repo_names),200


def check_private_repos():
non_private_repos = dict()
non_private_repos = []

headers = {
"Accept": "application/vnd.github+json",
Expand All @@ -71,13 +71,42 @@ def check_private_repos():

return jsonify({"message":"all repos are not private"}),500

for i, repo in enumerate(repos):
repo_num = i + 1
for repo in repos:
if repo["private"] == False:
non_private_repos[f"repo{repo_num}"] = repo["name"]
non_private_repos.append(repo["name"])

return jsonify({"message": f"these are the non private repos: {non_private_repos}"}), 200

def create_git_repo():
headers = {
"Accept": "application/vnd.github+json",
f"Authorization": "Bearer {GITHUB_TOKEN}",
"X-GitHub-Api-Version": "2022-11-28"
}

try:
try:
user_data = request.json
# return jsonify(f"data received: {data}"), 201
logging.info(f"data received: {user_data}")
except Exception as e:
logging.error(f"Missing data: {e}")
return jsonify("bad request"), 400

if not user_data["repo_name"] or not user_data["private"]:
logging.error("Body does not contain repo_name or private fields")
return jsonify("Body does not contain repo name or specified if repo is private"), 400

logging.info("creating repo in github")
requests.post(f"https://api.github.com/{GITHUB_USER}/repos",data=user_data,headers=headers) #TODO need to create new token with read permissions
# print(response)

except Exception as e:
logging.error(f"An error has a occured while trying to create github repo {e}")
return e, 500





@app.route('/check-repos-private')
Expand All @@ -94,6 +123,10 @@ def get_repos():
def ready():
return jsonify({"status": "healthy"}),200

@app.route("/create-repo",methods=['POST'])
def create_repo():
return create_git_repo()


if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
4 changes: 2 additions & 2 deletions Kubernetes/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "{{ $.Chart.Name }}-{{ $.Values.app }}"
name: {{ $.Chart.Name }}
labels:
app: {{ $.Values.app }}
{{- with $.Values.ingress.annotations }}
Expand All @@ -19,7 +19,7 @@ spec:
path: {{ $.Values.ingress.path }}
backend:
service:
name: "{{ $.Chart.Name }}-{{ $.Values.app }}"
name: {{ $.Chart.Name }}
port:
number: {{ $.Values.service.port }}
{{- end }}
6 changes: 3 additions & 3 deletions Kubernetes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ deployment:
memory: "1Gi"
#cpu: "1500m"
healthProbes:
enabled: false
enabled: true
readinessProbe:
enabled: true
path: /ready
port: 5000
livenessProbe:
enabled: false
enabled: true
path: /ready
port: 5000
securityContext:
Expand All @@ -40,6 +40,6 @@ service:
port: 80

ingress:
enabled: false
enabled: true
hostname: localhost
path: /
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ After one minute because the nginx controller takes a few seconds to be ready yo

```
curl http://localhost/funnyfact
curl http://localhost/uselessfact
```


Expand Down

0 comments on commit 72ba2f2

Please sign in to comment.