Skip to content

Commit a325ed8

Browse files
committed
Major improvements
* update to the latest alpine version * support independant git account name from git-server repository location * update documentation
1 parent 72f69a5 commit a325ed8

11 files changed

+226
-99
lines changed

.gitignore

-5
This file was deleted.

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sudo: required
2+
3+
env:
4+
global:
5+
- secure: tiAuLlmIpPpapn2Nt9fk2Ykm9rY0c0MIADBhea+Zf8gJK5zRJAE0tbmD9Ub84lTQ8ItUJbCWRB2Fa2lWP4eEzB8iG06rbfa9bbEo05dvzRTlXs61wpSk5gGyxfVhmhegt47vQCe0bMnzb+Ywc64nkYBhJgfDl78GgdzJFRLS7UwumnnZxEPNC7eGn6QcZCr8VZHPsEeB2hk5d6gq4Qiv9bG86UwQGjkP0qU0rPG39B6dtLbb53BsgTHZtLlED11sZco941cyLJ/HaSgcSaKp2Ufl+Mn+H5kYerpLY3vTGxwpU6/94/fgE7ht2dWzTWNoOV3F1Q0rUApSkI94d7G9uRzRcIOnY1Fa6+ZsxjzrStc6WmVmw6LPs1fIvwbHmuckegYX5XvefCWAlRm7Ih15PG5OWN4nXT0czpRe1Yh+upb8pnAjczZQj2hde4VV5xFh7P2PqUxxY2BQPzuIEJKwtbUFBBof3TOwG6DFUbcUjmh4QRz8y+P/1vLelXtbFiEw2ylXlmzFXSeeAfI/R18Kv92EO29D9a+aSU1mi+GTcWigbDFxjrliZqeyxyZZzd61Qt28r0UHhl5iYCrzpZkwdcKggR1J/64uuCkzISKH0wzIOTl+IBM7+XNUuNz9E2lg1XdGJ4a40dmmfv1N7DL/ht0D/zTf+JM+dFXN5HEQJLQ=
6+
- secure: bltFDyxC7dT064zMqiaghvRaLefw6QR8+H+roS6bn17ZQ1fMID4I4DBU2cgUMXwk9kYHhhYV9LjHNOG+rcRIHe3BiD2HLsmtkCQbCtOu7NCoeUmjQazwVBIwfXpZL14sV0TF7PoQo4RY/1/AMZFLyWAuPeRG9LEtEPUsU7y8g5/JqGLamH1iBLj7615xKFuWN0xAyJkNQhbTKqsirnEkh41AUswk3LHInFnyxfbtGB7KjpiFVOrcTpeMmzJJ6vp2ySHb6hxH6R3D31AhHqG/I/vnxWvzt7wFv+zJ5iUq5mIIOcN0xeYpw2Mh8TrZqmEezBpfH3Z0n8H7zB/imeRsY5hgbQct5mRR3mQsUEq/VJr2sE2fVhwMugIx3kJUf5Htmm3woGgoEAmKdg7xyp75PQloWDLQv8h5vfegedMlI6wyoVo86KL0koLHooyMtHU9Bi4fpjfLqwWXoHnlZ2ESqgRGJATmF83sKoWv8v4I6RZXKOaP75BwmeoYKZE47iv3qFEnHZDHnFyCDFQ2NfjK1KEMQh4StzhRDzWcYIhonxxKXkG9yXLTnKScEGDR7qt/YV55p/xxyn9zBvNHrruAxTEFmMl/L/lorhhfDNqVcqyI6FjmwmK3sreq1I/KiuP1iB66Pm7CezCNdhxndwLl7cuc3603Elr9BPm47jqkH0E=
7+
8+
services:
9+
- docker
10+
11+
addons:
12+
apt:
13+
update: true
14+
15+
script:
16+
- make build
17+
18+
after_success:
19+
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
20+
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then make
21+
release; fi

Dockerfile

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
FROM alpine:3.4
1+
FROM alpine:latest
22

3-
MAINTAINER Carlos Bernárdez "[email protected]"
3+
LABEL Maintainer="Frank Ittermann [email protected]"
44

5-
# "--no-cache" is new in Alpine 3.3 and it avoid using
6-
# "--update + rm -rf /var/cache/apk/*" (to remove cache)
7-
RUN apk add --no-cache \
8-
# openssh=7.2_p2-r1 \
5+
RUN apk update && \
6+
apk add --no-cache \
97
openssh \
10-
# git=2.8.3-r0
118
git
129

13-
# Key generation on the server
10+
# generate host keys
1411
RUN ssh-keygen -A
1512

16-
# SSH autorun
17-
# RUN rc-update add sshd
18-
19-
WORKDIR /git-server/
13+
WORKDIR /git-server
2014

2115
# -D flag avoids password generation
2216
# -s flag changes user's shell
@@ -34,8 +28,11 @@ COPY git-shell-commands /home/git/git-shell-commands
3428

3529
# sshd_config file is edited for enable access key and disable access password
3630
COPY sshd_config /etc/ssh/sshd_config
37-
COPY start.sh start.sh
31+
COPY start.sh /start.sh
32+
COPY motd /etc
33+
34+
ENV ACCOUNT helmet
3835

3936
EXPOSE 22
4037

41-
CMD ["sh", "start.sh"]
38+
CMD ["sh", "/start.sh"]

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
VERSION=1.0.0
3+
ACCOUNT?=fr123k
4+
REPOSITORIES?=$(PWD)/../
5+
export NAME=fr123k/git-server-docker
6+
export IMAGE="${NAME}:${VERSION}"
7+
export LATEST="${NAME}:latest"
8+
9+
build: ## Build the jenkins in docker image.
10+
docker build -t $(IMAGE) -f Dockerfile .
11+
12+
release: build ## Push docker image to docker hub
13+
docker tag ${IMAGE} ${LATEST}
14+
docker push ${NAME}
15+
16+
git-server:
17+
docker run -p 22:22 -it -v $(REPOSITORIES):/git-server -e ACCOUNT=$(ACCOUNT) --name github --rm ${IMAGE}

README.md

+145-44
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,177 @@
11
# git-server-docker
2-
A lightweight Git Server Docker image built with Alpine Linux. Available on [GitHub](https://github.com/jkarlosb/git-server-docker) and [Docker Hub](https://hub.docker.com/r/jkarlos/git-server-docker/)
2+
A lightweight Git Server Docker image built with Alpine Linux. Available on [GitHub](https://github.com/fr123k/git-server-docker) and [Docker Hub](https://hub.docker.com/r/fr123k/git-server-docker/)
33

4-
!["image git server docker" "git server docker"](https://raw.githubusercontent.com/jkarlosb/git-server-docker/master/git-server-docker.jpg)
4+
## Use Case
55

6-
### Basic Usage
6+
### Local Jenkins use Local Git Repository
77

8-
How to run the container in port 2222 with two volumes: keys volume for public keys and repos volume for git repositories:
8+
The major motivation for the local git server docker container is to provide a way for a local jenkins running in docker to use local git repositories instead of github for example.
99

10-
$ docker run -d -p 2222:22 -v ~/git-server/keys:/git-server/keys -v ~/git-server/repos:/git-server/repos jkarlos/git-server-docker
10+
The following steps describe a way to use the local git server in jenkins without changing the github url of the jobs in jenkins. They can still point to the original github respositories.
1111

12-
How to use a public key:
12+
#### Local DNS
1313

14-
Copy them to keys folder:
15-
- From host: $ cp ~/.ssh/id_rsa.pub ~/git-server/keys
16-
- From remote: $ scp ~/.ssh/id_rsa.pub user@host:~/git-server/keys
17-
You need restart the container when keys are updated:
18-
$ docker restart <container-id>
19-
20-
How to check that container works (you must to have a key):
14+
Setup a domain like `local.github.com` that is then used by jenkins.
2115

22-
$ ssh git@<ip-docker-server> -p 2222
23-
...
24-
Welcome to git-server-docker!
25-
You've successfully authenticated, but I do not
26-
provide interactive shell access.
27-
...
16+
```bash
17+
echo "192.168.65.2 local.github.com" >> /etc/hosts
18+
```
2819

29-
How to create a new repo:
20+
The ip address `192.168.65.2` is specific to your operating system and only works from within a docker container.
21+
**This ip address work on MacOS.**
3022

31-
$ cd myrepo
32-
$ git init --shared=true
33-
$ git add .
34-
$ git commit -m "my first commit"
35-
$ cd ..
36-
$ git clone --bare myrepo myrepo.git
23+
#### Git Config
3724

38-
How to upload a repo:
25+
Add or change the `%{JENKINS_HOME}/.gitconfig` with the following setting.
26+
```
27+
[url "ssh://[email protected]"]
28+
insteadOf = https://github.com/
3929
40-
From host:
41-
$ mv myrepo.git ~/git-server/repos
42-
From remote:
43-
$ scp -r myrepo.git user@host:~/git-server/repos
30+
[url "ssh://[email protected]/"]
31+
insteadOf = [email protected]:
32+
```
4433

45-
How clone a repository:
34+
#### Local Github Server
35+
36+
Run the docker git server container on the port 22 (sshd) and specify the github account like `fr123k`.
37+
38+
`docker run -p 22:22 -it -v $(PWD)/../:/git-server `**`-e ACCOUNT=fr123k`**` --name github --rm fr123k/git-server-docker`
4639

47-
$ git clone ssh://git@<ip-docker-server>:2222/git-server/repos/myrepo.git
40+
If something is not as expected check the [Troubleshooting](#Troubleshooting) section.
41+
42+
## Basic Usage
4843

4944
### Arguments
5045

5146
* **Expose ports**: 22
5247
* **Volumes**:
53-
* */git-server/keys*: Volume to store the users public keys
54-
* */git-server/repos*: Volume to store the repositories
48+
* **/git-server/**: Volume to store the repositories
49+
* **Environment Variables**:
50+
* **ACCOUNT**: Name of the git account
51+
* **DEBUG**: If exits enable debug logging of the sshd to the file `/var/log/auth.log`. Useful for troubleshooting
52+
53+
### Git Repository Volume
54+
55+
The volume has to be mounted to /git-server mount point.
56+
It has to contain the `.keys` folder with all the public keys
57+
for the ssh authentication.
58+
59+
* -v (local_git_repository):/git-server/
60+
61+
Example mount directory that is above the current one as a git repository.
62+
63+
`docker run -p 2222:22 -it `**`-v $(PWD)/../:/git-server`**` --name github --rm fr123k/git-server-docker`
64+
65+
### Git Account Name
66+
67+
The name of the git repository.
68+
* -e ACCOUNT=(name of the git account) default: helmet
69+
70+
For example
71+
`docker run -p 2222:22 -it -v $(PWD)/../:/git-server `**`-e ACCOUNT=fr123k`**` --name github --rm fr123k/git-server-docker`
72+
73+
### Git Account Name
74+
75+
The name of the git repository.
76+
* -e DEBUG=true
77+
78+
For example
79+
`docker run -p 2222:22 -it -v $(PWD)/../:/git-server `**`-e DEBUG=true`**` --name github --rm fr123k/git-server-docker`
80+
81+
### Local SSH Git Server
82+
83+
How to run the container in port 22 (sshd).
84+
85+
`docker run -d -p `**`22:22`**` -v ~/git-server/repos:/git-server/ fr123k/git-server-docker/`
86+
87+
### Local Git Repositories
88+
89+
**After adding git repository described below the docker container has to be always restarted.**
90+
How to create a new repo:
91+
92+
```bash
93+
mkdir local-git-repo
94+
cd local-git-repo/
95+
git init --shared=true
96+
git add .
97+
git commit -m "my first commit"
98+
```
99+
100+
How to upload a repo:
101+
102+
From host:
103+
```bash
104+
mv local-git-repo ~/git-server/
105+
```
106+
From remote:
107+
```bash
108+
scp -r local-git-repo user@host:~/git-server/
109+
```
110+
111+
How clone a repository:
112+
113+
```bash
114+
git clone ssh://[email protected]:22/helmet/local-git-repo.git
115+
```
116+
117+
## Troubleshooting
118+
119+
### Validate Local SSH Git Server
120+
121+
How to check that container and the authentication keys works.
122+
`ssh [email protected] -p 2222`
123+
The expected output looks like this.
124+
```
125+
Welcome to git-server-docker!
126+
127+
Provided to you from
128+
129+
https://hub.docker.com/r/fr123k/git-server-docker/
130+
https://github.com/fr123k/git-server-docker
131+
132+
You've successfully authenticated, but I do not
133+
provide interactive shell access.
134+
Connection to 127.0.0.1 closed.
135+
```
55136

56137
### SSH Keys
57138

58139
How generate a pair keys in client machine:
59140

60-
$ ssh-keygen -t rsa
141+
```bash
142+
ssh-keygen -t rsa
143+
```
61144

62145
How upload quickly a public key to host volume:
63146

64-
$ scp ~/.ssh/id_rsa.pub user@host:~/git-server/keys
147+
```bash
148+
scp ~/.ssh/id_rsa.pub user@host:~/git-server/.keys
149+
```
150+
151+
## Docker Image
152+
153+
All `make` commands can only be from the folder where the Makefile is located.
154+
155+
### Build
65156

66-
### Build Image
157+
How to build the docker image:
67158

68-
How to make the image:
159+
```bash
160+
make build
161+
```
162+
or
163+
```bash
164+
docker build -t git-server-docker .
165+
```
69166

70-
$ docker build -t git-server-docker .
71-
72-
### Docker-Compose
167+
### Run
73168

74-
You can edit docker-compose.yml and run this container with docker-compose:
169+
How to run the image:
75170

76-
$ docker-compose up -d
171+
```bash
172+
make REPOSITORIES=$(PWD)/../ ACCOUNT=fr123k git-server
173+
```
174+
or
175+
```bash
176+
docker run -p 22:22 -it -v $(PWD)/../ :/git-server -e ACCOUNT=fr123k --name github --rm "fr123k/git-server-docker"
177+
```

docker-compose.yml

-15
This file was deleted.

git-server-docker.jpg

-16 KB
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
printf '%s\n' "Welcome to git-server-docker!"
2+
printf '\n'
33
printf '%s\n' "You've successfully authenticated, but I do not"
44
printf '%s\n' "provide interactive shell access."
55
exit 128

motd

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Welcome to git-server-docker!
2+
3+
Provided to you from
4+
5+
https://hub.docker.com/r/fr123k/git-server-docker/
6+
https://github.com/fr123k/git-server-docker

sshd_config

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
# Logging
3737
# obsoletes QuietMode and FascistLogging
38-
#SyslogFacility AUTH
39-
#LogLevel INFO
38+
SyslogFacility AUTH
39+
LogLevel DEBUG
4040

4141
# Authentication:
4242

@@ -50,9 +50,8 @@ RSAAuthentication yes
5050
PubkeyAuthentication yes
5151

5252
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
53-
# but this is overridden so installations will only check .ssh/authorized_keys
54-
AuthorizedKeysFile .ssh/authorized_keys
55-
#AuthorizedKeysFile /home/git/.ssh/authorized_keys
53+
# but this is overridden so installations will only check /home/git/.ssh/authorized_keys
54+
AuthorizedKeysFile /home/git/.ssh/authorized_keys
5655

5756
#AuthorizedPrincipalsFile none
5857

0 commit comments

Comments
 (0)