proiect2
This commit is contained in:
13
project2/Dockerfile
Normal file
13
project2/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY quotes.py .
|
||||||
|
|
||||||
|
# Defines o varianta de baza
|
||||||
|
ENV QUOTE_API_URL="https://api.quotable.io/random"
|
||||||
|
|
||||||
|
CMD ["python", "quotes.py"]
|
||||||
22
project2/famousquotes.py
Normal file
22
project2/famousquotes.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# URL-ul API-ului poate fi setat prin variabila de mediu QUOTE_API_URL, altfel se folosește valoarea implicită
|
||||||
|
API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random")
|
||||||
|
|
||||||
|
def get_quote():
|
||||||
|
try:
|
||||||
|
response = requests.get(API_URL, timeout=10)
|
||||||
|
response.raise_for_status() # Aruncă eroare dacă statusul nu e 200
|
||||||
|
data = response.json()
|
||||||
|
print("-" * 30)
|
||||||
|
print(f"CITAT: {data['content']}")
|
||||||
|
print(f"AUTOR: {data['author']}")
|
||||||
|
print("-" * 30)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Eroare la apelarea API-ului: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
get_quote()
|
||||||
49
project2/jenkinsfile
Normal file
49
project2/jenkinsfile
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Lint Check') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "Verificăm sintaxa Python..."
|
||||||
|
sh 'docker run --rm python:3.9-slim python -m py_compile project2/quotes.py'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
sh 'cd project2 && docker build -t quotes-app .'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Run & Test API') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "Rulăm aplicația și verificăm conexiunea API..."
|
||||||
|
// Pornim containerul și îi pasăm URL-ul API-ului ca variabilă de mediu
|
||||||
|
sh 'docker run --rm -e QUOTE_API_URL="https://api.quotable.io/random" quotes-app'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
failure {
|
||||||
|
script {
|
||||||
|
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa"
|
||||||
|
def payload = """
|
||||||
|
{
|
||||||
|
"content": "❌ **FAILED: Quotes App**\\nEtapa a eșuat la build-ul #${env.BUILD_NUMBER}. Verifica codul Python!"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
sh "curl -H 'Content-Type: application/json' -d '${payload}' ${discordUrl}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
success {
|
||||||
|
echo "Proiectul 2 a fost build-uit cu succes!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
project2/requirements.txt
Normal file
1
project2/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
requests==2.31.0
|
||||||
Reference in New Issue
Block a user