- Introduction
- Screenshots
- Project Structure
- Flask app
- Django app
- Running docker compose
- Jenkins Pipeline
Name: Annalhq Shaikh Roll No: 13
Containerized both Flask and Django apps using Docker Compose
Docker images:
Click here to view project structure
.
├── docker-compose.yml
├── flask/
│ ├── app.py
│ ├── requirements.txt
│ ├── Dockerfile
│ └── templates/
│ ├── base.html
│ ├── index.html
│ ├── greet_form.html
│ └── greet_result.html
├── django/
│ ├── manage.py
│ ├── requirements.txt
│ ├── Dockerfile
│ ├── myapp/ # Django project directory
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ ├── wsgi.py
│ │ └── asgi.py
│ └── items/ # Django app directory
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── models.py
│ ├── tests.py
│ ├── views.py
│ ├── migrations/
│ └── templates/
│ └── home.html
└── README.md
A simple Flask application with the following features:
- Homepage (
/
): Displays a "Hello, World!" welcome message. - Greeting Form (
/greet
):- Presents a form to input a name and age.
- Accepts POST requests with the form data.
- Performs basic validation (checks if name is provided and age is numeric).
- Displays a greeting message (
Hello, [Name]! You are [Age] years old.
) upon successful submission. - Shows an error message on the form if validation fails.
A basic Django application for managing a list of items:
- Homepage (
/
):- Displays a list of items retrieved from a SQLite database.
- Includes a form to add new items to the list.
- Admin Panel (
/admin/
):- Provides the standard Django admin interface.
- Allows authenticated users (superuser) to Create, Read, Update, and Delete (CRUD) items. (Note: You'll need to create a superuser first).
- Prerequisites: Make sure you have Docker and Docker Compose installed on your system.
- Build and Run: Navigate to the root directory containing the
docker-compose.yml
file and run:This command will build the Docker images for both the Flask and Django applications (if they don't exist) and start the containers.docker-compose up --build
- Accessing the Apps:
- Flask App: Open web browser and go to
http://localhost:5000
- Django App: Open web browser and go to
http://localhost:8000
- Flask App: Open web browser and go to
- Django Admin:
- To access the Django admin panel at
http://localhost:8000/admin/
, we first need to create a superuser. Open another terminal, navigate to the project root, and run:docker-compose exec django-app python manage.py createsuperuser
- Follow the prompts to create your admin user.
- Now we can log in to the admin panel using the credentials you just created.
- To access the Django admin panel at
- Stopping the Applications: Press
Ctrl + C
in the terminal wheredocker-compose up
is running. To remove the containers, run:docker-compose down
Key Features:
- Environment Variables: Defines Docker registry and image names
- Parameters: Allows selecting deployment environment and toggling tests and image pushing
- Parallel Execution: Runs lint and test stages in parallel for both applications
- Conditional Execution: Only runs tests and pushes images when specified
- Security: Uses Jenkins credentials for Docker registry authentication
- Environment-specific Deployment: Creates environment-specific overrides for docker-compose
- Production Safeguard: Requires manual approval for production deployments
- Cleanup: Ensures workspace is cleaned after pipeline execution