commit 74fafa196074e1f0a39d0ce7d93def2fdcb894ea Author: Charlyne Wargnier-Potier Date: Wed Mar 19 06:32:59 2025 +0000 Add file.sh for docker diff --git a/z1/prepare-app.sh b/z1/prepare-app.sh new file mode 100644 index 0000000..d0a4a40 --- /dev/null +++ b/z1/prepare-app.sh @@ -0,0 +1,13 @@ +#!/bin/bash +echo "Preparing app" + +# Create the Docker volume if it doesn't exist +docker volume create pgdata + +# Create the custom Docker network +docker network create app_net 2>/dev/null || echo "Network app_net already exists." + +# Build the Flask application image from the Dockerfile in the ./app folder. +docker build -t flask_app_image ./app + +echo "Prepa completed." diff --git a/z1/remove-app.sh b/z1/remove-app.sh new file mode 100644 index 0000000..18ea314 --- /dev/null +++ b/z1/remove-app.sh @@ -0,0 +1,12 @@ +#!/bin/bash +echo "Removing app" + +# Remove the containers forcefully. +docker rm -f flask_app postgres_db + +# Remove the custom network and volume if they exist. +docker network rm app_net 2>/dev/null || echo "Network app_net already removed." +docker volume rm pgdata 2>/dev/null || echo "Volume pgdata already removed." + +echo "Application removed." + diff --git a/z1/start-app.sh b/z1/start-app.sh new file mode 100644 index 0000000..333c3e6 --- /dev/null +++ b/z1/start-app.sh @@ -0,0 +1,28 @@ +#!/bin/bash +echo "Starting app" + +# Run PostgreSQL container +docker run -d --name postgres_db \ + --network app_net \ + -e POSTGRES_USER=user \ + -e POSTGRES_PASSWORD=password \ + -e POSTGRES_DB=sampledb \ + -v pgdata:/var/lib/postgresql/data \ + --restart always \ + postgres:13 +# Wait a few seconds to ensure PostgreSQL starts before the Flask app connects. +sleep 10 + +# Run Flask application container +docker run -d --name flask_app \ + --network app_net \ + -p 5000:5000 \ + --restart always \ + -e DB_HOST=postgres_db \ + -e POSTGRES_USER=user \ + -e POSTGRES_PASSWORD=password \ + -e POSTGRES_DB=sampledb \ + flask_app_image + +echo "The application is available at http://localhost:5000" + diff --git a/z1/stop-app.sh b/z1/stop-app.sh new file mode 100644 index 0000000..7ee60a8 --- /dev/null +++ b/z1/stop-app.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "Stopping app" + +docker stop flask_app postgres_db + +echo "Application stopped." +~