<commit_before># docker-gitolite-http

A Dockerfile for [Gitolite][gitolite] with added HTTP protocol support. Host your git repositories with Gitolite, access them from anywhere with HTTP ! Uses Apache 2.2, on Debian.

## Usage

### First installation (if you don't already use Gitolite) :

```bash
# 1. Run the container. Don't bind to the SSH port on the host.
sudo docker run -d --name gitolite-http -p 80:80 -p 8022:22 hyzual/gitolite-http

# 2. Next, create the .htpasswd to enable HTTP access
# Please replace "password" with a more secure password
sudo docker exec gitolite-http htpasswd -cb /data/.htpasswd admin password

# 3. To enable HTTP access to your repository, we first have to access it through SSH
# Copy the private key from the container
sudo docker cp gitolite-http:/data/admin .

# 4. Clone the admin repository, using the copied admin key
# Assuming Docker is installed on localhost
ssh-agent bash -c 'ssh-add ./admin; git clone git@localhost:8022:gitolite-admin'

# 5. Finally, we need to give the R permission to the user daemon (which is Apache).
# Add a "R = daemon" line at the end of the "repo testing" block.
vim gitolite-admin/conf/gitolite.conf

git commit

git push

# 6. Now, test that admin has access to the testing repository through HTTP
# Assuming you redirect to port 80 on localhost
git clone http://admin:password@localhost:80/git/testing

# If you cloned the repository without error, it's a success !
```

### To use existing Gitolite repositories :

First, we'll create a data-only container and we'll fill it with our existing gitolite data and repositories.
You can see those instructions at [gitolite-httpdata][gitolite-httpdata].

```bash
# Create a data-only container which will create the volumes needed
sudo docker run -d --name gitolite-httpdata hyzual/gitolite-httpdata
```

The container will stop immediately, which is normal.

Run another container with bash as command, bind-mount your existing repositories and copy them to the volumes. You will also need to change the permissions in the volume since gitolite-http will run with the image's `git` user. Assuming you already ran gitolite with user `git` on the host :

```bash
# Bind-mount gitolite's data to /hostdata and the repositories to /hostrepo
sudo docker run -it --rm --volumes-from gitolitedata -v /home/git:/hostdata -v /home/git/repositories:/hostrepo hyzual/gitolitedata bash

# Copy from /hostdata to the /data volume, copy from /hostrepo to the /repositories volume and change permissions.
cp -R /hostdata/* /data \
	&& cp -R /hostdata/.gitolite /data \
	&& cp -R /hostdata/.gitolite.rc /data \
	&& chown git:git -R /data \
	&& cp -R /hostrepo/* /repositories \
	&& chown git:git -R /repositories

# Check that the /data and /repositories have correct permissions, then exit from the container
exit
```

Now run gitolite-http with the volumes from our data-only container. Don't bind the SSH port on the host.

```bash
sudo docker run -d --name gitolite-http --p 80:80 -p 8022:22 --volumes-from gitolite-httpdata hyzual/gitolite-http
```

Finally, follow the remaining instructions above (see First installation) from step 2 to configure the `.htpasswd` file and grant apache access to the repositories.

## Debug :

```bash
# Apache Error log
docker exec gitolite-http cat /var/log/apache2/error.log
# Apache Access log<commit_msg>Update the README commands, using sh instead of bash in the data-only container<commit_after># docker-gitolite-http

A Dockerfile for [Gitolite][gitolite] with added HTTP protocol support. Host your git repositories with Gitolite, access them from anywhere with HTTP ! Uses Apache 2.2, on Debian.

## Usage

### First installation (if you don't already use Gitolite) :

```bash
# 1. Run the container. Don't bind to the SSH port on the host.
sudo docker run -d --name gitolite-http -p 80:80 -p 8022:22 hyzual/gitolite-http

# 2. Next, create the .htpasswd to enable HTTP access
# Please replace "password" with a more secure password
sudo docker exec gitolite-http htpasswd -cb /data/.htpasswd admin password

# 3. To enable HTTP access to your repository, we first have to access it through SSH
# Copy the private key from the container
sudo docker cp gitolite-http:/data/admin .

# 4. Clone the admin repository, using the copied admin key
# Assuming Docker is installed on localhost
ssh-agent bash -c 'ssh-add ./admin; git clone git@localhost:8022:gitolite-admin'

# 5. Finally, we need to give the R permission to the user daemon (which is Apache).
# Add a "R = daemon" line at the end of the "repo testing" block.
vim gitolite-admin/conf/gitolite.conf

git commit

git push

# 6. Now, test that admin has access to the testing repository through HTTP
# Assuming you redirect to port 80 on localhost
git clone http://admin:password@localhost:80/git/testing

# If you cloned the repository without error, it's a success !
```

### To use existing Gitolite repositories :

First, we'll create a data-only container and we'll fill it with our existing gitolite data and repositories.
You can see those instructions at [gitolite-httpdata][gitolite-httpdata].

```bash
# Create a data-only container which will create the volumes needed
sudo docker run -d --name gitolite-httpdata hyzual/gitolite-httpdata
```

The container will stop immediately, which is normal.

Run another container with bash as command, bind-mount your existing repositories and copy them to the volumes. You will also need to change the permissions in the volume since gitolite-http will run with the image's `git` user. Assuming you already ran gitolite with user `git` on the host :

```bash
# Bind-mount gitolite's data to /hostdata and the repositories to /hostrepo
sudo docker run -it --rm --volumes-from gitolitedata -v /home/git:/hostdata -v /home/git/repositories:/hostrepo hyzual/gitolitedata sh

# Copy from /hostdata to the /data volume, copy from /hostrepo to the /repositories volume and change permissions.
cp -R /hostdata/.[!.]* /data \
	&& chown git:git -R /data \
	&& cp -R /hostrepo/* /repositories \
	&& chown git:git -R /repositories

# Check that the /data and /repositories have correct permissions, then exit from the container
exit
```

Now run gitolite-http with the volumes from our data-only container. Don't bind the SSH port on the host.

```bash
sudo docker run -d --name gitolite-http --p 80:80 -p 8022:22 --volumes-from gitolite-httpdata hyzual/gitolite-http
```

Finally, follow the remaining instructions above (see First installation) from step 2 to configure the `.htpasswd` file and grant apache access to the repositories.

## Debug :

```bash
# Apache Error log
docker exec gitolite-http cat /var/log/apache2/error.log
# Apache Access log
{'fraction_non_alphanumeric': 0.08435171385991058, 'fraction_numerical': 0.011326378539493294, 'mean_word_length': 4.004474272930649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '579943', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1902, 'n_words': 923}