├── Dockerfile ├── start.sh ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM arm32v7/ubuntu:14.04 2 | 3 | RUN apt-get update \ 4 | && apt-get install -y openssh-server bash git vim lighttpd libcgi-pm-perl busybox-syslogd \ 5 | && rm -rf /var/lib/apt/lists/* \ 6 | && rm /etc/update-motd.d/* \ 7 | && addgroup --gid 1000 git \ 8 | && adduser --home /home/git --shell /bin/bash --uid 1000 --gid 1000 --gecos "" --disabled-password git \ 9 | && mkdir /var/run/sshd \ 10 | && /usr/bin/ssh-keygen -A \ 11 | && rm /etc/pam.d/sshd 12 | 13 | ADD start.sh /start.sh 14 | 15 | EXPOSE 22 1234 16 | 17 | CMD ["/start.sh"] 18 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Verifying configuration..." 4 | 5 | if [ "$(stat -c %a%u%g /home/git)" != "70010001000" ]; then 6 | echo "User git does not have valid homedir !" 7 | echo "Dump /home/" 8 | ls -alh /home/ 9 | exit 1 10 | fi 11 | 12 | if [ "$(stat -c %a%u%g /home/git/.ssh)" != "70010001000" ]; then 13 | echo "User git does not have valid ~/.ssh !" 14 | echo "Dump /home/git/" 15 | ls -alh /home/git/ 16 | exit 1 17 | fi 18 | 19 | if [ "$(stat -c %a%u%g /home/git/.ssh/authorized_keys)" != "60010001000" ]; then 20 | echo "User git does not have valid ~/.ssh/authorized_keys !" 21 | echo "Dump ~/.ssh/" 22 | ls -alh /home/git/.ssh/ 23 | exit 1 24 | fi 25 | 26 | if [ ! -e "/pub" ]; then 27 | ln -s /home/git/pub /pub 28 | fi 29 | 30 | echo "Start ssh server" 31 | /usr/sbin/sshd -D 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Tomasz Prus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # qnap-git-server 2 | 3 | Host your own Git repositories on QNAP server 4 | 5 | ## Introduction 6 | 7 | QNAP is a linux-based Network Attached Storage. It has a lot of nice features but there is no option for hosting git repositories by default. Fortunately there is an application named _Container Station_ which allows you to run Docker or LXC images. So it’s pretty easy to extend functions and for example install _GitLab_ to host git repositories (it’s QNAP recommendation). _Gitlab_ is a quite big system and if you need a just simple git server you can use this [qnap-git-server](https://github.com/tomplus/qnap-git-server). 8 | 9 | ## Instalation 10 | 11 | First, you have to prepare a directory which will be attached to Docker. This directory has to contain your ssh public key and it is also a place where your repositories will be stored. 12 | 13 | ``` 14 | $ ssh admin@my-qnap.local 15 | [~] cd /share 16 | [/share] mkdir -p git/.ssh 17 | [/share] mkdir git/pub 18 | [/share] echo “---your public key from ~/.ssh/id_rsa.pub---” > git/.ssh/authorized_keys 19 | [/share] chown 1000:1000 -R git/ 20 | [/share] chmod 700 git/ 21 | [/share] chmod 700 git/.ssh/ 22 | [/share] chmod 600 git/.ssh/authorized_keys 23 | ``` 24 | 25 | Now you can use _Container Station_ to start the image [tpimages/qnap-git-server](https://hub.docker.com/r/tpimages/qnap-git-server/). This image is prepared for arm32v7 only. 26 | You have to mount prepared directory as /home/git and expose port 22 as for example 2222 to connect it from your local network. You can also start it from command line: 27 | 28 | ``` 29 | [~] docker run -d -v /share/git:/home/git -p 2222:22 --rm tpimages/qnap-git-server:latest 30 | ``` 31 | 32 | Now your server is up and running. You can connect to it via SSH to create a bare repository: 33 | 34 | ``` 35 | $ ssh -p 2222 git@my-qnap.local 36 | $ mkdir pub/project.git 37 | $ cd pub/project.git/ 38 | $ git init --bare 39 | Initialized empty Git repository in /home/git/pub/project.git/ 40 | ``` 41 | 42 | and then you can clone the repository 43 | ``` 44 | $ git clone ssh://git@my-qnap.local:2222/pub/project.git 45 | ``` 46 | 47 | 48 | ## Building 49 | 50 | If you want to build you own custom version of this image your can do it simple by docker build command: 51 | 52 | ``` 53 | docker build -t qnap-git-server:my-own-version . 54 | ``` 55 | 56 | 57 | ## Troubleshooting 58 | 59 | Structure of file `git/.ssh/authorized_keys` requires that each key is stored in separate lines. 60 | If you store there only one key, ensure that there are not additional new lines `\n`. 61 | 62 | To check logs from syslogd you can use command `docker exec` to run `syslogd`. It'll start the deamon 63 | syslogd and all logs will be writting to /var/log/messages. 64 | 65 | If you get errors like `exec user process caused "exec format error"` it means that your qnap 66 | has different architecture (eg. amd64) than the prepared image (arm32v7). It this case try to replace 67 | the base image in `Dockerfile` from 68 | ``` 69 | FROM arm32v7/ubuntu:14.04 70 | ``` 71 | to for example: 72 | ``` 73 | FROM amd64/ubuntu:14.04 74 | ``` 75 | and build your own image. 76 | --------------------------------------------------------------------------------