My docker-compose.yml
looks like:
gitsync:
image: openweb/git-sync:0.0.1
restart: always
command: >
sh -c "ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa &&
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts &&
chmod 600 ~/.ssh/id_rsa &&
chmod 600 ~/.ssh/known_hosts"
environment:
GIT_SYNC_REPO: git@github.com:{company}/{repo_name}.git
GIT_SYNC_DEST: /opt/airflow/dags/my_folder
GIT_SYNC_BRANCH: master
GIT_SYNC_SSH: 1
GIT_SSH_KEY_FILE: ~/.ssh/id_rsa
GIT_SSH_KNOWN_HOSTS_FILE: ~/.ssh/known_hosts
volumes:
- ./database_utils:/database_utils
- ./maintenance:/maintenance
- ./utils:/utils
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
The error that I get is:
2022/02/02 16:29:36 error syncing repo: error running command "git fetch origin master": exit status 128: Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The repository exists because that docker-compose.yml
worked when the content was setup to do it through https
:
gitsync:
image: openweb/git-sync:0.0.1
restart: always
environment:
GIT_SYNC_REPO: https://{user}:{personal-access-token}@github.com/{company}/{repo_name}.git
GIT_SYNC_DEST: /opt/airflow/dags/my_folder
GIT_SYNC_BRANCH: master
volumes:
- ./database_utils:/database_utils
- ./maintenance:/maintenance
- ./utils:/utils
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
I tried to setup the grants to 600 as I read otherwise the key won't be used. Any idea how to fix it?
EDIT: test with dockerfile
I changed docker-compose.yml
to:
gitsync:
image: my-gitsync-image
restart: always
container_name: my-gitsync
build:
context: .
dockerfile: Dockerfile-gitsync
environment:
GIT_SYNC_REPO: git@github.com:{company}/{repo}.git
GIT_SYNC_DEST: /opt/airflow/dags/my_folder
GIT_SYNC_BRANCH: master
GIT_SYNC_SSH: 1
GIT_SSH_KEY_FILE: ~/.ssh/id_rsa
GIT_SSH_KNOWN_HOSTS_FILE: ~/.ssh/known_hosts
And created a Dockerfile-gitsync
as:
FROM openweb/git-sync:0.0.1
RUN ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa
RUN ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
RUN chmod 600 ~/.ssh/id_rsa
RUN chmod 600 ~/.ssh/known_hosts
Now the error is:
2022/02/02 17:53:41 error syncing repo: error running command "git fetch origin master": exit status 128: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
So I guess that know known host is working but ssh key doesn't like it. I tried doing:
RUN ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa -C "my_company@email.com"
But doesn't work neither.