https://github.com/dnce17/crochet_shop_docker
A crochet shop website deployed using Docker, GCP, and Azure
https://github.com/dnce17/crochet_shop_docker
azure docker gcp sqlite
Last synced: about 2 months ago
JSON representation
A crochet shop website deployed using Docker, GCP, and Azure
- Host: GitHub
- URL: https://github.com/dnce17/crochet_shop_docker
- Owner: dnce17
- Created: 2024-11-17T21:07:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-18T04:46:42.000Z (over 1 year ago)
- Last Synced: 2025-01-22T18:29:25.451Z (over 1 year ago)
- Topics: azure, docker, gcp, sqlite
- Language: HTML
- Homepage: https://crochet-shop-website-1057035447975.us-central1.run.app
- Size: 10.5 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Crochet Shop Web Application
## Description
This Flask-based project is a shop website. The options in the navigation bar are clickable and lead to other pages. I primarily made this project to further practice responsive web design, Flask, and SQL after finishing a [Pokemon Mystery Dungeon Informational Website](https://github.com/dnce17/pkmn_md_site).
## Deployment Note
This web application was originally deployed at [Render](Render.com) in my [crochet_shop_site](https://github.com/dnce17/crochet_shop_site) repo; this repo was made to practice deploying applications with Docker, GCP, and Azure. However, as of 8/17/25, the GCP and Azure demos are no longer active due to expiration of student credits.
## Demo Link
#### NOTE: Uses free tier, so may take a few seconds to 1 minute for the initial load
Render: https://crochet-shop-site.onrender.com/
https://github.com/user-attachments/assets/5581fae1-de47-4963-b3bb-6160cd4d939b
## Features
* Shop page
* displays various items in a grid layout
* has pagination
* items can be added to cart
* Cart page
* cart items can be deleted and item quantity can be adjusted
## Notes While Deploying to GCP and Azure
The Dockerfile uses the below command since the website is ran using gunicorn
```python
CMD ["gunicorn", "-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "-w", "1", "-b", "0.0.0.0:8000", "app:app"]
```
### Issue
Regarding why `-b` and `ip_address:port` (like 0.0.0.0:8000) is needed in the above cmd
* Issue: When running `gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app` (without -b and ip_address:port), the app is not ran on the port specified in...
```python
if __name__ == "__main__":
socketio.run(app, debug=True, host="0.0.0.0", port="5000")
```
NOTE: I had already changed the port to 8000 in socketio.run() for app.py. The issue above is referring to the time I had the port at 5000 and ran into the problem.
### Explanation and Solution
#### Key Points
* socketio.run(app, ...): When calling socketio.run(app, ...) inside the if __name__ == "__main__": block, it starts the built-in Flask development server (not gunicorn) and listens on the specified host and port. In the code above, port=5000 is specified, so the Flask development server would runs on port 5000.
* gunicorn: When gunicorn is run, it completely takes over the web server and does not use the Flask development server. It will start the application on the port specified in gunicorn's command (e.g., with the -b option) or the default port (which is 8000 if not specified).
#### Why It Runs on Port 8000
When specifying the port in socketio.run(app, ...) but then running gunicorn, the Flask development server is never actually used. gunicorn starts a separate process and ignores any port settings in socketio.run(). If port with gunicorn is not specified, it will default to port 8000.
In other words:
* socketio.run(app) only applies when running the Flask app directly (i.e., without gunicorn).
* gunicorn overrides the need for socketio.run() and will start the server based on its own configuration.
Using -b and specifying the port like the below allows you to control which port gunicorn will use
* `-b 0.0.0.0:5000`: This binds gunicorn to port 5000 and listens on all IP addresses (0.0.0.0), which is typically what you want for Docker containers.