Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Tmp docker environment #117

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ad0fa21
init front
tamakiii Sep 24, 2020
a62f182
init golang
tamakiii Sep 24, 2020
473b52f
init ruby
tamakiii Sep 24, 2020
40e6236
.dockerignore
tamakiii Sep 24, 2020
3db8955
.gitignore
tamakiii Sep 24, 2020
2a3694b
init docker-compose.yml
tamakiii Sep 24, 2020
5518994
init mysql
tamakiii Sep 24, 2020
f84bc74
tmp add initdb.d
tamakiii Sep 24, 2020
c29c4a0
init php/Dockerfile
tamakiii Sep 25, 2020
ba319b4
docker.mk for language switch
tamakiii Sep 25, 2020
b6355d8
composer create-project slim/slim-skeleton
tamakiii Sep 25, 2020
c375969
Revert "composer create-project slim/slim-skeleton"
tamakiii Sep 25, 2020
876cfd3
spiral/app-grpc deps
tamakiii Sep 25, 2020
d55a278
pecl install protobuf
tamakiii Sep 25, 2020
f859b6f
Merge remote-tracking branch 'origin/master' into tmp-docker-environment
tamakiii Sep 27, 2020
30d3a50
init webapp/php/grpc
tamakiii Sep 27, 2020
73faa5a
add ruby/grpc
tamakiii Sep 27, 2020
7edba2c
fix port
tamakiii Sep 27, 2020
403e4d5
fix port
tamakiii Sep 27, 2020
5489bc7
Revert "Revert "composer create-project slim/slim-skeleton""
tamakiii Sep 27, 2020
31e7f9f
mv to web
tamakiii Sep 27, 2020
a1dab68
fix WORKDIR
tamakiii Sep 27, 2020
1eb8d4b
link frontend files
tamakiii Sep 27, 2020
c4ca917
fix
tamakiii Sep 27, 2020
d274593
ln -> cp
tamakiii Sep 27, 2020
97d60cd
link public
tamakiii Sep 27, 2020
3b72efa
init nginx
tamakiii Sep 27, 2020
c456c61
using php-fpm
tamakiii Sep 27, 2020
206f681
using nginx
tamakiii Sep 27, 2020
d13396f
composer require google/protobuf
tamakiii Sep 27, 2020
fbec2e8
mv Dockerfile
tamakiii Sep 27, 2020
e8e6fb9
add protobuf-compiler
tamakiii Sep 27, 2020
56e2525
fix mount path
tamakiii Sep 27, 2020
5eb795e
add make protoc
tamakiii Sep 27, 2020
341e7e4
protoc --php_out=./src/Protobuf
tamakiii Sep 27, 2020
d1b3921
src/Protobuf -> lib
tamakiii Sep 27, 2020
e846daf
src/Protobuf -> lib
tamakiii Sep 27, 2020
9452613
add autoloda
tamakiii Sep 27, 2020
5d400da
rm Google\\Protobuf
tamakiii Sep 27, 2020
054623c
fix autoload
tamakiii Sep 27, 2020
b17d236
tmp impl /api/session
tamakiii Sep 27, 2020
a09da10
tmp impl send_web_push.php
tamakiii Sep 27, 2020
299f4c2
merge apt-get install and add bcmath
tamakiii Sep 27, 2020
7b52162
add environments
tamakiii Sep 27, 2020
27cb7a6
init PDO
tamakiii Sep 27, 2020
8a622fa
implementing /api/session
tamakiii Sep 27, 2020
0e98ded
tmp impl notifier
tamakiii Sep 27, 2020
b3f58e9
impl /initialize
tamakiii Sep 27, 2020
ee1d0f1
Merge remote-tracking branch 'origin/master' into tmp-docker-environment
tamakiii Sep 27, 2020
92a0c84
composer require minishlink/web-push
tamakiii Sep 29, 2020
6ffa7a5
Merge remote-tracking branch 'origin/master' into tmp-docker-environment
tamakiii Sep 29, 2020
1f3f658
using v6.0.1
tamakiii Sep 29, 2020
ff2b3ba
add vapid_private.pem
tamakiii Sep 29, 2020
32083b3
add gmp and format
tamakiii Sep 29, 2020
58ab356
add push_vapid_key to /api/session
tamakiii Sep 29, 2020
86947e6
fix
tamakiii Sep 29, 2020
2648416
composer require symfony/http-foundation
tamakiii Sep 29, 2020
be9d47b
impl /api/admin/clarifications
tamakiii Sep 29, 2020
74c8b93
impl /api/admin/clarifications/{id}
tamakiii Sep 29, 2020
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 webapp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/frontend/node_modules/
2 changes: 2 additions & 0 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/docker-compose.override.yml
/frontend/node_modules/
30 changes: 30 additions & 0 deletions webapp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.7"
services:
frontend:
build: ./frontend
volumes:
- ..:/isucon10/isucon10-final

golang:
build: ./golang
environment:
- NODE_ENV=development
volumes:
- ..:/isucon10/isucon10-final
ports:
- 9291:9291

mysql:
image: mysql:5.7
volumes:
- mysqldata:/var/lib/mysql
- ./sql/setup.sql:/docker-entrypoint-initdb.d/00_setup.sql
- ./sql/schema.sql:/docker-entrypoint-initdb.d/01_schema.sql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xsuportal
MYSQL_USER: isucon
MYSQL_PASSWORD: isucon

volumes:
mysqldata:
10 changes: 10 additions & 0 deletions webapp/docker.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: ruby php

ruby: ruby/docker-compose.override.yml
ln -s $< docker-compose.override.yml

php: php/docker-compose.override.yml
ln -s $< docker-compose.override.yml

clean:
rm docker-compose.override.yml
5 changes: 5 additions & 0 deletions webapp/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:14.11.0

WORKDIR /isucon10/isucon10-final/webapp/frontend

CMD ["make", "install", "watch"]
23 changes: 23 additions & 0 deletions webapp/frontend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: help install dependencies build watch clean

help:
@cat $(firstword $(MAKEFILE_LIST))

install: \
dependencies \
node_modules \
build

node_modules:
yarn install

build:
npm run build

watch:
npm run watch

clean:
rm -rf node_modules
rm -rf public/sw.js
rm -rf public/sw.js.map
5 changes: 5 additions & 0 deletions webapp/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM golang:1.15.2

WORKDIR /isucon10/isucon10-final/webapp/golang

CMD ["make", "run"]
17 changes: 17 additions & 0 deletions webapp/php/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.7"
services:
nginx:
build: ./php/nginx
volumes:
- ..:/isucon10/isucon10-final
ports:
- 8081:80

php:
build: ./php/web
environment:
- MYSQL_HOSTNAME=mysql
- MYSQL_PORT=3306
- docker=1
volumes:
- ..:/isucon10/isucon10-final
20 changes: 20 additions & 0 deletions webapp/php/grpc/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 4
8 changes: 8 additions & 0 deletions webapp/php/grpc/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Debug mode disabled view cache and enabled higher verbosity.
DEBUG = true

# Set to application specific value, used to encrypt/decrypt cookies and etc.
ENCRYPTER_KEY = {encrypt-key}

# Set to TRUE to disable confirmation in `migrate` commands.
SAFE_MIGRATIONS = true
7 changes: 7 additions & 0 deletions webapp/php/grpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
vendor
runtime
composer.lock
rr*
.env
spiral*
25 changes: 25 additions & 0 deletions webapp/php/grpc/.rr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# grpc service configuration.
grpc:
listen: tcp://0.0.0.0:50051
proto: "proto/service.proto"
workers.command: "php app.php"
tls.key: "app.key"
tls.cert: "app.crt"

# queue and jobs
jobs:
dispatch:
app-job-*.pipeline: "local"
pipelines:
local:
broker: "ephemeral"
consume: ["local"]

workers:
command: "php app.php"
pool.numWorkers: 2

# control the max memory usage
limit:
services:
grpc.maxMemory: 100
21 changes: 21 additions & 0 deletions webapp/php/grpc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Spiral Scout

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 98 additions & 0 deletions webapp/php/grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Spiral GRPC Application Skeleton [![Latest Stable Version](https://poser.pugx.org/spiral/app-grpc/version)](https://packagist.org/packages/spiral/app-grpc)

<img src="https://user-images.githubusercontent.com/796136/67560465-9d827780-f723-11e9-91ac-9b2fafb027f2.png" height="135px" alt="Spiral Framework" align="left"/>

Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components. The Framework execution model based on a hybrid runtime where some services (GRPC, Queue, WebSockets, etc.) handled by Application Server [RoadRunner](https://github.com/spiral/roadrunner) and the PHP code of your application stays in memory permanently (anti-memory leak tools included).

[App Skeleton](https://github.com/spiral/app) ([CLI](https://github.com/spiral/app-cli), [GRPC](https://github.com/spiral/app-grpc)) | [**Documentation**](https://spiral.dev/docs) | [Twitter](https://twitter.com/spiralphp) | [CHANGELOG](/CHANGELOG.md) | [Contributing](https://github.com/spiral/guide/blob/master/contributing.md)

<br/>

Server Requirements
--------
Make sure that your server is configured with following PHP version and extensions:
* PHP 7.2+, 64bit
* **mb-string** extension
* PDO Extension with desired database drivers
* [Install](https://github.com/protocolbuffers/protobuf/tree/master/php) `protobuf-ext` to gain higher performance.

Application Bundle
--------
Application bundle includes the following components:
* GRPC Server server based on [RoadRunner](https://roadrunner.dev)
* Console commands via Symfony/Console
* Queue support for AMQP, Beanstalk, Amazon SQS, in-Memory
* DBAL and migrations support
* Monolog, Dotenv
* Prometheus metrics
* [Cycle DataMapper ORM](https://github.com/cycle)

Installation
--------
```
composer create-project spiral/app-grpc
```

> Application server will be downloaded automatically (`php-curl` and `php-zip` required).

Once the application is installed you can ensure that it was configured properly by executing:

```
$ php ./app.php configure
```

## Running GRPC Server
In order to run GRPC server you must specify location of server key and certificate in `.rr.yaml` file:

```yaml
grpc:
listen: tcp://0.0.0.0:50051
proto: "proto/service.proto"
workers.command: "php app.php"
tls.key: "app.key"
tls.cert: "app.crt"
```

To issue local certificate:

```
$ openssl req -newkey rsa:2048 -nodes -keyout app.key -x509 -days 365 -out app.crt
```

To start application server execute:

```
$ ./spiral serve -v -d
```

On Windows:

```
$ spiral.exe serve -v -d
```

You can test your endpoints using any GRPC client. For example using [grpcui](https://github.com/fullstorydev/grpcui):

```
$ grpcui -insecure -import-path ./proto/ -proto service.proto localhost:50051
```

> Make sure to use `-insecure` option while using a self-signed certificate.

Generating Services
--------
In order to compile protobuf declarations into service code make sure to install:
* [protoc compiler](https://github.com/protocolbuffers/protobuf)
* [protoc-gen-php-grpc plugin](https://github.com/spiral/php-grpc)

To update or generate service code for your application run:

```
$ php ./app.php grpc:generate proto/service.proto
```

Generated code will be available in `app/src/Service`. Implemented service will be automatically registered in your application.

License:
--------
MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by [Spiral Scout](https://spiralscout.com).
37 changes: 37 additions & 0 deletions webapp/php/grpc/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of Spiral package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use App\App;

//
// If you forgot to configure some of this in your php.ini file,
// then don't worry, we will set the standard environment
// settings for you.
//

mb_internal_encoding('UTF-8');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'stderr');

//
// Register Composer's auto loader.
//
require __DIR__ . '/vendor/autoload.php';


//
// Initialize shared container, bindings, directories and etc.
//
$app = App::init(['root' => __DIR__]);

if ($app !== null) {
$app->serve();
}
45 changes: 45 additions & 0 deletions webapp/php/grpc/app/config/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This file is part of Spiral package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

return [
/**
* Default database connection
*/
'default' => 'default',

/**
* The Spiral/Database module provides support to manage multiple databases
* in one application, use read/write connections and logically separate
* multiple databases within one connection using prefixes.
*
* To register a new database simply add a new one into
* "databases" section below.
*/
'databases' => [
'default' => [
'driver' => 'sqlite'
],
],

/**
* Each database instance must have an associated connection object.
* Connections used to provide low-level functionality and wrap different
* database drivers. To register a new connection you have to specify
* the driver class and its connection options.
*/
'drivers' => [
'sqlite' => [
'driver' => \Spiral\Database\Driver\SQLite\SQLiteDriver::class,
'connection' => 'sqlite:' . directory('root') . 'app.db',
'profiling' => true,
],
]
];
Loading