Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yuki-kimoto/gitprep
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Jun 15, 2021
2 parents e074051 27030ea commit a57e311
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 4,6 @@ deny from all
allow from all
</Files>

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

DirectoryIndex index.cgi
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 549,33 @@ Caveat - this installation method is only supported for Linux OS.

Follow [Sparrowdo](https://github.com/melezhik/sparrowdo) for the details.

**Dockerfile and docker-compose**

You can use Docker to build your own container based on Alpine Linux. This image configures SSHD to be run by user root and GitPrep to be run by user gitprep.

docker build ./deploy -t jndeverteuil/gitprep:latest

With that build, you can start a service with docker-compose:

version: "3"

services:
gitprep:
image: jndeverteuil/gitprep:latest
container_name: gitprep
hostname: gitprep
restart: always
ports:
- "10020:10020"
- "0.0.0.0:2222:22"
volumes:
- gitprep:/home/gitprep
- sshd:/etc/ssh

volumes:
gitprep:
sshd:

## For Developers

### Run GitPrep in development mode
Expand All @@ -573,7 600,7 @@ GitPrep is the best example for developers who want to create installabel Mojoli

Even if shared hosting server, you can install Mojolicious application as CGI.

###1. cpanm and cpanfile, module installation and version controll###
###1. cpanm and cpanfile, module installation and version control###

[Tatsuhiko Miyagawa](http://weblog.bulknews.net/)'s cpanm and cpanfile is the tool which install CPAN module easily.

Expand Down
76 changes: 76 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 1,76 @@
FROM alpine:3.9

# Update OS and install dependencies
RUN set -x \
&& apk update \
&& apk upgrade \
&& apk --no-cache add \
tini \
bash \
shadow \
perl \
git \
openssh-server \
perl-dev \
gcc \
g \
curl \
wget \
make

# Create user gitprep
RUN set -x \
&& useradd -m gitprep \
&& mkdir -m 700 /home/gitprep/.ssh \
&& usermod -p '*' gitprep \
&& touch /home/gitprep/.ssh/authorized_keys \
&& chmod 600 /home/gitprep/.ssh/authorized_keys \
&& chown -R gitprep:gitprep /home/gitprep/.ssh \
&& sed -i 's/#PasswordAuthentication yes.*/PasswordAuthentication no/' /etc/ssh/sshd_config \
&& sed -i 's/#ChallengeResponseAuthentication yes.*/ChallengeResponseAuthentication no /' /etc/ssh/sshd_config

USER gitprep

# Install GitPrep
RUN set -x \
&& git --version \
&& perl -v \
&& curl -kL https://github.com/yuki-kimoto/gitprep/archive/latest.tar.gz \
> /home/gitprep/gitprep-latest.tar.gz \
&& mkdir /home/gitprep/gitprep \
&& tar -zxf /home/gitprep/gitprep-latest.tar.gz \
--strip-components=1 -C /home/gitprep/gitprep \
&& rm -f /home/gitprep/gitprep-latest.tar.gz \
&& cd /home/gitprep/gitprep \
&& PERL_USE_UNSAFE_INC=1 ./setup_module \
&& prove t \
&& ./setup_database

USER root

# Clean obsolete Packages
RUN set -x \
&& apk del --no-cache \
perl-dev \
gcc \
g \
curl \
wget \
make

# Copy start script
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod 700 /docker-entrypoint.sh

# Expose default HTTP connector port.
EXPOSE 10020
EXPOSE 22

# Set volume mount point
VOLUME ["/home/gitprep"]

# Set the default working directory as the installation directory.
WORKDIR /home/gitprep

# Set entrypoint to invoke tini as PID1
ENTRYPOINT ["/sbin/tini","--","/docker-entrypoint.sh"]
18 changes: 18 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 1,18 @@
version: "3"

services:
gitprep:
image: yuki-kimoto/gitprep:latest
container_name: gitprep
hostname: gitprep
restart: always
ports:
- "10020:10020"
- "0.0.0.0:2222:22"
volumes:
- gitprep:/home/gitprep
- sshd:/etc/ssh

volumes:
gitprep:
sshd:
20 changes: 20 additions & 0 deletions deploy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 1,20 @@
#!/bin/sh

# Making all required files if they are not existing.
test -f /etc/ssh/ssh_host_ecdsa_key || \
/usr/bin/ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -C '' -N ''
test -f /etc/ssh/ssh_host_rsa_key || \
/usr/bin/ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C '' -N ''
test -f /etc/ssh/ssh_host_ed25519_key || \
/usr/bin/ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -C '' -N ''

# Now start SSH daemon.
/usr/sbin/sshd

# GitPrep restrict max post message size 10MB(This is default of Mojolicious)
# We overwrite the value to 1GB :
export MOJO_MAX_MESSAGE_SIZE=1024000000

# Start GitPrep and tail log file
su - gitprep -s /bin/bash -c '/home/gitprep/gitprep/gitprep'
tail -f /home/gitprep/gitprep/log/production.log
11 changes: 7 additions & 4 deletions lib/Gitprep.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 24,9 @@ use Time::Moment;

our $VERSION = 'v2.6.2';

our $user_re = qr/[a-zA-Z0-9_\-] /;
our $project_re = qr/[a-zA-Z0-9_\-\.] /;

has 'dbi';
has 'git';
has 'manager';
Expand Down Expand Up @@ -294,14 297,14 @@ sub startup {
user_name => sub {
my $value = shift;

return ($value || '') =~ /^[a-zA-Z0-9_\-] $/;
return ($value || '') =~ /^$user_re$/;
},
project_name => sub {
my $value = shift;
return 0 unless defined $value;
return 0 if $value eq '.' || $value eq '..';

return ($value || '') =~ /[a-zA-Z0-9_\-\.] $/;
return ($value || '') =~ /$project_re$/;
}
);

Expand All @@ -311,12 314,12 @@ sub startup {
return 0 unless defined $value;
return 0 if $value eq '.' || $value eq '..';

return ($value || '') =~ /[a-zA-Z0-9_\-\.] $/;
return ($value || '') =~ /$project_re$/;
});
$vc->add_check(user_name => sub {
my ($vc, $value) = @_;

return ($value || '') =~ /^[a-zA-Z0-9_\-] $/;
return ($value || '') =~ /^$user_re$/;
});

# Basic auth plugin
Expand Down
5 changes: 3 additions & 2 deletions script/gitprep-shell-raw
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 11,12 @@ use Gitprep;
my $debug = 0;

# Project name pattern
my $project_re = qr/[a-zA-Z0-9_\-\.] $/;
my $project_re = qr/$Gitprep::project_re$/;

# User
my $session_user_id = shift;
die "User not specifed" unless defined $session_user_id;
my $user_re = qr/$Gitprep::user_re/;

# Application
my $app = Mojo::Server->new->load_app("$FindBin::Bin/gitprep");
Expand Down Expand Up @@ -78,7 79,7 @@ sub parse_ssh_original_command {
$ssh_original_command ||= '';

my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
if ($ssh_original_command =~ m(^($git_commands) '.*/([a-zA-Z0-9_] )/([^\/] ?)\.git'$)) {
if ($ssh_original_command =~ m(^($git_commands) '.*/($user_re)/([^\/] ?)\.git'$)) {
my ($verb, $user_id, $project_id) = ($1, $2, $3);
warn "User:$user_id, Project:$project_id" if $debug;
die "invalid repo name: '$project_id'\n" if $project_id !~ $project_re;
Expand Down

0 comments on commit a57e311

Please sign in to comment.