Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c898b0d
Upgrades to latest Git release
solsson Sep 20, 2016
076b26c
Break up into separate images for git installation and git httpd conf…
solsson Sep 20, 2016
8900286
Omit the organization prefix so we can use FROM with docker-compose b…
solsson Sep 20, 2016
583cb98
Use one container to initialize git repositories with content for a s…
solsson Sep 20, 2016
0286ced
Removes misleading image: from downstrea, but keeps depends_on becaus…
solsson Sep 20, 2016
bc6ce0a
libcurl-gnutls required for local git http clone, and with libcurl pr…
solsson Sep 20, 2016
ecb23ec
Looks like there's a severe regression in solsson/httpd:git for 2.9+,…
solsson Sep 20, 2016
fcd8aca
Verified that config reload works with docker httpd, noted as pseudo …
solsson Sep 20, 2016
98c80c8
Test setup, now let's do the scripting
solsson Sep 22, 2016
8aede88
Refactors git httpd config to allow push, if auth is configured. Yole…
solsson Sep 22, 2016
72a8d4b
wip httpd with conf from git clone
solsson Sep 22, 2016
62c2c10
Starts HTTP level specs for the httpd-reconf concept
solsson Sep 23, 2016
047933a
Automatic test runs would be great for development
solsson Sep 23, 2016
b70bf92
Test::Continuous worked with Docker for Mac, App::prowess didn't
solsson Sep 23, 2016
5b7b3a1
Just switch entrypoint to get continous testing. Validated with both …
solsson Sep 23, 2016
52b22b2
Adapt to new perlspec entrypoint
solsson Sep 23, 2016
4e825c1
Starts a script concept for the reconf operation
solsson Sep 23, 2016
06abc13
The build+FROM gotcha
solsson Sep 24, 2016
5ed5999
No runtimeDeps may exist in buildDeps. Regarding ca-certificates they…
solsson Sep 24, 2016
ab42aeb
Make som kind of lib for the various tasks invovled, experimenting wi…
solsson Sep 24, 2016
d3284de
lotsa gotchas
solsson Sep 24, 2016
136ec8c
Allows logging level to be increased using the same env as with node.js
solsson Sep 25, 2016
00c575d
Something of a complete, but untested, workflow
solsson Sep 25, 2016
8dc6fd5
Expose port for testing
solsson Sep 25, 2016
2374b7b
Support fixing invalid conf by pushing another git commit from somewhere
solsson Sep 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions build-contracts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '2'
services:
gitclient.build:
build: ../gitclient
image: httpd-gitclient
entrypoint: ["echo", "This service was just a build job. Exiting."]
git.build:
build: ../git
depends_on:
- gitclient.build
image: httpd-git
entrypoint: ["echo", "This service was just a build job. Exiting."]
# httpd-git acceptance testing
githost:
build: ./githost
depends_on:
- git.build
ports:
- "80"
readonly:
build: ./githost
depends_on:
- git.build
ports:
- "80"
environment:
- GIT_READONLY=1
test.git:
build: ./perlspec
labels:
com.yolean.build-contract: "*"
links:
- githost
- readonly
volumes:
- ./test:/project/t
# httpd-gitconf acceptance testing
httpd:
build: ../httpd-gitconf
image: httpd-gitconf
depends_on:
- gitclient.build
links:
- githost
volumes:
- ./gitconf-test:/gitconf-test
- ../httpd-gitconf:/perldev
entrypoint: /gitconf-test/httpd-entrypoint-gitconf
ports:
- "80"
environment:
- DEBUG=*
test.reconf:
build: ./perlspec
labels:
com.yolean.build-contract: "*"
links:
- githost
- httpd
volumes:
- ./gitconf-test:/project/t
# Of these test watch tools prowess' terminal usage seems to work better with docker-compose run, but neither understands Ctrl+C so you need docker kill
#entrypoint: autoprove
#entrypoint: prowess
12 changes: 12 additions & 0 deletions build-contracts/gitconf-test/httpd-entrypoint-gitconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/perl -w
use strict;

`git clone http://githost/git/Test/conf.git /tmp/conf`; $? == 0 or die;
`git clone http://githost/git/Test/cert.git /tmp/cert`; $? == 0 or die;
`rm /usr/local/apache2/conf -Rf`; $? == 0 or die;
`mv /tmp/conf /usr/local/apache2/conf`; $? == 0 or die;
`mv /tmp/cert /usr/local/apache2/cert`; $? == 0 or die;
`apachectl configtest`; $? == 0 or die;

# now the real entrypoint
exec 'httpd-foreground';
85 changes: 85 additions & 0 deletions build-contracts/gitconf-test/reconf-spec.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/perl -w
use strict;

use Test::Spec;

my $testkey = time();
mkdir "/tmp/testrun-$testkey";
chdir "/tmp/testrun-$testkey";
print "# testrun /tmp/testrun-$testkey\n";

use HTTP::Tiny;
use JSON;

my $r;

describe "Httpd state at container startup" => sub {

it "Should be running" => sub {
$r = HTTP::Tiny->new->head('http://httpd/');
is($r->{status}, 200);
};

it "Should have a typical 404 error page" => sub {
$r = HTTP::Tiny->new->head('http://httpd/testing/notfound');
is($r->{status}, 404);
isnt($r->{content}, 'Custom.');
};

};

describe "A shared git remote" => sub {

it "Is alive" => sub {
$r = HTTP::Tiny->new->head('http://githost/');
is($r->{status}, 200);
};

it "Has a conf repo to clone" => sub {
`git clone http://githost/git/Test/conf.git`;
is($?, 0);
ok(-e 'conf/.git');
};

it "Has a cert repo to clone" => sub {
`git clone http://githost/git/Test/cert.git`;
is($?, 0);
ok(-e 'conf/.git');
};

};

describe "Extenal conf modification over git" => sub {

it "Add a simple one liner that can be detected over HTTP" => sub {
`echo '<Location /testing>ErrorDocument 404 "Custom."</Location>' >> conf/httpd.conf`;
is($?, 0);
`cd conf/; git add httpd.conf; git commit -m "Change 404 page"`;
is($?, 0);
};

it "Trigger httpd reconf using REST endpoint" => sub {
my $http = HTTP::Tiny->new();
my $r = $http->post(
'http://httpd/admin/reconf' => {
content => to_json(
{}
),
headers => {
'Accept' => 'application/json',
},
},
);
is($r->{status}, 200);
};

it "Shuld now have affected httpd's runtime conf" => sub {
$r = HTTP::Tiny->new->head('http://httpd/testing/notfound');
is($r->{content}, 'Custom.');
};

};



runtests unless caller;
22 changes: 22 additions & 0 deletions build-contracts/githost/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM httpd-git

RUN sed -i 's|^#LoadModule authn_anon_module|LoadModule authn_anon_module|' conf/httpd.conf

COPY auth-anon.conf conf/git/

RUN mkdir -p /opt/git/Test \
&& git init --bare /opt/git/Test/test.git \
&& git init --bare /opt/git/Test/conf.git \
&& git init --bare /opt/git/Test/cert.git \
&& chown -R daemon /opt/git

RUN git config --global user.email "you@example.com" \
&& git config --global user.name "Your Name" \
&& git clone /opt/git/Test/conf.git /tmp/conf \
&& cd /tmp/conf/ \
&& cp /usr/local/apache2/conf/httpd.conf . \
&& cp /usr/local/apache2/conf/mime.types . \
&& sed -i 's/^Include/#Include/' httpd.conf \
&& git add * \
&& git commit -m "Gets httpd up and running" \
&& git push origin master
11 changes: 11 additions & 0 deletions build-contracts/githost/auth-anon.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Location />
AuthName "If visitors get this auth prompt you are at risk"
AuthType Basic
AuthBasicProvider anon

Anonymous_NoUserID off
Anonymous_MustGiveEmail off
Anonymous_VerifyEmail off
Anonymous_LogEmail off
Anonymous "*"
</Location>
25 changes: 25 additions & 0 deletions build-contracts/perlspec/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM perl:5.24

# http://stackoverflow.com/questions/3462058/how-do-i-automate-cpan-configuration
RUN (echo y;echo o conf prerequisites_policy follow;echo o conf commit) | cpan

RUN cpan install Test::Spec

RUN cpan install HTTP::Tiny JSON

# We need one of these and I don't know which one is more stable or useful yet
# To evaluate, toggle entrypoint between prove/autoprove/prowess
RUN cpan install Test::Continuous App::prowess

RUN git --version && cpan install Git::Wrapper

RUN git config --global user.email "perlspec-testing@example.com" \
&& git config --global user.name "Perlspec Testint"

# Official perl image gotcha, /usr/bin/perl fails to include CPAN modules
RUN mv /usr/bin/perl /usr/bin/perl.org \
&& ln -s /usr/local/bin/perl /usr/bin/perl

WORKDIR /project

ENTRYPOINT ["prove"]
70 changes: 70 additions & 0 deletions build-contracts/test/git-http-spec.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/perl -w
use strict;

use Test::Spec;

# Didn't like this much, let's see if we need it
#use Git::Wrapper;
#my $git = Git::Wrapper->new('/tmp/test');

my $testkey = time();
mkdir "/tmp/testrun-$testkey";
chdir "/tmp/testrun-$testkey";
print "# testrun /tmp/testrun-$testkey\n";

describe "Clone at /git/[org]/[repo]" => sub {

it "Allowed" => sub {
`git clone http://githost/git/Test/test.git ./test`;
is($?, 0);
};

it "Produces a local repo" => sub {
ok(-e 'test/.git' and -d 'test/.git');
};

};

describe "Readonly" => sub {

it "Same clone behavior as regular host" => sub {
`git clone http://readonly/git/Test/test.git ./readonly`;
is($?, 0);
};

it "Same fetch" => sub {
`cd test/ && git remote add readonly http://readonly/git/Test/test.git && git fetch readonly`;
is($?, 0);
};

it "Denies push" => sub {
`cd test/ && echo test > test1.txt && git add test1.txt && git commit -m "Test 1"`;
is($?, 0);
`cd test/ && git push readonly master`;
isnt($?, 0);
};

# TODO test for status code 403 at GET /git/Test/test.git/info/refs?service=git-receive-pack
# as the test above passes for status 500 (i.e. auth not configured) too
# Or we can possibly just check for git auth attempt "fatal: could not read Username for 'http://readonly': No such device or address"

};

describe "Push" => sub {

it "Requires authentication (with default config, custom auth conf needed)" => sub {
`cd test/ && git push origin master`;
isnt($?, 0);
};

it "Test container runs mod_auth_anon so any username will do here" => sub {
`cd test/ && git remote add auth 'http://testuser:\@githost/git/Test/test.git' && git remote -v`;
## more presistent auth
#`echo 'http://testuser:@githost' >> ~/.git-credentials`
#`cd test/ && git config credential.helper store && git push origin master`;
is($?, 0);
};

};

runtests unless caller;
51 changes: 6 additions & 45 deletions git/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@

FROM httpd:2.4.23

ENV GIT_VERSION 2.9.3
ENV GIT_VERSION_TGZ_URL https://www.kernel.org/pub/software/scm/git/git-$GIT_VERSION.tar.gz
ENV GIT_VERSION_TGZ_SHA1 ae90c4e5008ae10c8a67a51ff3dbea8364d97168

RUN depsRuntime=' \
libcurl3 \
libexpat1 \
gettext \
libssl1.0.0 \
' \
&& depsBuild=' \
curl ca-certificates \
gcc \
make \
autoconf \
libcurl4-gnutls-dev \
libexpat1-dev \
gettext \
libz-dev \
libssl-dev \
' \
set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends $depsRuntime \
&& apt-get install -y --no-install-recommends $depsBuild \
&& rm -r /var/lib/apt/lists/* \
&& curl -SL "$GIT_VERSION_TGZ_URL" -o git-$GIT_VERSION.tar.gz \
&& echo "$GIT_VERSION_TGZ_SHA1 git-$GIT_VERSION.tar.gz" | sha1sum -c - \
&& mkdir -p src/git \
&& tar -xvf git-$GIT_VERSION.tar.gz -C src/git --strip-components=1 \
&& rm git-$GIT_VERSION.tar.gz* \
&& cd src/git \
&& make configure \
&& ./configure --prefix=/usr \
&& make all \
&& make install \
&& cd ../../ \
&& rm -r src/git \
&& apt-get purge -y --auto-remove $depsBuild

EXPOSE 80
FROM httpd-gitclient

RUN sed -i 's|#LoadModule cgid_module|LoadModule cgid_module|' conf/httpd.conf \
&& sed -i 's|#LoadModule rewrite_module|LoadModule rewrite_module|' conf/httpd.conf \
&& echo "Include conf/git/*.conf" >> conf/httpd.conf

ENV GIT_PROJECT_ROOT="/opt/git"
ENV GIT_HTTP_EXPORT_ALL="1"
ENV GIT_READONLY=""

ADD conf/git.conf /usr/local/apache2/conf/git/
ADD conf/git-readonly.conf /usr/local/apache2/conf/git/
ADD conf/git-access.conf /usr/local/apache2/conf/git/
18 changes: 18 additions & 0 deletions git/conf/git-access.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

RewriteEngine On

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteCond %{GIT_READONLY} !^$
RewriteRule ^/git/ - [F]

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED]

<Files "git-http-backend">
Require valid-user
Order deny,allow
Deny from env=AUTHREQUIRED
Satisfy any
</Files>
6 changes: 0 additions & 6 deletions git/conf/git-readonly.conf

This file was deleted.

10 changes: 3 additions & 7 deletions git/conf/git.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
SetEnv GIT_PROJECT_ROOT /opt/git
SetEnv GIT_HTTP_EXPORT_ALL 1
PassEnv GIT_PROJECT_ROOT
PassEnv GIT_HTTP_EXPORT_ALL

ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<Location /usr/libexec/git-core>
Options +ExecCGI
Require all granted
</Location>

RewriteEngine On
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED]
Loading