diff --git a/GCP/gcp-app-engine/.gcloudignore b/GCP/gcp-app-engine/.gcloudignore new file mode 100644 index 0000000..06b3946 --- /dev/null +++ b/GCP/gcp-app-engine/.gcloudignore @@ -0,0 +1,37 @@ +# This file specifies files that are _not_ uploaded to Google Cloud + +# using gcloud. It follows the same syntax as .gitignore, with the addition of + +# "#!include" directives (which insert the entries of the given .gitignore-style + +# file at that point). + +# + +# For more information, run: + +# $ gcloud topic gcloudignore + +# + +.gcloudignore + +# If you would like to upload your .git directory, .gitignore file or files + +# from your .gitignore file, remove the corresponding line + +# below: + +.git +.gitignore +Dockerfile +.history +venv + +# Python pycache: + +**pycache**/ + +# Ignored by the build system + +/setup.cfg diff --git a/GCP/gcp-app-engine/README.md b/GCP/gcp-app-engine/README.md new file mode 100644 index 0000000..729d845 --- /dev/null +++ b/GCP/gcp-app-engine/README.md @@ -0,0 +1,69 @@ +# Deploying Flask App on GCP App Engine + + + +This guide will walk you through the steps to deploy a Flask application, like the provided `main.py`, on Google Cloud Platform's App Engine. + +## Prerequisites + +- A Google Cloud Platform account. +- Google Cloud SDK installed on your local machine. + +## Getting Started + +1. **Rename Your Application File:** + Ensure that your Flask application file is named `main.py`. + +2. **App Engine Configuration File:** + Create an `app.yaml` file in the same directory as your `main.py`. This file is used to configure your App Engine environment. + +3. **Update Cloud SDK:** + Run the following command to update all the installed components of the Google Cloud SDK to the latest version: + + ``` + gcloud components update + ``` + +4. **Create a GCP Project:** + If you haven't already, create a new project on Google Cloud Platform. Note down the `PROJECT_ID`. + +5. **Enable App Engine Admin API:** + Enable the App Engine Admin API for your project. This is required for deploying applications. + +6. **Authenticate Your Account:** + Authenticate your GCP account with the following command: + + ``` + gcloud auth login + ``` + +7. **Set Project ID:** + Configure `gcloud` to use your project with the following command: + + ``` + gcloud config set project PROJECT_ID + ``` + + Replace `PROJECT_ID` with your actual GCP project ID. + +8. **Deploy the Application:** + Navigate to your application directory where `main.py` and `app.yaml` are located. Run the following command to deploy your application: + + ``` + gcloud app deploy + ``` + + Follow the on-screen prompts to complete the deployment. + +9. **Access Your Application:** + Once the deployment is successful, you can access your application using the following command: + ``` + gcloud app browse + ``` + +## Additional Information + +- Make sure you are in the correct directory where your `main.py` and `app.yaml` files are located before running the deployment commands. +- For more detailed information and troubleshooting, refer to the [Google Cloud App Engine Documentation](https://cloud.google.com/appengine/docs). + +--- diff --git a/GCP/gcp-app-engine/app.yaml b/GCP/gcp-app-engine/app.yaml new file mode 100644 index 0000000..d558f66 --- /dev/null +++ b/GCP/gcp-app-engine/app.yaml @@ -0,0 +1,5 @@ +runtime: python39 + +handlers: + - url: /.* + script: auto diff --git a/GCP/gcp-app-engine/cover.png b/GCP/gcp-app-engine/cover.png new file mode 100644 index 0000000..31dd709 Binary files /dev/null and b/GCP/gcp-app-engine/cover.png differ diff --git a/GCP/gcp-app-engine/main.py b/GCP/gcp-app-engine/main.py new file mode 100644 index 0000000..487ba75 --- /dev/null +++ b/GCP/gcp-app-engine/main.py @@ -0,0 +1,12 @@ +import os +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World! This is a Flask app running on GCP App Engine.' + +if __name__ == '__main__': + port = int(os.environ.get('PORT', 8080)) + app.run(host='0.0.0.0', port=port, debug=True) diff --git a/GCP/gcp-app-engine/requirements.txt b/GCP/gcp-app-engine/requirements.txt new file mode 100644 index 0000000..e0f2ec9 --- /dev/null +++ b/GCP/gcp-app-engine/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +Werkzeug==2.0.1 \ No newline at end of file diff --git a/GCP/gcp-cloud-run/.dockerignore b/GCP/gcp-cloud-run/.dockerignore new file mode 100644 index 0000000..f216c27 --- /dev/null +++ b/GCP/gcp-cloud-run/.dockerignore @@ -0,0 +1,5 @@ +.history +Dockerfile +.gcloudignore +.gitignore +&.md \ No newline at end of file diff --git a/GCP/gcp-cloud-run/Dockerfile b/GCP/gcp-cloud-run/Dockerfile new file mode 100644 index 0000000..5286d53 --- /dev/null +++ b/GCP/gcp-cloud-run/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.9 + +WORKDIR /usr/src/app + +COPY . . + +RUN pip install --upgrade pip + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 8080 + +CMD ["python3", "./main.py"] \ No newline at end of file diff --git a/GCP/gcp-cloud-run/README.md b/GCP/gcp-cloud-run/README.md new file mode 100644 index 0000000..c24080e --- /dev/null +++ b/GCP/gcp-cloud-run/README.md @@ -0,0 +1,90 @@ +## Deploying Flask App on Google Cloud Run + + + +### Prerequisites + +- A Google Cloud Platform account. +- Google Cloud SDK installed on your local machine. +- Docker installed on your local machine (for building the container image). + +### Steps + +1. **Prepare Your Application:** + + - Ensure your Flask application is in a file named `main.py`. + - Create a `requirements.txt` file in the same directory as your `main.py`, listing all the dependencies. + +2. **Containerize Your Application:** + + - Create a `Dockerfile` in the same directory as your `main.py`. A basic example of a Dockerfile for a Flask application is: + +3. **Build Your Container Image:** + + - Build the Docker image and tag it for uploading: + ``` + docker build -t gcr.io/PROJECT_ID/my-flask-app . + ``` + - Replace `PROJECT_ID` with your actual GCP project ID. + +4. **Push Your Container Image to Container Registry:** + + - Push the image to Google Container Registry: + ``` + docker push gcr.io/PROJECT_ID/my-flask-app + ``` + +5. **Deploy on Cloud Run:** + + - Ensure you have set your GCP project ID: + ``` + gcloud config set project PROJECT_ID + ``` + - Deploy the image to Cloud Run: + ``` + gcloud run deploy --image gcr.io/PROJECT_ID/my-flask-app --platform managed + ``` + - Follow the prompts to specify the service name and region. Allow unauthenticated invocations if needed. + +6. **Access Your Application:** + - Once the deployment is successful, Cloud Run will provide a URL to access your application. + +To remove or delete the deployment of your application from Google Cloud Run, you can follow these steps: + +### Delete the Cloud Run Service + +First, you'll need to delete the specific Cloud Run service where your application is deployed. You can do this using the Google Cloud Console or the `gcloud` command-line tool. + +Using `gcloud`, the command to delete a service is: + +```sh +gcloud run services delete SERVICE_NAME --platform managed +``` + +Replace `SERVICE_NAME` with the name of the service you want to delete. + +This command will prompt you to confirm the deletion. Once confirmed, it will remove the service and stop serving your application. + +### Remove the Container Image + +If you also want to remove the container image from the Google Container Registry, you can do so through the Google Cloud Console or using `gcloud`: + +```sh +gcloud container images delete gcr.io/PROJECT_ID/my-flask-app --force-delete-tags +``` + +Replace `PROJECT_ID` with your actual GCP project ID and `my-flask-app` with the name of your Docker image. + +This command will delete the container image and its tags from your Container Registry. + +### Delete the GCR Repository + +``` +gcloud container images list --repository=gcr.io/PROJECT_ID +``` + +### Notes + +- Make sure you replace `PROJECT_ID` with your actual Google Cloud project ID in the commands. +- The first deployment might take a bit longer as it involves setting up the Cloud Run service. +- For more detailed information, refer to the [Google Cloud Run Documentation](https://cloud.google.com/run/docs). diff --git a/GCP/gcp-cloud-run/cover.png b/GCP/gcp-cloud-run/cover.png new file mode 100644 index 0000000..119dbc4 Binary files /dev/null and b/GCP/gcp-cloud-run/cover.png differ diff --git a/GCP/gcp-cloud-run/main.py b/GCP/gcp-cloud-run/main.py new file mode 100644 index 0000000..e8d9608 --- /dev/null +++ b/GCP/gcp-cloud-run/main.py @@ -0,0 +1,12 @@ +import os +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World! This is a Flask app running on GCP Cloud Run.' + +if __name__ == '__main__': + port = int(os.environ.get('PORT', 8080)) + app.run(host='0.0.0.0', port=port, debug=True) diff --git a/GCP/gcp-cloud-run/requirements.txt b/GCP/gcp-cloud-run/requirements.txt new file mode 100644 index 0000000..e0f2ec9 --- /dev/null +++ b/GCP/gcp-cloud-run/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +Werkzeug==2.0.1 \ No newline at end of file