WIP: working on db initial create #3
14
Dockerfile
14
Dockerfile
@@ -17,7 +17,9 @@ RUN mkdir -p /app/instance/data
|
|||||||
COPY app.py /app
|
COPY app.py /app
|
||||||
COPY requirements.txt /app
|
COPY requirements.txt /app
|
||||||
COPY models.py /app
|
COPY models.py /app
|
||||||
COPY init_db.py /app/init_db.py
|
COPY entrypoint.sh /app
|
||||||
|
COPY init_db.py /app
|
||||||
|
|
||||||
|
|
||||||
# Install any needed packages specified in requirements.txt
|
# Install any needed packages specified in requirements.txt
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
@@ -26,6 +28,7 @@ RUN apk del .build-deps
|
|||||||
|
|
||||||
# ---- Production Stage ----
|
# ---- Production Stage ----
|
||||||
FROM python:3.8-alpine3.18 as production
|
FROM python:3.8-alpine3.18 as production
|
||||||
|
RUN apk add --upgrade --no-cache bash
|
||||||
|
|
||||||
# Create a user to run our application
|
# Create a user to run our application
|
||||||
RUN adduser -D myuser -u 1000
|
RUN adduser -D myuser -u 1000
|
||||||
@@ -35,10 +38,19 @@ WORKDIR /app
|
|||||||
COPY --from=builder /app /app
|
COPY --from=builder /app /app
|
||||||
COPY --from=builder /usr/local /usr/local
|
COPY --from=builder /usr/local /usr/local
|
||||||
COPY --from=builder /usr/bin /usr/bin
|
COPY --from=builder /usr/bin /usr/bin
|
||||||
|
|
||||||
RUN chown -R myuser:myuser /app
|
RUN chown -R myuser:myuser /app
|
||||||
|
# Set script to be executable
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
# Switch to the created user
|
# Switch to the created user
|
||||||
USER myuser
|
USER myuser
|
||||||
|
|
||||||
|
RUN ls -l /app
|
||||||
|
RUN ls -l /
|
||||||
|
|
||||||
|
# Set the script as the entrypoint
|
||||||
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
|
|
||||||
# Start gunicorn with the appropriate options
|
# Start gunicorn with the appropriate options
|
||||||
CMD ["gunicorn", "-b", "0.0.0.0:3000", "--log-level=debug", "--workers=3", "app:app"]
|
CMD ["gunicorn", "-b", "0.0.0.0:3000", "--log-level=debug", "--workers=3", "app:app"]
|
||||||
|
|||||||
36
app.py
36
app.py
@@ -41,14 +41,15 @@ class WebPushService():
|
|||||||
db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:////app/instance/data/webpush.db')
|
db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:////app/instance/data/webpush.db')
|
||||||
# This relative path works in docker-compose
|
# This relative path works in docker-compose
|
||||||
#db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///data/webpush.db')
|
#db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///data/webpush.db')
|
||||||
self.app.config['SQLALCHEMY_DATABASE_URI'] = db_uri
|
# self.app.config['SQLALCHEMY_DATABASE_URI'] = db_uri
|
||||||
|
|
||||||
# Initializing the database with the application
|
# Initializing the database with the application
|
||||||
db.init_app(self.app)
|
# db.init_app(self.app)
|
||||||
|
# db.create_all()
|
||||||
|
|
||||||
# Creating a context for the application and initializing services
|
# Creating a context for the application and initializing services
|
||||||
with self.app.app_context():
|
# with self.app.app_context():
|
||||||
self._initialize()
|
# self._initialize()
|
||||||
|
|
||||||
# Creating and starting a thread to send daily notifications
|
# Creating and starting a thread to send daily notifications
|
||||||
self.daily_notification_thread = threading.Thread(target=self._send_daily_notifications)
|
self.daily_notification_thread = threading.Thread(target=self._send_daily_notifications)
|
||||||
@@ -109,6 +110,7 @@ class WebPushService():
|
|||||||
to web clients, hence the check and generation if they don't exist.
|
to web clients, hence the check and generation if they don't exist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
pass
|
||||||
# Checking if there are any VAPID keys in the database
|
# Checking if there are any VAPID keys in the database
|
||||||
if not VAPIDKey.query.first():
|
if not VAPIDKey.query.first():
|
||||||
|
|
||||||
@@ -170,26 +172,26 @@ class WebPushService():
|
|||||||
|
|
||||||
# Creating a context for the application to enable database operations
|
# Creating a context for the application to enable database operations
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
|
pass
|
||||||
# Retrieving all subscription data from the database
|
# Retrieving all subscription data from the database
|
||||||
all_subscriptions = Subscription.query.all()
|
#all_subscriptions = Subscription.query.all()
|
||||||
|
|
||||||
# Retrieving the VAPID key from the database
|
# Retrieving the VAPID key from the database
|
||||||
vapid_key = VAPIDKey.query.first()
|
#vapid_key = VAPIDKey.query.first()
|
||||||
|
|
||||||
# Constructing the push notification message
|
# Constructing the push notification message
|
||||||
message = {"title": "Daily Update", "message": "Here's your daily update!"}
|
#message = {"title": "Daily Update", "message": "Here's your daily update!"}
|
||||||
|
|
||||||
# Sending a push notification to each subscribed client
|
# Sending a push notification to each subscribed client
|
||||||
for subscription in all_subscriptions:
|
# for subscription in all_subscriptions:
|
||||||
subscription_info = {
|
# subscription_info = {
|
||||||
"endpoint": subscription.endpoint,
|
# "endpoint": subscription.endpoint,
|
||||||
"keys": {
|
# "keys": {
|
||||||
"p256dh": subscription.p256dh,
|
# "p256dh": subscription.p256dh,
|
||||||
"auth": subscription.auth
|
# "auth": subscription.auth
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
WebPushService._send_push_notification(subscription_info, message, vapid_key)
|
# WebPushService._send_push_notification(subscription_info, message, vapid_key)
|
||||||
|
|
||||||
# Sleeping for 24 hours before sending the next set of notifications
|
# Sleeping for 24 hours before sending the next set of notifications
|
||||||
time.sleep(24 * 60 * 60)
|
time.sleep(24 * 60 * 60)
|
||||||
|
|||||||
9
entrypoint.sh
Normal file
9
entrypoint.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Set the desired permissions
|
||||||
|
#chown -R 1000:1000 /app/instance/data
|
||||||
|
|
||||||
|
echo "Hello World"
|
||||||
|
|
||||||
|
# Execute the command provided as arguments to this script
|
||||||
|
#exec "$@"
|
||||||
Reference in New Issue
Block a user