Skip to content

Commit

Permalink
Merge pull request #102 from LinkValue/feature/app-images
Browse files Browse the repository at this point in the history
Support application images
  • Loading branch information
Oliboy50 committed Mar 23, 2018
2 parents c85d5b6 + e7ddfe4 commit 09042d6
Show file tree
Hide file tree
Showing 74 changed files with 2,148 additions and 949 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
!/bin/console
!/bin/symfony_requirements

# assets
# assets, uploads
/node_modules/
/web/assets/*
!/web/assets/.gitkeep
/web/uploads/*
!/web/uploads/.gitkeep

# PHP-CS-Fixer
/.php_cs.*
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ php:

before_script:
- nvm install "$(jq -r '.engines.node' package.json)"
- make install-bin-dev install-bin-prod install-composer install-npm db-build clean
- make install-bin-dev install-bin-prod install-composer install-npm db-build assets-build

script:
- npm run lint
Expand Down
14 changes: 6 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ Note: If it unluckily fails at some point, don't hesitate to re-run this command
```shell
# connect to the VM
make ssh
# install the project for development (you'll have to press "Enter" several times to keep default parameters)
# install the project for development (you'll have to press "Enter" several times to configure the project with default parameters)
make install
# serve assets for development environment
npm start
```

#### 4. Enjoy

You should see your application up and running at http://appbuild.dev/app_dev.php/
You should see your application up and running at http://local.appbuild.com/app_dev.php/

Try to login using one of the following credentials:
```
Expand All @@ -46,13 +44,13 @@ [email protected] => user

Front assets (css/js/images) are handled by [Webpack](https://webpack.js.org/).

When you're in development environment (i.e. `http://appbuild.dev/app_dev.php/...`), the project is configured to use webpack dev server to serve assets, it means that the project will seems to be broken until you run the following command:
When you're in production environment (i.e. `http://local.appbuild.com/...`), the project will use the assets found in `web/assets`, it means that you'll have to run `make assets-build` each time you edit an asset file to see the modification in your browser (after refreshing it manually).

When you're in development environment (i.e. `http://local.appbuild.com/app_dev.php/...`), you can also watch asset modifications to benefit from the hot reloading feature of webpack-dev-server, by typing the following command:
```shell
npm start
make assets-watch
```

When you're in production environment (i.e. `http://appbuild.dev/...`), the project will use the assets found in `web/assets`, it means that you'll have to run `npm run build` each time you edit an asset file to see the modification in your browser (after refreshing it).

### Common tasks
```shell
# rebuild the whole database with clean fixtures
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: provision start stop ssh destroy rebuild clean install update
.PHONY: provision start stop ssh destroy rebuild clean install update clean

#
# Main targets
Expand Down Expand Up @@ -56,7 +56,7 @@ install-jwt:
test -f var/jwt/private.pem || openssl genrsa -out var/jwt/private.pem -passout pass:Appbuild -aes256 4096
test -f var/jwt/public.pem || openssl rsa -in var/jwt/private.pem -passin pass:Appbuild -pubout -out var/jwt/public.pem

install: install-bin-dev install-bin-prod install-composer install-jwt install-npm db-build assets-build clean
install: install-bin-dev install-bin-prod install-composer install-jwt install-npm db-build assets-build

# Update
update: update-composer clean
Expand Down Expand Up @@ -84,12 +84,14 @@ db-update:
php bin/console doctrine:migrations:migrate -n

# Assets
assets-build:
npm run build
assets-build: clean npm-build

assets-watch:
assets-watch: clean
npm start

npm-build:
npm run build

# Production
prod-install: install-bin-prod
SYMFONY_ENV=prod php bin/composer install --no-dev --optimize-autoloader --no-interaction
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Appbuild is a "simple" [Symfony 3.3](http://symfony.com/doc/3.3/index.html) appl
- [Linux](https://getgnulinux.org) (it may works on Windows/macOS but you can't blame us if it doesn't)
- [`php 5.6.19+`](http://php.net) (`php 7+` is recommended)
- [`MySQL`](https://www.mysql.com) (it should also work using [`MariaDB`](https://mariadb.org), if not => please let us know)
- [`Node.js`](https://nodejs.org) along with `npm` (it works great with `npm 5.2.0` for instance)
- [`Node.js`](https://nodejs.org) along with `npm` (it works great with `npm 5.7.1` for instance)
- HTTP server supporting PHP (such as [`nginx`](http://nginx.org) + [`php-fpm`](http://php.net/manual/fr/install.fpm.php), etc.)

### Application setup
Expand Down Expand Up @@ -68,6 +68,13 @@ More documentation for specific HTTP servers:

## API documentation

*WARNING*

*This API is still in BETA, it may be strongly updated.*
*Please be really careful before updating this project if you were already using the API.*

*/WARNING*

Before using the API, you must read [this documentation about how to be authenticated on the API side](doc/api/authentication.md).

- [/api/application](doc/api/application.md)
Expand Down
2 changes: 1 addition & 1 deletion ansible/vagrant-parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vm_ip: '192.168.100.70'
# List of aliases bound to the Virtual Machine's IP (see "vm_ip")
# If the plugin "vagrant-hostmanager" is installed, these aliases will be added to your "/etc/hosts" file automatically.
# Else, aliases will be displayed in the console during VM provisioning, then it will be up to you to copy/paste this output in your "/etc/hosts" file.
vm_ip_aliases: ['appbuild.dev']
vm_ip_aliases: ['local.appbuild.com']

# VM hostname (this will be added to the "vm_ip_aliases" list, displayed in your SSH terminal, etc.)
vm_hostname: 'appbuild'
Expand Down
2 changes: 1 addition & 1 deletion ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
workspace: '/var/www/Appbuild'

sites:
- { name: 'Appbuild', server_name: 'appbuild.dev', template: 'vhost.symfony.j2', client_max_body_size: '1024M' }
- { name: 'Appbuild', server_name: 'local.appbuild.com', template: 'vhost.symfony.j2', client_max_body_size: '1024M' }

mysql:
users:
Expand Down
18 changes: 17 additions & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,25 @@ public function registerContainerConfiguration(LoaderInterface $loader)
// Handle webpack-dev-server assets dynamically served
if ($this->getEnvironment() === 'dev') {
$loader->load(function (ContainerBuilder $container) {
// Check if webpack dev server is up before using it
@file_get_contents($container->getParameter('webpack_dev_server_base_url'));
if (!isset($http_response_header)) {
return;
}

// Override "framework.assets.packages.static" configuration to use webpack dev server
$container->loadFromExtension('framework', [
'assets' => [
'base_url' => 'http://'.$container->getParameter('webpack_dev_server_host').':8080',
'packages' => [
'static' => [
'base_path' => null,
'base_url' => sprintf(
'%s/%s',
rtrim($container->getParameter('webpack_dev_server_base_url'), '/'),
$container->getParameter('static_assets_base_path')
),
],
],
],
]);
});
Expand Down
36 changes: 36 additions & 0 deletions app/DoctrineMigrations/Version20171019161456.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171019161456 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE appbuild_application ADD display_image_file_path VARCHAR(510) DEFAULT NULL, ADD full_size_image_file_path VARCHAR(510) DEFAULT NULL');
$this->addSql('ALTER TABLE appbuild_build CHANGE file_path file_path VARCHAR(510) DEFAULT NULL');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE appbuild_application DROP display_image_file_path, DROP full_size_image_file_path');
$this->addSql('ALTER TABLE appbuild_build CHANGE file_path file_path VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci');
}
}
21 changes: 15 additions & 6 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ imports:
- { resource: 'parameters.yml' }
- { resource: 'security.yml' }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

# Locales
routing_locales: '(fr|en)'
enabled_locales: ['fr', 'en']

# Miscellaneous
# Assets
static_assets_base_path: 'assets' # corresponding to __STATIC_ASSETS_BASE_PATH__ value in webpack.config.js
uploads_assets_base_path: 'uploads'

# Application images
application_images_webroot_relative_dir: '%uploads_assets_base_path%/application_images'
application_images_dir: '%kernel.project_dir%/web/%application_images_webroot_relative_dir%'

# API
build_token_ttl: 600 # seconds

framework:
Expand All @@ -19,7 +25,7 @@ framework:
default_locale: '%default_locale%'
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
Expand All @@ -28,12 +34,14 @@ framework:
engines: ['twig']
trusted_hosts: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: 'session.handler.native_file'
save_path: '%session_save_path%'
fragments: ~
http_method_override: true
assets: ~
assets:
packages:
static:
base_path: '%static_assets_base_path%'
php_errors:
log: true

Expand All @@ -44,6 +52,7 @@ twig:
- 'bootstrap_3_layout.html.twig'
globals:
timezone: '%timezone%'
application_images_webroot_relative_dir: '%application_images_webroot_relative_dir%'

doctrine:
dbal:
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ imports:

framework:
router:
resource: '%kernel.root_dir%/config/routing_dev.yml'
resource: '%kernel.project_dir%/app/config/routing_dev.yml'
strict_requirements: true
profiler: { only_exceptions: false }

Expand Down
15 changes: 7 additions & 8 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This file is a "template" of what your parameters.yml file should look like
# Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production.
# http://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
# Set parameters here which may be different on each deployment target of this app, e.g. development, staging, production.
parameters:
# Database configurations
database_host: '127.0.0.1'
Expand All @@ -16,14 +15,14 @@ parameters:
mailer_user: ~
mailer_password: ~

# A secret key that's used to generate certain security-related tokens
# A secret key that's used to generate some security-related tokens
secret: 'ThisTokenIsNotSoSecretChangeIt'

# webpack-dev-server (to watch assets modification in development environment)
webpack_dev_server_host: 'appbuild.dev' # could be 'localhost' if you're not using the provided Vagrant environment
webpack_dev_server_base_url: 'http://local.appbuild.com:8080' # could be 'http://localhost:8080' if you're not using the provided Vagrant environment

# Symfony session path (set this to '/tmp/sessions' for example if you encounter some issues in dev environment)
session_save_path: '%kernel.root_dir%/../var/sessions/%kernel.environment%'
session_save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'

# Default locale
default_locale: 'en' # supported values are 'en' and 'fr'
Expand All @@ -32,10 +31,10 @@ parameters:
timezone: 'UTC' # any PHP timezone (such as 'Europe/Paris') is supported. See http://php.net/manual/fr/timezones.php for complete list.

# Path to the directory where builds file will be stored
builds_application_dir: '%kernel.root_dir%/../var/build_files'
builds_application_dir: '%kernel.project_dir%/var/build_files'

# JWT parameters for API authentication
jwt_private_key_path: '%kernel.root_dir%/../var/jwt/private.pem' # ssh private key path
jwt_public_key_path: '%kernel.root_dir%/../var/jwt/public.pem' # ssh public key path
jwt_private_key_path: '%kernel.project_dir%/var/jwt/private.pem' # ssh private key path
jwt_public_key_path: '%kernel.project_dir%/var/jwt/public.pem' # ssh public key path
jwt_key_pass_phrase: 'Appbuild' # ssh key pass phrase
jwt_token_ttl: 31536000 # Approximately one year
2 changes: 1 addition & 1 deletion app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ security:
firewalls:
# disables authentication for assets and the profiler
dev:
pattern: '^/(_(profiler|wdt)|assets)/'
pattern: '^/(_(profiler|wdt)|assets|uploads)/'
security: false

# API security
Expand Down
11 changes: 5 additions & 6 deletions doc/api/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GET /api/build/{id}
"version": "1.5.2",
"comment": "This is a comment for this build.\nWith a line break.\nAnd another one.\n",
"is_latest": true,
"download_link": "http://app-build.dev/app_dev.php/fr/application/1/build/1/download",
"download_link": "http://my-appbuild.domain/fr/application/1/build/1/download",
"application": {
"id": 1
}
Expand All @@ -42,7 +42,7 @@ GET /api/application/{application_id}/build
"version": "1.5.2",
"comment": "This is a comment for this build.\nWith a line break.\nAnd another one.\n",
"is_latest": true,
"download_link": "http://app-build.dev/app_dev.php/fr/application/1/build/1/download",
"download_link": "http://my-appbuild.domain/fr/application/1/build/1/download",
"application": {
"id": 1
}
Expand All @@ -67,7 +67,7 @@ GET /api/application/{application_id}/build/latest
"id": 1,
"version": "1.5.2",
"comment": "This is a comment for this build.\nWith a line break.\nAnd another one.\n",
"download_link": "http://app-build.dev/app_dev.php/fr/application/1/build/1/download"
"download_link": "http://my-appbuild.domain/fr/application/1/build/1/download"
}
```

Expand All @@ -94,19 +94,18 @@ PUT /api/application/{application_id}/build
```json
{
"build_id": 4,
"upload_location": "http://app-build.domain/api/build/4/file"
"upload_location": "http://my-appbuild.domain/api/build/4/file"
}
```

## Upload a file for a build

Note: This route is given by `Create a new build` through `upload_location` response field.
`filename` query param should match the build type (`ipa` or `apk`).

### Request

```
PUT /api/build/{build_id}/file?filename={filename}
PUT /api/build/{build_id}/file
```

```
Expand Down
Loading

0 comments on commit 09042d6

Please sign in to comment.