diff --git a/.github/workflows/payment-api-deploy.yaml b/.github/workflows/payment-api-deploy.yaml new file mode 100644 index 0000000..f6f3609 --- /dev/null +++ b/.github/workflows/payment-api-deploy.yaml @@ -0,0 +1,52 @@ +name: Deploy payment-api to k8s + +on: + workflow_dispatch: + push: + branches: + - main + + paths: + - .github/workflows/payment-api-deploy.yml + - .github/workflows/composite/deploy/action.yml + - deploy/k8s/payment-service.yaml + - SimpleServer/src/Services/Payment/Payment.API/** + +env: + NAMESPACE: ingress-nginx + +jobs: + deploy-to-k8s: + permissions: + actions: read + # contents: read + id-token: write + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4.1.1 + + # Logs in with your Azure credentials + - name: Azure login + uses: azure/login@v1.4.6 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - uses: ./.github/workflows/composite/deploy + with: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + cluster_name: ${{ secrets.CLUSTER_NAME }} + resource_group: ${{ secrets.RESOURCE_GROUP }} + manifest_path: | + deploy/k8s/postgres-secret.yaml + deploy/k8s/postgres-configmap.yaml + deploy/k8s/postgresql.yaml + deploy/k8s/stripe-secret.yaml + deploy/k8s/payment-service.yaml + registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }} + namespace: ${{ env.NAMESPACE }} + image_name: movie.api + deployment_name: movie-api-deployment + service_name: movie-api-service diff --git a/SimpleServer/src/ApiGateways/Web.Bff.SimpleNetflix/OcelotApiGw/ocelot.Development.json b/SimpleServer/src/ApiGateways/Web.Bff.SimpleNetflix/OcelotApiGw/ocelot.Development.json index f90cd05..a250b33 100644 --- a/SimpleServer/src/ApiGateways/Web.Bff.SimpleNetflix/OcelotApiGw/ocelot.Development.json +++ b/SimpleServer/src/ApiGateways/Web.Bff.SimpleNetflix/OcelotApiGw/ocelot.Development.json @@ -1,7 +1,7 @@ { "Routes": [ { - "DownstreamPathTemplate": "/api/pricingPlans", + "DownstreamPathTemplate": "/api/pricingPlan/{everything}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { @@ -12,7 +12,7 @@ "UpstreamHttpMethod": [ "GET" ], - "UpstreamPathTemplate": "/payment/planform/{everything}", + "UpstreamPathTemplate": "/payment/plan/{everything}", "AuthenticationOptions": { "AuthenticationProviderKey": "IdentityApiKey", "AllowedScopes": [ @@ -105,12 +105,9 @@ "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { - // Uncomment this to use the local api - "Host": "localhost", - "Port": 8000 // Uncomment this to use the docker container - // "Host": "movie.api", - // "Port": 80 + "Host": "movie.api", + "Port": 80 } ], "UpstreamPathTemplate": "/movies", diff --git a/deploy/k8s/apigw.yaml b/deploy/k8s/apigw.yaml index a4a74e9..2968643 100644 --- a/deploy/k8s/apigw.yaml +++ b/deploy/k8s/apigw.yaml @@ -25,7 +25,7 @@ spec: - containerPort: 80 env: - name: IdentityUrl - value: https://frontend.20.211.61.204.nip.io + value: https://netflix-identity.azurewebsites.net - name: ASPNETCORE_ENVIRONMENT value: Production - name: OCELOT_CONFIG_PATH diff --git a/deploy/k8s/ocelot-config.yaml b/deploy/k8s/ocelot-config.yaml index 47464f2..ec39655 100644 --- a/deploy/k8s/ocelot-config.yaml +++ b/deploy/k8s/ocelot-config.yaml @@ -5,39 +5,106 @@ metadata: data: ocelot.Production.json: |- { - "Routes": [ - { - "DownstreamPathTemplate": "/api/movie", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "movie-api-service", - "Port": 80 - } - ], - "UpstreamPathTemplate": "/movies", - "UpstreamHttpMethod": [ - "GET", - "POST", - "PUT" - ], - "AuthenticationOptions": { - "AuthenticationProviderKey": "IdentityApiKey", - "AllowedScopes": [ - "movies" - ] - } - }, - { - "DownstreamPathTemplate": "/", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "identity-grpc-service", - "Port": 80 + "Routes": [ + { + "DownstreamPathTemplate": "/api/pricingPlan/{everything}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "payment-api-service", + "Port": 80 + } + ], + "UpstreamHttpMethod": [ + "GET" + ], + "UpstreamPathTemplate": "/payment/plan/{everything}", + "AuthenticationOptions": { + "AuthenticationProviderKey": "IdentityApiKey", + "AllowedScopes": [ + "payment" + ] } - ], - "UpstreamPathTemplate": "/identity-grpc", - } - ] - } + }, + { + "DownstreamPathTemplate": "/api/pricingPlans", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "payment-api-service", + "Port": 80 + } + ], + "UpstreamHttpMethod": [ + "GET" + ], + "UpstreamPathTemplate": "/payment/planform", + "AuthenticationOptions": { + "AuthenticationProviderKey": "IdentityApiKey", + "AllowedScopes": [ + "payment" + ] + } + }, + { + "DownstreamPathTemplate": "/api/subscription", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "payment-api-service", + "Port": 80 + } + ], + "UpstreamHttpMethod": [ + "POST" + ], + "UpstreamPathTemplate": "/payment/subscriptions", + "AuthenticationOptions": { + "AuthenticationProviderKey": "IdentityApiKey", + "AllowedScopes": [ + "payment" + ] + } + }, + { + "DownstreamPathTemplate": "/api/create-payment-intent", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "payment-api-service", + "Port": 80 + } + ], + "UpstreamHttpMethod": [ + "POST" + ], + "UpstreamPathTemplate": "/payment/checkout", + "AuthenticationOptions": { + "AuthenticationProviderKey": "IdentityApiKey", + "AllowedScopes": [ + "payment" + ] + } + }, + { + "DownstreamPathTemplate": "/subscription/success", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "payment-api-service", + "Port": 80 + } + ], + "UpstreamHttpMethod": [ + "POST" + ], + "UpstreamPathTemplate": "/payment/success", + "AuthenticationOptions": { + "AuthenticationProviderKey": "IdentityApiKey", + "AllowedScopes": [ + "payment" + ] + } + }, + ] + } \ No newline at end of file diff --git a/deploy/k8s/payment-service.yaml b/deploy/k8s/payment-service.yaml new file mode 100644 index 0000000..38ebb23 --- /dev/null +++ b/deploy/k8s/payment-service.yaml @@ -0,0 +1,60 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: payment-api-deployment + namespace: ingress-nginx + labels: + app: payment-api +spec: + replicas: 1 + selector: + matchLabels: + app: payment-api + template: + metadata: + labels: + app: payment-api + spec: + containers: + - name: paymentapi + image: 281901/payment.api:dev + imagePullPolicy: Always + ports: + - containerPort: 80 + env: + - name: IdentityUrl + value: https://netflix-identity.azurewebsites.net + - name: ASPNETCORE_URLS + value: "http://+:50051;http://+:80" + - name: Stripe__SecretKey + valueFrom: + secretKeyRef: + name: stripe-secret + key: secret_key + - name: ConnectionStrings__PaymentDB + valueFrom: + configMapKeyRef: + name: postgres-configmap + key: connection_string + - name: GrpcUrl + value: http://identity-grpc-service:80 + resources: + requests: + memory: "64Mi" + cpu: "0.1" + limits: + memory: "128Mi" + cpu: "0.3" +--- +apiVersion: v1 +kind: Service +metadata: + name: payment-api-service + namespace: ingress-nginx +spec: + type: ClusterIP + selector: + app: payment-api + ports: + - protocol: TCP + port: 80 diff --git a/deploy/k8s/postgres-configmap.yaml b/deploy/k8s/postgres-configmap.yaml index 3fd381e..327f280 100644 --- a/deploy/k8s/postgres-configmap.yaml +++ b/deploy/k8s/postgres-configmap.yaml @@ -4,4 +4,4 @@ metadata: name: postgres-configmap namespace: ingress-nginx data: - connection_string: User ID=postgres;Password=123456;Server=postgres-service ;Port=5432;Database=IdentityDB; \ No newline at end of file + connection_string: User ID=postgres;Password=123456;Server=postgres-service ;Port=5432;Database=PaymentDB; \ No newline at end of file diff --git a/deploy/k8s/stripe-secret.yaml b/deploy/k8s/stripe-secret.yaml new file mode 100644 index 0000000..5d33523 --- /dev/null +++ b/deploy/k8s/stripe-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: stripe-secret + namespace: ingress-nginx +type: Opaque +data: + secret_key: c2tfdGVzdF81MU9CRVhkSGx2V241elZ5MHR6NVhncXB2T1AxQko3emVNanZYS2F5ZEpqYWxHNjRGaTQzMEJlOG4wTGx3Y3ZGRXNqN3BFRWhyRDNLbUEzaHY1T0VzNXUzSTAwWTFjRTg3aWk= \ No newline at end of file