diff --git a/k8s/webshop.yml b/k8s/webshop.yml index e69de29..698c82d 100644 --- a/k8s/webshop.yml +++ b/k8s/webshop.yml @@ -0,0 +1,68 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: webshop + namespace: unstablevortex + labels: + app: webshop +spec: + replicas: 1 + selector: + matchLabels: + app: webshop + strategy: + type: Recreate + template: + metadata: + labels: + app: webshop + spec: + containers: + - name: webshop + image: registry.kmlabz.com/unstablevortex/webshop + imagePullPolicy: Always + ports: + - containerPort: 8080 + imagePullSecrets: + - name: regcred +--- +apiVersion: v1 +kind: Service +metadata: + name: webshop + namespace: unstablevortex + labels: + app: webshop +spec: + ports: + - name: webshop + port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: webshop + type: ClusterIP +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: webshop + namespace: unstablevortex + annotations: + kubernetes.io/ingress.class: "nginx" + cert-manager.io/cluster-issuer: "letsencrypt-prod" + nginx.ingress.kubernetes.io/enable-cors: "true" +spec: + tls: + - hosts: + - unstablevortex.k8s.kmlabz.com + secretName: unstablevortex-cert-secret + rules: + - host: unstablevortex.k8s.kmlabz.com + http: + paths: + - path: / + backend: + serviceName: webshop + servicePort: 80 \ No newline at end of file diff --git a/src/app.py b/src/app.py index bf13371..68b983e 100644 --- a/src/app.py +++ b/src/app.py @@ -5,9 +5,10 @@ import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from healthcheck import HealthCheck +from flask_cors import CORS from utils.config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, POSTGRES_DB, PORT, POSTGRES_HOSTNAME, POSTGRES_PASSWORD, \ - POSTGRES_USERNAME, DEBUG, SECRET_KEY + POSTGRES_USERNAME, DEBUG, SECRET_KEY, ALLOWED_ORIGINS from utils import db, ma, health_database_status, security, user_datastore from views import ItemView, LoginView, ProfileView, RegisterView, UploadView @@ -41,6 +42,7 @@ health = HealthCheck() db.init_app(app) ma.init_app(app) security.init_app(app, user_datastore) +CORS(app, origins=ALLOWED_ORIGINS) formatter = logging.Formatter( fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s" diff --git a/src/utils/config.py b/src/utils/config.py index 97be0c5..5414803 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -25,3 +25,4 @@ POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", "webshop") POSTGRES_DB = os.getenv("POSTGRES_DB", "webshop") SECRET_KEY = os.getenv("SECRET_KEY") +ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')