From cf30eb0a949b1a7ade3d5ada0e0c03f22269c856 Mon Sep 17 00:00:00 2001 From: Enrico Goerlitz Date: Sat, 15 Jun 2024 09:50:12 +0200 Subject: [PATCH] app updated hostname --- app/app.py | 11 +++++----- docker/push-script.sh | 20 ------------------- .../{ec2-userscript.txt => ec2-userscript.sh} | 0 terraform/main.tf | 17 ++++++++++++++++ 4 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 docker/push-script.sh rename terraform/{ec2-userscript.txt => ec2-userscript.sh} (100%) diff --git a/app/app.py b/app/app.py index 289fb91..b2caf6b 100644 --- a/app/app.py +++ b/app/app.py @@ -1,5 +1,6 @@ +import os + from flask import Flask, jsonify -import socket app = Flask(__name__) @@ -7,18 +8,18 @@ @app.route("/") def healthcheck(): - internal_ip = socket.gethostbyname(socket.gethostname()) + hostname = os.uname()[1] return jsonify({ "healthcheck": "ok", - "internal_ip": internal_ip, + "hostname": hostname, "version": "v2" }) @app.route("/host") def host_ip(): - internal_ip = socket.gethostbyname(socket.gethostname()) - return jsonify({"internal_ip": internal_ip}) + hostname = os.uname()[1] + return jsonify({"hostname": hostname}) if __name__ == "__main__": diff --git a/docker/push-script.sh b/docker/push-script.sh deleted file mode 100644 index adacf49..0000000 --- a/docker/push-script.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Definiere Variablen -DOCKER_USERNAME=your-username -IMAGE_NAME=your-image-name -TAG=latest -DOCKERFILE_PATH=../Dockerfile -BUILD_CONTEXT=../ - -# Baue das Docker-Image mit dem angegebenen Kontext -docker build -t $DOCKER_USERNAME/$IMAGE_NAME -f $DOCKERFILE_PATH $BUILD_CONTEXT - -# Melde dich bei Docker Hub an -docker login - -# Tagge das Docker-Image -docker tag $DOCKER_USERNAME/$IMAGE_NAME $DOCKER_USERNAME/$IMAGE_NAME:$TAG - -# Pushe das Docker-Image zu Docker Hub -docker push $DOCKER_USERNAME/$IMAGE_NAME:$TAG diff --git a/terraform/ec2-userscript.txt b/terraform/ec2-userscript.sh similarity index 100% rename from terraform/ec2-userscript.txt rename to terraform/ec2-userscript.sh diff --git a/terraform/main.tf b/terraform/main.tf index e69de29..7ea18cf 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -0,0 +1,17 @@ +# CREATE SECURITY GROUP +# - name=bp2-hosting-backend +# - allow only http traffic + +# CREATE TARGET GROUP FOR LB +# - name=tg-bp2-hosting-backend + +# CREATE APPLICATION LOAD BALANCER +# - name=lb-bp2-hosting-backend +# - internet facing, IPv4, AZ=1a+b+c + +# CREATE LAUNCH TEMPLATE (EC2 Launch-Template) +# - name, AMI, t2.micro, no keypair, sg = sg-0f38bf63879bf9a9, +# default storage, AND User data = script! + +# CREATE AUTOSCALING GROUP +# - name=asg-bp2-hosting-backend, vpc=default, AZ=eu-central-1a + 1b + 1c \ No newline at end of file