<p>I have a Github repo with 2 branches on it, <code>develop</code> and <code>main</code>. The first is the &quot;test&quot; environment and the other is the &quot;production&quot; 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 :</p>
<ol>
<li>Pull <code>develop</code></li>
<li>Write code and test locally</li>
<li>When everything is fine locally, push on <code>develop</code> (it will automatically deploy on GKE workload <code>app_name_develop</code>)</li>
<li>QA tests on <code>app_name_develop</code></li>
<li>If QA tests passed, we create a pull request to put <code>develop</code> into <code>main</code></li>
<li>Automatically deploy on GKE workload <code>app_name_production</code> (from the <code>main</code> branch)</li>
</ol>
<p>The deployment of the container is defined in <code>Dockerfile</code> and the Kubernetes deployment is defined in <code>kubernetes/app.yaml</code>. Those two files are tracked with Git inside the repo.</p>
<p>The problem here is when we create a pull request to put <code>develop</code> into <code>main</code>, it also take the two files <code>app.yaml</code> and <code>Dockerfile</code> from <code>develop</code> to <code>main</code>. We end up with the settings from <code>develop</code> in <code>main</code>, and it messes the whole thing.</p>
<p>I can't define environment 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 multiple environments without having to manually modify the files after each pull request ?</p>
<p>I don't know if it can hlphere is my Dockerfile :</p>
<pre><code>FROM python:3.8

RUN apt-get update &amp;&amp; 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 [&quot;gunicorn&quot;, &quot;-b&quot;, &quot;:8080&quot;, &quot;main:app&quot;]
</code></pre>
<p>And here is my YAML file to deploy on GKE (actually I took the one advised by GKE when creating automated deployment) :</p>
<pre><code>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
</code></pre>
<p>Thanks a lot for any help you could provide !</p>

FairPluto
<p>You can't ignore some files from a pull request selectively. But there are 2 simple workarounds for this :</p>
<p><strong>First -</strong><br />
Create a new branch from ‘develop’</p>
<p>Replace the non-required files from 'main'</p>
<p>Create pull request from this new branch</p>
<p><strong>Second -</strong><br />
Create a new branch from 'main'</p>
<p>Put changes of required files from 'develop'</p>
<p>Create pull request from this new branch</p>
<p>Any of these methods will work. Which will be easier depends on how many files are to be included / excluded.</p>
<p><strong>Example :</strong><br />
Considering main as target and dev as source</p>
<pre><code>root 
|-- src 
| -- app.py 
|-- .gitignore 
|-- settings.py 
|-- requirements.txt
</code></pre>
<p>Let's say, I would want to ignore the settings.py file from being merged
First move to the target branch (the branch to which you want to merge the changes)</p>
<pre><code>git checkout main
</code></pre>
<p>Then you can use the git checkout command to selective pick the files you want to merge</p>
<pre><code>git checkout dev src/
</code></pre>
<p>This will only merge the files changed inside src/ folder</p>
<pre><code>NOTE: You can also do it selectively for each file. 
</code></pre>
<p>Then push to remote repository</p>
<pre><code>git push origin main
</code></pre>
<p>Bear in mind that this solution is useful only if the files to be excluded are small.</p>
<p><strong>Note:</strong> &quot;There are tools that are built to solve this problem like  skaffold and kustomize, but they might take a bit of time and restructuring of your repository before everything works. So, in the meantime, this is a simple solution which requires manual work but can do while you study and decide which of the more advanced instrumentation is suitable .&quot;</p>
