Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
sql/
Dockerfile*
app/tmp/
.env
17 changes: 17 additions & 0 deletions .env → .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml

# Extending with separate tooling container
#COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml:docker-compose.tooling.yml

# CakePHP env
LOG_ENGINE=console
DEBUG=1
AUTH_COOKIE_KEY=if-you-see-me-1n-prod-run-away
SECURITY_SALT=DYhG93b0qyJfIxfs2guøæåubWwvniR2G0FgaC9mi
SECURITY_CIPHER_SEED=76859309657453549899991337137
SESSION_COOKIE_DOMAIN=
# SLACK_TOKEN=xoxp-...

# DB (for CakePHP and migrations)
MYSQL_URL=mysql
MYSQL_MIGRATION_URL=mysql
MYSQL_USER=wannabe
MYSQL_ROOT_PASSWORD=wannabe
MYSQL_PASSWORD=wannabe
MYSQL_DATABASE=wannabe
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ Temporary Items
composer.phar

### CakePHP2 ###
.env
/app/tmp/*
/app/Config/core.php
/app/Config/database.php
/app/Config/email.php
## @todo: Add this back after cleaning up `vendor` folder.
## /vendors/*
/app/Vendor/*

### Migrate ###
/migrate/wannabe_*
76 changes: 58 additions & 18 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,43 @@ This page explains how to set up Wannabe on you personal or local server for dev
Currently only tested on in production on php5, but should work fairly well with php7.

### Install required packages

```
$ sudo apt-get install apache2 php5 mysql-server git gettext php5-mysql php5-mcrypt php5-gd
$ sudo a2enmod rewrite
```

### Clone git repo into your home folder

```
$ cd /var/www/html && git clone git@github.com:gathering/wannabe.git
$ cd wannabe
```

### Configure .env file

Copy example .env file, populate and replace all CakePHP and DB related
variables.

```
$ cp .env.example .env
$ vim .env
```

If running things manually (and dont really use `.env` file directly) you can
modify it and use it to populate your local runtime environment instead. As an
alternative to manually adjust all relevant config files you can;

1. Insert `export` on each line before the env variable. (Ex `export A=B`)
2. Run `source .env` to populate local env

If not wanting or able to use env variables at all see list of configuration
options to change in the individual steps below.

### Setup database

First create the database and a user

```
$ mysql -u root -p
mysql> CREATE DATABASE wannabe;
Expand All @@ -32,36 +55,39 @@ Install python-pip and mysql framework and run the migration
```
$ sudo apt-get install python-dev libmysqlclient-dev python-pip
$ pip install -r migrate/requirements.txt
$ cp migrate/db-config.examples.sh migrate/db-config.sh
$ vim migrate/db-config.sh
$ cp migrate/.simple-db-migrate.example.conf migrate/.simple-db-migrate.conf
$ vim migrate/.simple-db-migrate.conf
$ vim migrate/simple-db-migrate.conf
$ vim migrate/migrate.sh
$ cd migrate && sh migrate.sh && cd ..

# Lastly configure wannabe to connect to that database

# Lastly configure wannabe to connect to that database
$ cp app/Config/database.sample.php app/Config/database.php
$ vim app/Config/database.php

# Edit the following lines:
'login' => 'wannabe',
'password' => 'wannabe',
'database' => 'wannabe',
```

Relevant env variables (replace with static values if not using env)

- MYSQL_URL
- MYSQL_MIGRATION_URL (custom DB url for migration code)
- MYSQL_USER
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE

### Development configuration

Edit the configuration file
Add basic wannabe config

```
$ cp app/Config/core.example.php app/Config/core.php
$ vim app/Config/core.php

# Change the following lines:
Configure::write('debug', 1);
session.cookie_domain' => '.domain.com' // Leave blank if localhost
$ vim app/Config/bootstrap.php
```

Relevant env variables (replace with static values if not using env)

- SESSION_COOKIE_DOMAIN (leave blank if localhost)
- DEBUG (1 during local development / 0 in production)

### Custom configuration options

#### AUTH_COOKIE_KEY
Expand All @@ -73,8 +99,20 @@ containing users credentials, so be sure it's long and random.
Sessions will still be held for about 1 week according to CakePHP session/cookie
config, but will not automatically re-login user when it expires.

#### SLACK_TOKEN

Populate this with a slack token to automatically send slack invite to user
upon enrollment.

#### LOG_ENGINE

Set to "console" when running in a container environment to log to stdout and
stderr. If not set it defaults to regular file logging.

### Create cache and files upload folders

These folder are required for caching and image uploads (even if cache it not in use)

```
$ mkdir app/tmp
$ mkdir app/tmp/sessions
Expand All @@ -87,10 +125,11 @@ $ chmod 777 app/webroot/files
```

### Edit apache configuration for the development site
Start with editing the apache default configuration file

Start with editing the apache default configuration file

**/etc/apache2/sites-enabled/000-default.conf**

```
<VirtualHost *:80>
ServerAdmin email@domain.org
Expand Down Expand Up @@ -118,8 +157,8 @@ Finally restart apache2

`$ sudo service apache2 restart`


### Create a new event

1. Make sure you have cake in path

`echo 'export PATH="/var/www/html/wannabe/lib/Cake/Console:$PATH"' >> ~/.bashrc && source ~/.bashrc`
Expand All @@ -130,6 +169,7 @@ Finally restart apache2
If `cake event` returns ": No such file or directory" try "dos2unix /var/www/html/wannabe/lib/Cake/Console/cake"

#### Default login:

```
User: dev
Pass: gramofon
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ are very varying - I'm sorry, we're working on it!)

## Docker

Some work has begun on making it possible to develop using docker. It is
not complete, largely because we're also moving to a newer php version and
ideally fixing some stupid bugs, possibly moving to at least a more recent
CakePHP, ideally CakePHP 3.

Several further tweaks are needed, but this is a start.
While docker is the intended develop and production environment, it is not
complete (and probably never will be). Largely because we're also moving to a
newer php version and ideally fixing some stupid bugs, possibly moving to at
least a more recent CakePHP, ideally CakePHP 3.

### Initial configuration:

Copy `.env.example` to `.env`

First select between development and production setup by uncommenting the
corresponding lines in `./env` file. Development is the current default.
corresponding lines in `.env` file. Development is the current default.

If running in dev mode configuration files should be created automatically from
example files when starting the container the first time if they are missing.

Most of these config files utilize environment variables from the `.env` file
for common config options, and can likely often remain unchanged from sample
files.

See `build/prepate.sh` (used for both prod and dev) and
`build/development-entrypoint.sh` (used in dev only) for manual setup steps
reference. Some of these are also referenced in `INSTALL.md`.
Expand Down Expand Up @@ -171,7 +175,7 @@ folder, including `./migrate` and has required python packages installed. So
the simplest way to run migrations is from inside the container.

```
# While the `app` container us running, do this in another terminal:
# While the `app` container is running, do this in another terminal:
$ docker-compose exec app /bin/bash
$ cd migrate
$ ./migrate.sh
Expand Down
32 changes: 7 additions & 25 deletions WORKFLOW.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Work flow in git, schema migrations and how to apply changes to production

This page explains how your general work flow should be in git and how to apply your changes to production.

## New feature

Make sure you are on the master branch before branching out.

```bash
Expand All @@ -18,6 +20,7 @@ $ git push origin <BRANCH NAME>
You can now create a pullrequest from <BRANCH NAME> into master on github.

## Making schema migrations

Migrations are handled by a python module named `simple-db-migrate`. It also requires the `python-mysqldb` package.

They can be installed with pip and requirements.txt, or with easy_install.
Expand All @@ -28,9 +31,10 @@ $ pip install -r requirements.txt

Navigate to wannabe/migrations directory to start using migrations.

You need to change settings to fit your database setup. You can find this in the file `.simple-db-migrate.conf`.
You need to change settings to fit your database setup. You can do this by adjusting variables in root `.env` file.

To create a new migration, use the shellscript new-migration.sh and include a description for its name.

```bash
$ ./new-migration.sh added_some_model
```
Expand All @@ -43,36 +47,14 @@ The numbers in the migration name is YYYYMMDDHHMMSS of creation, which is used t

Migrations are tagged with unixepoch. When migrate.sh is ran, it runs all migrations > current unixepoch.

This becomes a problem when a developer has been working on a pull request for a while, and then merges the changes into develop.
This becomes a problem when a developer has been working on a pull request for a while, and then merges the changes into develop.
If the migrations, which are usually one of the first things to be made for a new model, are created at a date earlier than the currently highest migration stored in prod, it will not automatically be ran in the routines for prod setting.

A temporary fix for this is to make sure that all migration files are renamed to the current unixepoch after they have been merged to develop, but we should probably investigate ways to automate this process.

To migrate to the latest migration, use migrate.sh with no more options. If you wish to apply more options, the shell script allows for that.
One common cause to use additional options could be to choose a migration number to migrate to.
```bash
$ ./migrate.sh 20130320120000 # This will fetch the migration which matches the timestamp.
```

## Bug fixing
General small bug fixes can be done directly on the master branch.
(If severe, consider rolling back to an earlier tag)

## Apply changes to production
On your local machine, merge in master and tag

```bash
$ git checkout master
$ git pull origin master
$ git checkout prod
$ git merge master
$ git push origin prod
$ git tag -a YYYY-MM-DDvXX # Example 2017-10-26v01
$ git push --tags
```
Now log on to wen.gathering.org and go to /srv/vhosts/wannabe.gathering.org/wannabe

```bash
$ sudo -u wannabe-web git fetch --tags
$ sudo -u wannabe-web git checkout YYYY-MM-DDvXX
$ ./migrate.sh 20130320120000 # This will fetch the migration which matches the timestamp.
```
1 change: 0 additions & 1 deletion app/Config/.gitignore

This file was deleted.

10 changes: 5 additions & 5 deletions app/Config/core.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* In production mode, flash messages redirect after a time interval.
* In development mode, you need to click the flash message to continue.
*/
Configure::write('debug', 1);
Configure::write('debug', env('DEBUG'));
/**
* Configure the Error handler used to handle errors for your application. By default
* ErrorHandler::handleError() is used. It will display errors using Debugger, when debug > 0
Expand Down Expand Up @@ -176,7 +176,7 @@
'name' => 'Wannabe',
'timeout' => '6048',
'ini' => array(
'session.cookie_domain' => ''
'session.cookie_domain' => env('SESSION_COOKIE_DOMAIN'),
)
));

Expand All @@ -188,12 +188,12 @@
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guøæåubWwvniR2G0FgaC9mi');
Configure::write('Security.salt', env('SECURITY_CIPHER_SEED'));

/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
Configure::write('Security.cipherSeed', '76859309657453549899991337137');
Configure::write('Security.cipherSeed', env('SECURITY_SALT'));

/**
* Apply timestamps with the last modified time to static assets (js, css, images).
Expand Down Expand Up @@ -349,4 +349,4 @@
* LEGACY TOKEN
*/

Configure::write('Slack.token', '');
Configure::write('Slack.token', env('SLACK_TOKEN'));
24 changes: 14 additions & 10 deletions app/Config/database.sample.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'mysql',
'login' => 'wannabe',
'password' => 'wannabe',
'database' => 'wannabe',
'prefix' => 'wb4_',
'encoding' => 'utf8',
);
public $default;

public function __construct(){
$this->default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => env('MYSQL_URL'),
'login' => env('MYSQL_USER'),
'password' => env('MYSQL_PASSWORD'),
'database' => env('MYSQL_DATABASE'),
'prefix' => 'wb4_',
'encoding' => 'utf8',
);
}
}
Loading