smart48 / larak8

DigitalOcean Kubernetes Deployment of Laravel App
2 stars 3 forks source link

Git Cloner Fatal: destination path '/code' already exists and is not an empty directory. #13

Closed jasperf closed 3 years ago

jasperf commented 3 years ago

Cloning of the repository

# Laravel Code Download so we can run Horizon without issues 
# and have a codebase to start with For private repo better to add 
# code to laravel image
# initContainers:
  - name: git-cloner
    image: alpine/git
    imagePullPolicy: IfNotPresent
    args:
        - clone
        - --single-branch
        - --
        - https://github.com/smart48/smt-demo
        - /code
    volumeMounts:
    - mountPath: /code
      name: code-storage

fails

kubectl logs -f app-6b8877cdd7-b74hb git-cloner     
fatal: destination path '/code' already exists and is not an empty directory.

When I ssh into the kube I see

$ cd /data/code/
$ ll
-bash: ll: command not found
$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Dec  7 04:50 .
drwxr-xr-x 5 root root 4096 Dec  7 04:50 ..

which is ...odd

jasperf commented 3 years ago

We do have the directory now and no longer try to create the directory , but somehow only index is added so we need to check this some more.

$ pwd
/tmp/hostpath-provisioner/smt-local/code-pv-claim
$ ls -la
total 12
drwxrwxrwx 2 root root 4096 Dec  7 06:57 .
drwxr-xr-x 5 root root 4096 Dec  7 05:02 ..
-rw-r--r-- 1 root root 1823 Dec  7 07:07 index.php
kubectl describe pvc code-pv-claim 
Name:          code-pv-claim
Namespace:     smt-local
StorageClass:  standard
Status:        Bound
Volume:        pvc-006f5c11-d486-407e-84f4-7550c1ef283b
Labels:        type=code
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
               volume.beta.kubernetes.io/storage-provisioner: k8s.io/minikube-hostpath
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      5Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Mounted By:    app-5777b58f95-7g824
               app-5777b58f95-7wnpb
Events:        <none>
jasperf commented 3 years ago

initContainer can only run once as the next time it runs - and this also happens with replicas - it will fail as files are already there. So solution is to only run it once, run it as a regular deployment of a container or clone a different way.