From 4eedec5b49eb6c7b8ff88795ab2964ac76e2f40a Mon Sep 17 00:00:00 2001 From: Abdul Aziz Khan Date: Wed, 21 Jun 2023 04:57:17 +0500 Subject: [PATCH 01/13] v1 --- docker-compose.yaml | 20 ++++++++++++++++++++ quote_disp/Dockerfile | 6 ++++++ quote_gen/Dockerfile | 6 ++++++ 3 files changed, 32 insertions(+) create mode 100644 docker-compose.yaml create mode 100644 quote_disp/Dockerfile create mode 100644 quote_gen/Dockerfile diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..d1f9908 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,20 @@ +version: "3.7" +services: + web1: + build: ./quote_gen + ports: + - "5000:5000" + deploy: + mode: replicated + replicas: 2 + web2: + build: ./quote_disp + expose: + - "5000" + ports: + - "5001:5000" + depends_on: + - web1 + deploy: + mode: replicated + replicas: 2 \ No newline at end of file diff --git a/quote_disp/Dockerfile b/quote_disp/Dockerfile new file mode 100644 index 0000000..db26812 --- /dev/null +++ b/quote_disp/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/quote_gen/Dockerfile b/quote_gen/Dockerfile new file mode 100644 index 0000000..db26812 --- /dev/null +++ b/quote_gen/Dockerfile @@ -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" ] \ No newline at end of file From 29572d7eafdc2fc4404cb8bf45e22a6a6565d7c9 Mon Sep 17 00:00:00 2001 From: aazizk Date: Fri, 23 Jun 2023 05:39:42 +0500 Subject: [PATCH 02/13] workflows --- .github/workflows/ci_test_api_service.yml | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/ci_test_api_service.yml diff --git a/.github/workflows/ci_test_api_service.yml b/.github/workflows/ci_test_api_service.yml new file mode 100644 index 0000000..07bc7c6 --- /dev/null +++ b/.github/workflows/ci_test_api_service.yml @@ -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 From 4bcefc8f7dd2c78e9e09703a779813919423a840 Mon Sep 17 00:00:00 2001 From: aazizk Date: Fri, 23 Jun 2023 06:04:50 +0500 Subject: [PATCH 03/13] 1 --- docker-compose.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index d1f9908..d0ab4b8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,7 +14,4 @@ services: ports: - "5001:5000" depends_on: - - web1 - deploy: - mode: replicated - replicas: 2 \ No newline at end of file + - web1 \ No newline at end of file From 37a663b206fad23b6454ed543f91b89c4bfb81cf Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 00:20:57 +0500 Subject: [PATCH 04/13] change quote --- quote_disp/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quote_disp/app.py b/quote_disp/app.py index 18b3844..b52dab3 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -18,7 +18,7 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://gen:5000/quote").text + quote = requests.get("http://localhost:5000").text print("quote - ", quote) return render_template("quote.html", quote=quote) From 38d3ed85ab71721ed71757d905631ce8e7630634 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 03:01:11 +0500 Subject: [PATCH 05/13] service name added --- quote_disp/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quote_disp/app.py b/quote_disp/app.py index b52dab3..e539d50 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -18,7 +18,7 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://localhost:5000").text + quote = requests.get("http://quote-gen-service:5000").text print("quote - ", quote) return render_template("quote.html", quote=quote) From 4a27f3ce0ce4e4e482c3316d7e16fd2afa0261c3 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 03:06:05 +0500 Subject: [PATCH 06/13] 1 --- quote_disp/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quote_disp/app.py b/quote_disp/app.py index e539d50..0422197 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -18,7 +18,7 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://quote-gen-service:5000").text + quote = requests.get("http://quote-gen-service:5000/quote").text print("quote - ", quote) return render_template("quote.html", quote=quote) From d9e3fc54e4636cd9be1aee1312673b7422aa5dc0 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 03:26:11 +0500 Subject: [PATCH 07/13] 1 --- quote_disp/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quote_disp/app.py b/quote_disp/app.py index 0422197..ce69477 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -18,7 +18,7 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://quote-gen-service:5000/quote").text + quote = requests.get("http://quote-gen-container:5000/quote").text print("quote - ", quote) return render_template("quote.html", quote=quote) From 2fd8734350de6e1a238e877c3c570131e3e7d630 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 03:41:52 +0500 Subject: [PATCH 08/13] docker compose updated --- docker-compose.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index d0ab4b8..f9fb3cf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,14 +4,11 @@ services: build: ./quote_gen ports: - "5000:5000" - deploy: - mode: replicated - replicas: 2 web2: build: ./quote_disp expose: - "5000" ports: - - "5001:5000" + - "5001:5001" depends_on: - web1 \ No newline at end of file From 07bad4c014494d460b2b63250c50eb5c3d32dad8 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 04:40:32 +0500 Subject: [PATCH 09/13] restart added --- docker-compose.yaml | 14 ++++++++++---- quote_disp/app.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index f9fb3cf..908ba4e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,13 +2,19 @@ version: "3.7" services: web1: build: ./quote_gen + deploy: + replicas: 2 ports: - - "5000:5000" + - "5001-5002:5000" + restart: always + volumes: + - ./quote_gen:/app web2: build: ./quote_disp - expose: - - "5000" ports: - - "5001:5001" + - "6001:5001" + restart: always + volumes: + - ./quote_disp:/app depends_on: - web1 \ No newline at end of file diff --git a/quote_disp/app.py b/quote_disp/app.py index ce69477..3731346 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -18,7 +18,7 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://quote-gen-container:5000/quote").text + quote = requests.get("http://week2-devops-web1-1:5000/quote").text print("quote - ", quote) return render_template("quote.html", quote=quote) From 5bd82e5d2911b49883aab1e46ca6d4c7bd28b824 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 05:18:03 +0500 Subject: [PATCH 10/13] 1 --- docker-compose.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 908ba4e..2c4c17f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,15 +6,12 @@ services: replicas: 2 ports: - "5001-5002:5000" - restart: always - volumes: - - ./quote_gen:/app web2: build: ./quote_disp + deploy: + replicas: 2 ports: - - "6001:5001" + - "6001-6002:5001" restart: always - volumes: - - ./quote_disp:/app depends_on: - - web1 \ No newline at end of file + - web1 From fe6d2ad6fcafb36efccc44ffaa1a230190d23c7e Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 06:34:01 +0500 Subject: [PATCH 11/13] 1 --- quote_disp/app.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/quote_disp/app.py b/quote_disp/app.py index 3731346..4d2b8a0 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -8,7 +8,7 @@ @app.route("/health") def health(): - return "healthy" + return "healthy byte" @app.route("/") @@ -18,8 +18,16 @@ def home(): @app.route("/get_quote") def quote(): - quote = requests.get("http://week2-devops-web1-1: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) From 6750a4cbe52e2f0a040208a90d92082a649b9b69 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 06:45:36 +0500 Subject: [PATCH 12/13] i --- docker-compose.yaml | 8 ++++---- quote_disp/app.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 2c4c17f..9dc8067 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,15 +3,15 @@ services: web1: build: ./quote_gen deploy: - replicas: 2 + replicas: 1 ports: - - "5001-5002:5000" + - "5000:5000" web2: build: ./quote_disp deploy: - replicas: 2 + replicas: 1 ports: - - "6001-6002:5001" + - "5001:5001" restart: always depends_on: - web1 diff --git a/quote_disp/app.py b/quote_disp/app.py index 4d2b8a0..02af0cc 100644 --- a/quote_disp/app.py +++ b/quote_disp/app.py @@ -8,7 +8,7 @@ @app.route("/health") def health(): - return "healthy byte" + return "healthy time" @app.route("/") @@ -24,7 +24,7 @@ def quote(): ] quote = "Quote Service is unavailable" for host in hosts: - r = requests.get[host] + r = requests.get(host) if r.status_code ==200: quote = r.text break From 1215d79fd17d997e2820661f6022590706a815e9 Mon Sep 17 00:00:00 2001 From: aazizk Date: Sun, 25 Jun 2023 06:59:20 +0500 Subject: [PATCH 13/13] volumes added --- docker-compose.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 9dc8067..579e82e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,6 +6,10 @@ services: replicas: 1 ports: - "5000:5000" + restart: always + volumes: + - ./quote_gen:/app:rw + web2: build: ./quote_disp deploy: @@ -13,5 +17,7 @@ services: ports: - "5001:5001" restart: always + volumes: + - ./quote_disp:/app:rw depends_on: - web1