Commit f68c4eeb authored by Matthias Larisch's avatar Matthias Larisch
Browse files

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 diff is collapsed.
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment