Commit f68c4eeb authored by Matthias Larisch's avatar Matthias Larisch

Merge branch 'dev-setup' into 'master'

add dev-setup

See merge request !1
parents 6b5b96ee c92a4796
Pipeline #3871992 passed with stage
in 5 minutes and 5 seconds
.pip-cache
......@@ -10,3 +10,7 @@ node_modules
js/gen/script.js
css/gen/style.css
config.inc.php
cache
tmp
vendor
tests/_output/*vendor
image: alpine
cache:
# shared cache for all branches
key: "$CI_PROJECT_NAME"
paths:
- vendor/
- chat/node_modules/
- .pip-cache
services:
- docker:dind
test:
script:
# setup tools
- apk add -U docker bash py-pip
- mkdir -p .pip-cache
- pip install --cache-dir=.pip-cache docker-compose
# make cache dirs
- mkdir -p vendor chat/node_modules/
# run the actual tests
- ./scripts/ci.test
# collect the contents to cache
- rm -rf vendor chat/node_modules/
- docker cp foodsharing_ci_app:/app/vendor vendor
- docker cp foodsharing_ci_chat:/app/chat/node_modules chat/node_modules
# stop/kill all the containers
- FS_ENV=ci ./scripts/rm
tags:
- shared
variables:
DOCKER_HOST: docker:2375
# https://docs.docker.com/engine/userguide/storagedriver/selectadriver/
# https://gitlab.com/gitlab-org/gitlab-ce/issues/19971
DOCKER_DRIVER: overlay
# foodsharing
This `dev-setup` branch makes it easy for people to setup foodsharing on their computer
for development purposes.
It runs everything inside docker containers to have minimal impact on the local system and
allow precise versions of software to be defined to match production setup closely.
The intention would be to merge it into master, a few things should be checked/solved first
though:
* it includes `config.inc.php` in the repo now, to switch between configs based on env var, the live site would have to create a `config.inc.prod.php` file and set env var `FS_ENV=prod`
* it should be checked by someone familiar with the foodsharing.de codebase/infrastructure
* see https://gitlab.com/foodsharing-dev/foodsharing/milestones/3 for other outstanding issues
## Getting started
Make sure you have installed
[docker-compose](https://docs.docker.com/compose/install/) and node/npm first.
If you're [using OSX](https://docs.docker.com/engine/installation/mac/)
you'll have a better experience with Docker for Mac rather than Docker Toolbox
(files won't update properly if using Toolbox).
```
git clone git@gitlab.com:foodsharing-dev/foodsharing.git foodsharing
cd foodsharing
git checkout dev-setup
./scripts/start
```
It'll take some time the first time you run it to fetch all the docker images and
install composer/npm etc, so go and make a cup of tea.
### Up and Running
Now go and visit [localhost:18080](http://localhost:18080).
If you want a bit of seed data to play with, run:
```
./scripts/seed
```
It will give you two users you can sign in as:
| email | password |
|-------------------|----------|
| user1@example.com | user1 |
| user2@example.com | user2 |
To stop everything again just run:
```
./scripts/stop
```
PHPMyAdmin is also included: [localhost:18081](http://localhost:18081). Log in with:
| field | value |
|-------|-------|
| Server | db |
| Username | root |
| Password | root |
### Testing
Run the tests with:
```
./scripts/test
```
You will need to have initialized everything once (with `./scripts/start`),
but you do not need to have the main containers running to run the tests
as it uses it's own cluster of docker containers.
### Asset watching / building
To rebuild assets on change, run:
```
./scripts/watch-assets
```
# Helper scripts
There are a number of helper scripts available. Most of them obey the `FS_INT` env var. Default is `dev`, you can also set it to `test`.
| script | purpose |
|--------|---------|
| ./scripts/build-assets | builds the static assets |
| ./scripts/watch-assets | builds the static assets on change |
| ./scripts/composer | run php composer |
| ./scripts/docker-compose | docker-compose with the correct options set for the env |
| ./scripts/dropdb | drop the database |
| ./scripts/clean | remove anything add by start/test commands |
| ./scripts/initdb | create the database and run migrations |
| ./scripts/mkdirs | create directories that need to be present |
| ./scripts/mysql | run mysql command in correct context |
| ./scripts/mysqldump | run mysqldump command in correct context |
| ./scripts/npm | run npm in the chat server context |
| ./scripts/rebuild-container [name] | rebuilds and restarts a single container, useful if changing nginx config for example |
| ./scripts/rm | shutdown and cleanup all containers |
| ./scripts/seed | run seed scripts in `scripts/seeds/*.sql` |
| ./scripts/start| start everything! initializing anything if needed |
| ./scripts/stop | stop everything, but leave it configured |
| ./scripts/test | run tests |
| ./scripts/test-rerun | run tests without recreating db |
......@@ -75,4 +75,4 @@ class BasketControl extends Control
$this->view->basket($basket,$wallposts,$requests);
}
}
\ No newline at end of file
}
FROM registry.gitlab.com/foodsharing-dev/images:chat
WORKDIR /app/chat
COPY package.json .
RUN npm install
RUN npm prune
CMD ["node", "server.js"]
FROM registry.gitlab.com/foodsharing-dev/images:chat
COPY . /app/chat
WORKDIR /app/chat
COPY package.json .
RUN npm install
RUN npm prune
CMD ["node", "server.js"]
......@@ -9,7 +9,7 @@ var http = require('http');
var input_port = 1338
var client_port = 1337
var listenHost = process.argv[2] || '127.0.0.1';
sendtoclient = function(client,a,m,o){
if(connected_clients[client]) {
......@@ -59,8 +59,8 @@ var app = http.createServer(function (req, res) {
}
///// http://127.0.0.1:1338/?c=123456&a=msg&m=module&o=[aaa,bbb,ccc]
});
app.listen(input_port, 'localhost');
console.log("http server started on port ", input_port);
app.listen(input_port, listenHost);
console.log("http server started on", listenHost + ':' + input_port);
var app2 = http.createServer(function (req, res) {
......@@ -72,8 +72,8 @@ var io = require('socket.io')(app2);
//io.set("transports", ['websocket', 'xhr-polling', 'htmlfile']);
//io.set("polling duration", 10);
app2.listen(client_port, 'localhost');
console.log("socket.io started on port ", client_port);
app2.listen(client_port, listenHost);
console.log("socket.io started on port", listenHost + ':' + client_port);
var connected_clients = {};
io.on('connection', function (socket) {
......
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
This diff is collapsed.
<?php
$protocol = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
{
$protocol = 'https';
}
define('PROTOCOL',$protocol);
define('DB_HOST','db');
define('DB_USER','root');
define('DB_PASS','root');
define('DB_DB','foodsharing');
define('PREFIX','fs_');
define('ERROR_REPORT',E_ALL);
define('BASE_URL', $protocol . '//lmr.local/');
define('URL_INTERN',$protocol . '://lmr.local/freiwillige/');
define('DEFAULT_EMAIL','noreply@lebensmittelretten.de');
define('DEFAULT_EMAIL_NAME','Foodsharing Freiwillige');
define('VERSION','0.8.1');
define('EMAIL_PUBLIC', 'info@lebensmittelretten.de');
define('EMAIL_PUBLIC_NAME','Foodsharing Freiwillige');
define('DEFAULT_HOST','lebensmittelretten.de');
define('API_ID','c1d9a69515d63194b4329a5359a4c40a'); // foodsharing api key
define('SMTP_HOST','');
define('SMTP_USER','');
define('SMTP_PASS','');
define('SMTP_PORT',25);
define('MEM_ENABLED', true);
define('REDIS_HOST', 'redis');
define('REDIS_PORT', 6379);
if(!defined('ROOT_DIR'))
{
define('ROOT_DIR','./');
}
<?php
# TODO: sanitize env name
# TODO: maybe have a default env?
# TODO: check if there is not already a concept of app environment elsewhere
$FS_ENV= getenv('FS_ENV');
$env_filename = 'config.inc.'.$FS_ENV.'.php';
if (file_exists($env_filename)) {
require_once $env_filename;
} else {
die('no config found for env ['.$FS_ENV.']');
}
<?php
$protocol = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
{
$protocol = 'https';
}
define('PROTOCOL',$protocol);
define('DB_HOST','db');
define('DB_USER','root');
define('DB_PASS','root');
define('DB_DB','foodsharing');
define('PREFIX','fs_');
define('ERROR_REPORT',E_ALL);
define('BASE_URL', $protocol . '//lmr.local/');
define('URL_INTERN',$protocol . '://lmr.local/freiwillige/');
define('DEFAULT_EMAIL','noreply@lebensmittelretten.de');
define('DEFAULT_EMAIL_NAME','Foodsharing Freiwillige');
define('VERSION','0.8.1');
define('EMAIL_PUBLIC', 'info@lebensmittelretten.de');
define('EMAIL_PUBLIC_NAME','Foodsharing Freiwillige');
define('DEFAULT_HOST','lebensmittelretten.de');
define('API_ID','c1d9a69515d63194b4329a5359a4c40a'); // foodsharing api key
define('SMTP_HOST','');
define('SMTP_USER','');
define('SMTP_PASS','');
define('SMTP_PORT',25);
define('MEM_ENABLED', true);
define('REDIS_HOST', 'redis');
define('REDIS_PORT', 6379);
if(!defined('ROOT_DIR'))
{
define('ROOT_DIR','./');
}
This source diff could not be displayed because it is too large. You can view the blob instead.
FROM orchardup/mysql
COPY . /app
FROM registry.gitlab.com/foodsharing-dev/images:php
WORKDIR /app
COPY composer.json .
COPY composer.lock .
RUN composer install
\ No newline at end of file
FROM registry.gitlab.com/foodsharing-dev/images:php
COPY . /app
RUN chmod 777 -R /app
WORKDIR /app
COPY composer.json .
COPY composer.lock .
RUN composer install
FROM registry.gitlab.com/foodsharing-dev/images:web
\ No newline at end of file
FROM registry.gitlab.com/foodsharing-dev/images:web
COPY . /app
\ No newline at end of file
[global]
daemonize = no
error_log = /proc/self/fd/2
[www]
access.log = /proc/self/fd/2
clear_env = no
catch_workers_output = yes
user = www-data
group = www-data
listen = 0.0.0.0:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /app
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
extension=curl.so
extension=zip.so
[CLI Server]
cli_server.color = On
[Date]
date.timezone = UTC
[filter]
[iconv]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[Assertion]
zend.assertions = -1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[opcache]
[curl]
[openssl]
#upstream app {
# server app:9000;
#}
upstream chat {
server chat:1337;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8080 default_server;
server_name localhost;
root /app;
index index.php;
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass app:9000;
}
include includes/foodsharing.conf;
location / {
try_files $uri $uri/ =404;
}
location /chat/socket.io {
rewrite /chat/(.*) /$1 break;
proxy_pass http://chat;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
location ^~ /partner {
try_files $uri $uri/ /index.php?page=content&sub=partner&uri=$uri;
}
location ^~ /ueber-uns {
try_files $uri $uri/ /index.php?page=content&sub=about&uri=$uri;
}
location ^~ /team {
try_files $uri $uri/ /index.php?page=team&uri=$uri;
}
location ^~ /faq {
try_files $uri $uri/ /index.php?page=content&sub=faq&uri=$uri;
}
location ^~ /fuer-unternehmen {
try_files $uri $uri/ /index.php?page=content&sub=fuer_unternehmen&uri=$uri;
}
location ^~ /leeretonne {
try_files $uri $uri/ /index.php?page=content&sub=leeretonne&uri=$uri;
}
location ^~ /fairteilerrettung {
try_files $uri $uri/ /index.php?page=content&sub=fairteilerrettung&uri=$uri;
}
location ^~ /unterstuetzung {
try_files $uri $uri/ /index.php?page=content&sub=unterstuetzung&uri=$uri;
}
location ^~ /impressum {
try_files $uri $uri/ /index.php?page=content&sub=impressum&uri=$uri;
}
location ^~ /ratgeber {
try_files $uri $uri/ /index.php?page=content&sub=ratgeber&uri=$uri;
}
location ^~ /recovery {
try_files $uri $uri/ /index.php?page=login&sub=passwordReset&uri=$uri;
}
location ^~ /login {
try_files $uri $uri/ /index.php?page=login&uri=$uri;
}
location ^~ /statistik {
try_files $uri $uri/ /index.php?page=statistics&uri=$uri;
}
location ^~ /profile {
try_files $uri $uri/ /index.php?page=profile&uri=$uri;
}
location ^~ /karte {
try_files $uri $uri/ /index.php?page=map&uri=$uri;
}
location ^~ /news {
try_files $uri $uri/ /index.php?page=blog&uri=$uri;
}
location ~ "^/blog/([0-9]+)$" {
try_files $uri $uri/ /index.php?page=blog&sub=read&id=$1;
}
location ^~ /mach-mit {
try_files $uri $uri/ /index.php?page=join&uri=$uri;
}
location ^~ /fairteiler {
try_files $uri $uri/ /index.php?page=fairteiler&uri=$uri;
}
location ^~ /essenskoerbe {
try_files $uri $uri/ /index.php?page=basket&uri=$uri;
}
\ No newline at end of file
version: '2'
services:
# nginx
#------------------------------------
# proxies connections to app/chat
web:
container_name: foodsharing_ci_web
build:
context: ..
dockerfile: docker/Dockerfile.web.ci
ports:
- 38080:8080
expose:
- 8080
depends_on:
- app
- chat
# main php app
#------------------------------------
app:
container_name: foodsharing_ci_app
build:
context: ..
dockerfile: docker/Dockerfile.php.ci
expose:
- 9000
links:
- redis:redis
- db:db
- chat:chat
environment:
FS_ENV: test