0

I have a Github repo with 2 branches on it, develop and main. The first is the "test" environment and the other is the "production" environment. I am working with Google Kubernetes Engine and I have automated deployment from the push on Github to the deploy on GKE. So our workflow is :

  1. Pull develop
  2. Write code and test locally
  3. When everything is fine locally, push on develop (it will automatically deploy on GKE workload app_name_develop)
  4. QA tests on app_name_develop
  5. If QA tests passed, we create a pull request to put develop into main
  6. Automatically deploy on GKE workload app_name_production (from the main branch)

The deployment of the container is defined in Dockerfile and the Kubernetes deployment is defined in kubernetes/app.yaml. Those two files are tracked with Git inside the repo.

The problem here is when we create a pull request to put develop into main, it also take the two files app.yaml and Dockerfile from develop to main. We end up with the settings from develop in main, and it messes the whole thing.

I can't define env variables in those files because it could end up in the wrong branch. My question is : How can I exclude those files from the pull request ? Or is there any way to manage multiples environment without having to manually modify the files after each pull request ?

I don't know if it can hlphere is my Dockerfile :

FROM python:3.8

RUN apt-get update && apt-get install -y --no-install-recommends

RUN python -m pip install --upgrade pip

WORKDIR /app/

COPY requirements.txt .
RUN python -m pip install -r requirements.txt

COPY . .

EXPOSE 8080
CMD ["gunicorn", "-b", ":8080", "main:app"]

And here is my YAML file to deploy on GKE (actually I took the one advised by GKE when creating automated deployment) :

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app_name-api
  name: app_name-api
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app_name-api
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: app_name-api
    spec:
      containers:
        - image: gcr.io/path_to_image/github.com/company_name/app_name
          imagePullPolicy: IfNotPresent
          name: app_name-1
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  labels:
    app: app_name-api
  name: app_name-api-pod-autoscaler
  namespace: default
spec:
  maxReplicas: 3
  metrics:
    - resource:
        name: cpu
        targetAverageUtilization: 80
      type: Resource
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: app_name-api

Thanks a lot for any help you could provide !

1
  • The way we manage it - is having a directory per environment rather than a branch per environment. Should solve the issues you are facing. – taleodor Jun 2 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.