This repository contains a simple Flask "Hello World" application, Dockerized and deployed on DigitalOcean using Terraform.
This repository demonstrates how to containerize a basic Flask application using Docker and deploy it to a DigitalOcean Droplet using Terraform.
- DigitalOcean Account: Ensure you have a DigitalOcean account.
- DigitalOcean API Token: Generate a Personal Access Token from DigitalOcean.
- Terraform: Install Terraform.
- Docker: Install Docker.
- SSH Key: Ensure you have an SSH key added to your DigitalOcean account.
The Flask app is defined in app/app.py
. This simple application responds with "Hello, World!" when accessed.
-
Log in to Docker Hub:
docker login
-
Build the Docker image:
docker build -t yourdockerhubusername/flask-hello-world:latest app/
-
Push the Docker image to Docker Hub:
docker push yourdockerhubusername/flask-hello-world:latest
The Terraform configuration files are located in the terraform/
directory. These files will help you create and manage your DigitalOcean Droplet.
Update the following variables in terraform/terraform.tfvars
:
digitalocean_token
: Your DigitalOcean API token.ssh_fingerprint
: The fingerprint of your SSH key.private_key_path
: The path to your private SSH key.
-
Initialize Terraform:
terraform init
-
Apply the Terraform configuration:
terraform apply
Confirm the action by typing
yes
when prompted.
After the Terraform apply process completes, it will output the IP address of your DigitalOcean Droplet. You can access your Flask app by navigating to http://<droplet-ip>
in your web browser.
This setup provides a simple Flask "Hello World" application, containerized using Docker, and deployed to a DigitalOcean Droplet using Terraform. Ensure to replace placeholders like yourdockerhubusername
, your_digitalocean_api_token
, and your_ssh_key_fingerprint
with your actual values.