Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #6

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
44 changes: 44 additions & 0 deletions .github/workflows/ci_test_api_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test API Service

on:
push:
branches:
- main
pull_request:
branches:
- "*"

jobs:
test_api_service:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build and run Docker Compose
run: |
docker-compose build
docker-compose up -d

- name: Wait for API to start
run: sleep 10

- name: Test Quote Disp Health
run: |
status=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:5001/health)
if [[ "$status" -ne 200 ]]; then
echo "API endpoint returned $status"
exit 1
fi

- name: Test Quote Gen Health
run: |
status=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:5000/health)
if [[ "$status" -ne 200 ]]; then
echo "API endpoint returned $status"
exit 1
fi

- name: Stop Docker Compose
run: docker-compose down
23 changes: 23 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.7"
services:
web1:
build: ./quote_gen
deploy:
replicas: 1
ports:
- "5000:5000"
restart: always
volumes:
- ./quote_gen:/app:rw

web2:
build: ./quote_disp
deploy:
replicas: 1
ports:
- "5001:5001"
restart: always
volumes:
- ./quote_disp:/app:rw
depends_on:
- web1
6 changes: 6 additions & 0 deletions quote_disp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.8-slim-buster
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
14 changes: 11 additions & 3 deletions quote_disp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@app.route("/health")
def health():
return "healthy"
return "healthy time"


@app.route("/")
Expand All @@ -18,8 +18,16 @@ def home():

@app.route("/get_quote")
def quote():
quote = requests.get("http://gen:5000/quote").text
print("quote - ", quote)
hosts = [
"http://week2-devops-web1-1:5000/quote",
"http://week2-devops-web1-2:5000/quote"
]
quote = "Quote Service is unavailable"
for host in hosts:
r = requests.get(host)
if r.status_code ==200:
quote = r.text
break

return render_template("quote.html", quote=quote)

Expand Down
6 changes: 6 additions & 0 deletions quote_gen/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.8-slim-buster
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]