Skip to content

How to Prevent .env and upload from Being Deleted During git-sync (Similar to .gitignore) #937

@1ocate

Description

@1ocate

The issue is that after git-sync successfully completes, all untracked files are deleted, including the external file links and .env file connections. However, recreating the links after syncing feels a bit odd, as the file connections are lost during the sync process.

How can this be solved? Should I recreate the symbolic links immediately after the sync finishes?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
        - name: example
          image: docker.redgistry.kr/example:latest
          imagePullPolicy: Always
          volumeMounts:
          - name: web-source
            mountPath: /var/www/html
          - name: storage
            mountPath: /var/www/html/upload
          - name: htaccess
            mountPath: /var/www/html/.htaccess
            subPath: .htaccess
          - name: config
            mountPath: /var/www/html/.env
            subPath: .env
          command: ["/bin/sh", "-c"]
          args:
            - |
              chown -R root:www-data /var/www/html/upload && \
              chmod -R 775 /var/www/html/upload && \
              ln -s /var/www/html/.env /var/www/html/web/.env && \
              ln -s /var/www/html/.htaccess /var/www/html/web/.htaccess && \
              ln -s /var/www/html/upload /var/www/html/web/upload && \
              apache2-foreground
          ports:
            - containerPort: 80
          env:
          - name: TZ
            value: Asia/Seoul
        - name: git-sync
          image: registry.k8s.io/git-sync/git-sync:v4.0.0
          securityContext:
            runAsUser: 1000
            runAsGroup: 1000
          args:
            - "--repo=https://$(GIT_USERNAME):$(GIT_TOKEN)@github.com/redgistry-kr/example.git"
            - "--branch=$(BRANCH)"
            - "--root=/git"
            - "--dest=web"
            - "--one-time=false"
            - "--period=60s"
            - "--wait=60"
          env:
            - name: BRANCH
              value: branch
            - name: GIT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: git-credentials
                  key: GIT_USERNAME
            - name: GIT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: git-credentials
                  key: GIT_TOKEN
          volumeMounts:
            - name: web-source
              mountPath: /git
      imagePullSecrets:
        - name: redgistry-registry-secret
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: web-pvc
        - name: htaccess
          configMap:
            name: htaccess
        - name: config
          configMap:
            name: web-env
        - name: web-source
          emptyDir: {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions