Skip to content

Commit

Permalink
Merge pull request #23 from mborne/22-viewer
Browse files Browse the repository at this point in the history
restore a basic viewer and upgrade flysystem
  • Loading branch information
mborne authored Jun 18, 2023
2 parents 81aa015 + 5c1875a commit 542aef7
Show file tree
Hide file tree
Showing 25 changed files with 526 additions and 48 deletions.
11 changes: 11 additions & 0 deletions .docker/apache-ports.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Note that default is 80 which requires the following systemctl config
# in some environment : config net.ipv4.ip_unprivileged_port_start=0
Listen 8000

<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
73 changes: 73 additions & 0 deletions .docker/apache-security.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Disable access to the entire file system except for the directories that
# are explicitly allowed later.
#
# This currently breaks the configurations that come with some web application
# Debian packages.
#
#<Directory />
# AllowOverride None
# Require all denied
#</Directory>


# Changing the following options will not really affect the security of the
# server, but might make attacks slightly more difficult in some cases.

#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens Prod
#ServerTokens Full

#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
ServerSignature Off
#ServerSignature On

#
# Allow TRACE method
#
# Set to "extended" to also reflect the request body (only for testing and
# diagnostic purposes).
#
# Set to one of: On | Off | extended
TraceEnable Off
#TraceEnable On

#
# Forbid access to version control directories
#
# If you use version control systems in your document root, you should
# probably deny access to their directories. For example, for subversion:
#
#<DirectoryMatch "/\.svn">
# Require all denied
#</DirectoryMatch>

#
# Setting this header will prevent MSIE from interpreting files as something
# else than declared by the content type in the HTTP headers.
# Requires mod_headers to be enabled.
#
#Header set X-Content-Type-Options: "nosniff"

#
# Setting this header will prevent other sites from embedding pages from this
# site as frames. This defends against clickjacking attacks.
# Requires mod_headers to be enabled.
#
#Header set X-Frame-Options: "sameorigin"


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
13 changes: 13 additions & 0 deletions .docker/apache-vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<VirtualHost *:8000>
DocumentRoot /opt/git-manager/public

<Directory "/opt/git-manager/public">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All

Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
14 changes: 14 additions & 0 deletions .docker/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; config/php.ini
date.timezone = UTC

opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.revalidate_freq = 0
apc.enable_cli = On

display_errors = Off
display_startup_errors = Off

# to avoid problems with symfony
variables_order = "EGPCS"
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

HOST_HOSTNAME=dev.localhost

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=31090a62341e9229972636159d444257
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
php-version: [7.4,8.1,8.2]
php-version: [8.1,8.2]

runs-on: ubuntu-latest

Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ RUN apt-get update \
&& docker-php-ext-install opcache \
&& rm -rf /var/cache/apt/*

#----------------------------------------------------------------------
# Configure PHP
#----------------------------------------------------------------------
COPY .docker/php.ini /usr/local/etc/php/conf.d/app.ini

#----------------------------------------------------------------------
# Configure apache
#----------------------------------------------------------------------
COPY .docker/apache-ports.conf /etc/apache2/ports.conf
COPY .docker/apache-security.conf /etc/apache2/conf-enabled/security.conf
COPY .docker/apache-vhost.conf /etc/apache2/sites-available/000-default.conf

RUN a2enmod rewrite

COPY . /opt/git-manager
WORKDIR /opt/git-manager
COPY --from=builder /opt/git-manager/vendor vendor
Expand All @@ -21,3 +35,5 @@ RUN chown -R www-data:www-data /opt/git-manager/var \
VOLUME /var/git-manager

USER www-data
EXPOSE 8000

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dist: vendor
chmod +x dist/git-manager.phar

.PHONY: test
test: vendor
test: check-style
mkdir -p var/output
rm -rf var/output/*
XDEBUG_MODE=coverage SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit -c phpunit.xml.dist \
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CLI helpers to manage a set of git repositories :

## Requirements

* PHP >= 7.4
* PHP >= 8.x

## Parameters

Expand Down Expand Up @@ -40,7 +40,7 @@ bin/console git:fetch-all --users=_me_ https://github.com $GITHUB_TOKEN
* From gogs or gitea :

```bash
bin/console git:fetch-all --type gogs-v1 https://codes.quadtreeworld.net $GITEA_RO_TOKEN
bin/console git:fetch-all --type gogs-v1 https://codes.quadtreeworld.net $QTW_TOKEN
```

### Compute stats about repositories
Expand All @@ -49,6 +49,22 @@ bin/console git:fetch-all --type gogs-v1 https://codes.quadtreeworld.net $GITEA_
bin/console git:stats -O stats.json
```

## Usage with docker

```bash
# Build image
docker compose build
# Start git-manager
docker compose up -d

# Fetch repositories
docker compose exec git-manager bin/console git:fetch-all https://github.com -u mborne
#docker compose exec git-manager bin/console git:fetch-all --type gogs-v1 https://codes.quadtreeworld.net $QTW_TOKEN

# Build stats
docker compose exec git-manager bin/console git:stats
```

## License

[MIT](LICENSE)
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
],
"require": {
"gitonomy/gitlib": "^1.0",
"league/flysystem": "^1.0",
"mborne/remote-git": "0.4.*",
"league/flysystem": "^3.0",
"mborne/remote-git": "0.5.*",
"symfony/framework-bundle": "5.4.*",
"symfony/console": "5.4.*",
"symfony/runtime": "5.4.*",
"symfony/yaml": "5.4.*"
"symfony/yaml": "5.4.*",
"symfony/twig-bundle": "^6.3",
"symfony/asset": "^6.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.11",
Expand Down
3 changes: 2 additions & 1 deletion config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
];
8 changes: 8 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
twig:
default_path: '%kernel.project_dir%/templates'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
exception_controller: null
# form_themes:
# - 'bootstrap_5_layout.html.twig'
# - 'forms.html.twig'
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

services:

git-manager:
image: ghcr.io/mborne/git-manager:latest
build:
context: .
ports:
- 8000:8000
volumes:
- git-manager-data:/var/git-manager
restart: unless-stopped

volumes:
git-manager-data:
name: git-manager-data

66 changes: 66 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options +FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
55 changes: 55 additions & 0 deletions public/js/git-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function getLastActivity(repository) {
const dates = Object.keys(repository.activity);
if (dates.length == 0) {
return '0000-00-00';
}
const lastDate = dates[dates.length - 1];
return `${lastDate.substring(0, 4)}-${lastDate.substring(4, 6)}-${lastDate.substring(6, 8)}`;
}

/**
* Load /api/repositories to #repositories tables.
*/
function loadRepositories() {
fetch('/api/repositories').then(function (response) {
if (response.status != 200) {
throw new Error('fail to fetch repositories');
}
return response.json();
}).then(function (items) {
let dataSet = Object.keys(items).map(function (name) {
const item = items[name];
const sizeMo = (item.size / (1024 * 1024)).toFixed(1);
return [
`<a href="https://${name}">${name}</a>`,
`<span class="${item.readme ? "text-success" : "text-danger"}">${item.readme ? "FOUND" : "MISSING"}</span>`,
`<span class="${item.license ? "text-success" : "text-danger"}">${item.license ? item.license : "MISSING"}</span>`,
getLastActivity(item),
sizeMo,
];
});
$('#repositories').DataTable({
data: dataSet,
columns: [
{ title: "Name"},
{ title: "README" },
{ title: "LICENSE" },
{ title: "Last Activity" },
{ title: "Size (Mo)" },
],
"paging": false,
"info": false
});
}).catch(function (error) {
$('#repositories').DataTable({
data: [[
`<span class="text-danger">fail to load repositories (run 'bin/console git:stats')</span>`,
]],
columns: [
{ title: "Error" },
],
"paging": false,
"info": false
});
});
}
Loading

0 comments on commit 542aef7

Please sign in to comment.