macrdel commited on
Commit
134d85e
1 Parent(s): e2898af

update workflow

Browse files
.github/workflows/main.yml CHANGED
@@ -7,6 +7,7 @@ on:
7
  jobs:
8
  build:
9
  runs-on: ubuntu-latest
 
10
  steps:
11
  - name: Checkout code
12
  uses: actions/checkout@v2
@@ -20,38 +21,28 @@ jobs:
20
  username: ${{ secrets.DOCKER_USERNAME }}
21
  password: ${{ secrets.DOCKER_PASSWORD }}
22
 
23
- - name: Build Docker images
24
- run: |
25
- docker-compose -f docker-compose.yml build
 
 
26
 
27
  test:
28
  runs-on: ubuntu-latest
29
  needs: build
30
- services:
31
- docker:
32
- image: docker:19.03.12
33
- options: --privileged
34
- ports:
35
- - 8000:8000
36
- #- 8002:8000
37
- - 9090:9090
38
- - 3000:3000
39
- #- 8080:8080
40
  steps:
41
  - name: Checkout code
42
  uses: actions/checkout@v2
43
 
44
- - name: Set up Docker Compose
45
- run: |
46
- docker-compose -f docker-compose.yml up -d
47
-
48
  - name: Run tests
49
  run: |
50
- docker-compose -f docker-compose.yml run tests
51
 
52
  push:
53
  runs-on: ubuntu-latest
54
  needs: test
 
55
  steps:
56
  - name: Checkout code
57
  uses: actions/checkout@v2
@@ -62,9 +53,18 @@ jobs:
62
  username: ${{ secrets.DOCKER_USERNAME }}
63
  password: ${{ secrets.DOCKER_PASSWORD }}
64
 
65
- - name: Push Docker images
 
 
 
 
66
  run: |
67
- docker-compose -f docker-compose.yml push
 
 
 
 
 
68
 
69
  deploy:
70
  runs-on: ubuntu-latest
 
7
  jobs:
8
  build:
9
  runs-on: ubuntu-latest
10
+
11
  steps:
12
  - name: Checkout code
13
  uses: actions/checkout@v2
 
21
  username: ${{ secrets.DOCKER_USERNAME }}
22
  password: ${{ secrets.DOCKER_PASSWORD }}
23
 
24
+ - name: Build Docker image for app
25
+ run: docker build -t macrdel/sentiment-summarize-youtube-comments-backend:latest .
26
+
27
+ - name: Build Docker image for tests
28
+ run: docker build -t macrdel/sentiment-summarize-youtube-comments-backend-tests:latest .
29
 
30
  test:
31
  runs-on: ubuntu-latest
32
  needs: build
33
+
 
 
 
 
 
 
 
 
 
34
  steps:
35
  - name: Checkout code
36
  uses: actions/checkout@v2
37
 
 
 
 
 
38
  - name: Run tests
39
  run: |
40
+ docker run --rm macrdel/sentiment-summarize-youtube-comments-backend-tests:latest pytest tests
41
 
42
  push:
43
  runs-on: ubuntu-latest
44
  needs: test
45
+
46
  steps:
47
  - name: Checkout code
48
  uses: actions/checkout@v2
 
53
  username: ${{ secrets.DOCKER_USERNAME }}
54
  password: ${{ secrets.DOCKER_PASSWORD }}
55
 
56
+ - name: Push application
57
+ run: |
58
+ docker run -d --name app --network example-network --ip 172.16.238.10 -p 8000:8000 macrdel/sentiment-summarize-youtube-comments-backend:latest uvicorn app.api:app --host 0.0.0.0 --port 8000
59
+
60
+ - name: Push Prometheus
61
  run: |
62
+ docker run -d --name prometheus --network example-network --ip 172.16.238.11 -p 9090:9090 -v $(pwd)/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:latest
63
+
64
+ - name: Push Grafana
65
+ run: |
66
+ docker run -d --name grafana --network example-network --ip 172.16.238.12 -p 3000:3000 -v $(pwd)/grafana/provisioning:/etc/grafana/provisioning --env-file $(pwd)/grafana/config.monitoring grafana/grafana
67
+
68
 
69
  deploy:
70
  runs-on: ubuntu-latest
Dockerfile CHANGED
@@ -2,9 +2,9 @@ FROM python:3.10.5
2
 
3
  WORKDIR /code
4
 
5
- COPY requirements.txt .
6
 
7
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
8
 
9
  RUN useradd -m -u 1000 user
10
  USER user
@@ -13,7 +13,7 @@ ENV HOME=/home/user \
13
 
14
  WORKDIR $HOME/app
15
 
16
- COPY --chown=user . .
17
 
18
  ENV PYTHONPATH=/home/user/app
19
 
 
2
 
3
  WORKDIR /code
4
 
5
+ COPY ./requirements.txt /code/requirements.txt
6
 
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
  RUN useradd -m -u 1000 user
10
  USER user
 
13
 
14
  WORKDIR $HOME/app
15
 
16
+ COPY --chown=user . $HOME/app
17
 
18
  ENV PYTHONPATH=/home/user/app
19
 
Dockerfile.Test DELETED
@@ -1,20 +0,0 @@
1
- FROM python:3.10.5
2
-
3
- WORKDIR /code
4
-
5
- COPY requirements.txt .
6
-
7
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
8
-
9
- RUN useradd -m -u 1000 user
10
- USER user
11
- ENV HOME=/home/user \
12
- PATH=/home/user/.local/bin:$PATH
13
-
14
- WORKDIR $HOME/app
15
-
16
- COPY --chown=user . .
17
-
18
- ENV PYTHONPATH=/home/user/app
19
-
20
- # CMD ["pytest", "tests"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/api.py CHANGED
@@ -2,10 +2,11 @@ from config import config
2
  from app.src.src import pipeline_sentiment, pipeline_stats, pipeline_summarize
3
 
4
  from fastapi import FastAPI
 
 
5
  from pydantic import BaseModel
6
  # from transformers import pipeline
7
  # import uvicorn
8
- from prometheus_client import start_http_server, Summary
9
  import pandas as pd
10
  import os
11
 
@@ -16,7 +17,6 @@ SENT_API_URL = f"https://api-inference.huggingface.co/models/{config.sentiment_m
16
  SUM_API_URL = f"https://api-inference.huggingface.co/models/{config.sum_model}"
17
 
18
  app = FastAPI()
19
- REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
20
 
21
  class YouTubeUrl(BaseModel):
22
  url_video: str
@@ -43,9 +43,15 @@ def get_summarize():
43
  data = pd.read_csv(f"{config.DATA_FILE}")
44
  return pipeline_summarize(data['text_comment'], headers, SUM_API_URL)
45
 
46
- @app.on_event("startup")
47
- def startup_event():
48
- start_http_server(8000)
 
 
 
 
 
 
49
 
50
 
51
  #if __name__ == '__main__':
 
2
  from app.src.src import pipeline_sentiment, pipeline_stats, pipeline_summarize
3
 
4
  from fastapi import FastAPI
5
+ from fastapi.middleware.cors import CORSMiddleware
6
+ from prometheus_fastapi_instrumentator import Instrumentator
7
  from pydantic import BaseModel
8
  # from transformers import pipeline
9
  # import uvicorn
 
10
  import pandas as pd
11
  import os
12
 
 
17
  SUM_API_URL = f"https://api-inference.huggingface.co/models/{config.sum_model}"
18
 
19
  app = FastAPI()
 
20
 
21
  class YouTubeUrl(BaseModel):
22
  url_video: str
 
43
  data = pd.read_csv(f"{config.DATA_FILE}")
44
  return pipeline_summarize(data['text_comment'], headers, SUM_API_URL)
45
 
46
+ app.add_middleware(
47
+ CORSMiddleware,
48
+ allow_origins=["*"],
49
+ allow_credentials=True,
50
+ allow_methods=["*"],
51
+ allow_headers=["*"],
52
+ )
53
+
54
+ Instrumentator().instrument(app).expose(app)
55
 
56
 
57
  #if __name__ == '__main__':
docker-compose.yml CHANGED
@@ -1,18 +1,20 @@
1
- version: '3.7'
2
 
3
  services:
4
  app:
5
  build: .
6
- command: uvicorn app.api:app --host 0.0.0.0 --port 8000 # --reload
7
- container_name: "sentiment-summarize-youtube-comments"
 
8
  ports:
9
- - "8000:8000"
10
  volumes:
11
  - .:/home/user/app
12
  environment:
13
  - PYTHONPATH=/home/user/app
14
- depends_on:
15
- - prometheus
 
16
 
17
  # app2:
18
  # build: .
@@ -39,27 +41,35 @@ services:
39
  # - app2
40
 
41
  prometheus:
42
- image: prom/prometheus
 
43
  container_name: prometheus
 
 
44
  volumes:
45
  - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
46
- ports:
47
- - "9090:9090"
 
48
 
49
  grafana:
50
  image: grafana/grafana
51
  container_name: grafana
52
- ports:
53
- - "3000:3000"
54
- environment:
55
- - GF_SECURITY_ADMIN_PASSWORD=admin
56
  depends_on:
57
  - prometheus
 
 
 
 
 
 
 
 
 
58
 
59
  tests:
60
- build:
61
- context: .
62
- dockerfile: Dockerfile.Test
63
  volumes:
64
  - .:/home/user/app
65
  environment:
@@ -67,3 +77,12 @@ services:
67
  depends_on:
68
  - app
69
  command: pytest tests
 
 
 
 
 
 
 
 
 
 
1
+ version: "3.10.5"
2
 
3
  services:
4
  app:
5
  build: .
6
+ restart: unless-stopped
7
+ command: uvicorn app.api:app --host 0.0.0.0 --port 8000
8
+ container_name: app
9
  ports:
10
+ - 8000:8000
11
  volumes:
12
  - .:/home/user/app
13
  environment:
14
  - PYTHONPATH=/home/user/app
15
+ networks:
16
+ example-network:
17
+ ipv4_address: 172.16.238.10
18
 
19
  # app2:
20
  # build: .
 
41
  # - app2
42
 
43
  prometheus:
44
+ image: prom/prometheus:latest
45
+ restart: unless-stopped
46
  container_name: prometheus
47
+ ports:
48
+ - 9090:9090
49
  volumes:
50
  - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
51
+ networks:
52
+ example-network:
53
+ ipv4_address: 172.16.238.11
54
 
55
  grafana:
56
  image: grafana/grafana
57
  container_name: grafana
58
+ restart: unless-stopped
 
 
 
59
  depends_on:
60
  - prometheus
61
+ ports:
62
+ - 3000:3000
63
+ volumes:
64
+ - ./grafana/provisioning:/etc/grafana/provisioning
65
+ env_file:
66
+ - ./grafana/config.monitoring
67
+ networks:
68
+ example-network:
69
+ ipv4_address: 172.16.238.12
70
 
71
  tests:
72
+ build: .
 
 
73
  volumes:
74
  - .:/home/user/app
75
  environment:
 
77
  depends_on:
78
  - app
79
  command: pytest tests
80
+
81
+ networks:
82
+ example-network:
83
+ name: example-network
84
+ driver: bridge
85
+ ipam:
86
+ driver: default
87
+ config:
88
+ - subnet: 172.16.238.0/24
grafana/provisioning/config.monitoring ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GF_SECURITY_ADMIN_PASSWORD=admin
2
+ GF_USERS_ALLOW_SIGN_UP=false
prometheus/prometheus.yml CHANGED
@@ -2,6 +2,12 @@ global:
2
  scrape_interval: 15s
3
 
4
  scrape_configs:
5
- - job_name: 'sentiment-summarize-youtube-comments'
 
 
 
 
 
 
6
  static_configs:
7
  - targets: ['app:8000']
 
2
  scrape_interval: 15s
3
 
4
  scrape_configs:
5
+ - job_name: 'prometheus'
6
+ scrape_interval: 15s
7
+ metrics_path: /prometheus/metrics
8
+ static_configs:
9
+ - targets: ['localhost:9090']
10
+ - job_name: 'app'
11
+ scrape_interval: 5s
12
  static_configs:
13
  - targets: ['app:8000']