A docker image designed as a k8 initContainer for git pull on pod initialization. To use it, pass the following environment variables:
GIT_REPO_URL: URL of the Git repository to sync to, for example ssh://[email protected]/foo/bar.git. (required)GIT_REPO_BRANCH: Branch of the Git repository to sync to, for example production (defaults to master).SYNC_DIR: path to pull contents into. Should match your mounted directory path (defaults to /sync-dir).GROUP_ID: (defaults to 999); after clone/pull, the sync dir is chmod'd to 0:$GROUP_IDSSH_PK_ID_FILE: name of private key file. This should be a mounted secret along with a config file at the same location (defaults to appkey). See below.appkey and place it in tmp folder.config file. Replace myappId with the name of your app service account defined above. Replace example.com with bitbucket.org, github.com or other repo where your code resides.Host example.com
IdentityFile /root/.ssh/appkey
User myappId
StrictHostKeyChecking no
kubectl create secret generic ssh-appkey \
--from-file=config=/path/to/config \
--from-file=appkey=/path/to/appkey
volumes:
- name: myapp-api-pvc
persistentVolumeClaim:
claimName: myapp-api-source-code-pvc
- name: sshkey
secret:
secretName: ssh-appkey
defaultMode: 256
initContainers:
- name: git-sync
image: init-git-pull
volumeMounts:
- name: sshkey
mountPath: "/root/.ssh"
- name: myapp-pvc
mountPath: /sync-dir
subPath: api
env:
- name: GIT_REPO_URL
value: ssh://[email protected]/myorg/myapprepo.git
- name: GIT_REPO_BRANCH
value: myworkbranch
containers:
- name: myapp
image: repo/imagename
volumeMounts:
- name: myapp-api-pvc
mountPath: /some/path
subPath: api
Content type
Image
Digest
Size
14.7 MB
Last updated
over 7 years ago
docker pull nflcumd/init-git-pull