# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START cloudrun_mc_hello_php_nginx_mc]
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: "MC_SERVICE_NAME"
  labels:
    cloud.googleapis.com/location: "REGION"
  annotations:
    run.googleapis.com/launch-stage: BETA
    run.googleapis.com/description: sample tutorial service
    run.googleapis.com/ingress: all
spec:
  template:
    metadata:
      annotations:
        run.googleapis.com/execution-environment: gen2
        # Defines container startup order within multi-container service.
        # Below requires side-car "hellophp" container to spin up before nginx proxy (entrypoint).
        # https://cloud.google.com/run/docs/configuring/containers#container-ordering
        run.googleapis.com/container-dependencies: '{"nginx":["hellophp"]}'
    spec:
      containerConcurrency: 1
      containers:
        - name: nginx
          image: "REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/nginx"
          ports:
            - name: http1
              containerPort: 8080
          resources:
            limits:
              cpu: 500m
              memory: 256M
          startupProbe:
            timeoutSeconds: 240
            periodSeconds: 240
            failureThreshold: 1
            tcpSocket:
              port: 8080
        - name: hellophp
          image: "REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/php"
          env:
            - name: PORT
              value: "9000"
          resources:
            limits:
              cpu: 1000m
              # Explore more how to set memory limits in Cloud Run
              # https://cloud.google.com/run/docs/tips/general#optimize_concurrency
              # https://cloud.google.com/run/docs/configuring/services/memory-limits#optimizing
            memory: 335M
          startupProbe:
            timeoutSeconds: 240
            periodSeconds: 240
            failureThreshold: 1
            tcpSocket:
              port: 9000
# [END cloudrun_mc_hello_php_nginx_mc]
