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

ローカル開発環境の整備 #4

Merged
merged 1 commit into from Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions .env
@@ -0,0 +1,49 @@
APP_NAME=${APP_NAME_C}
APP_ENV=${APP_ENV_C}
APP_KEY=${APP_KEY_C}
APP_DEBUG=${APP_DEBUG_C}
APP_URL=${APP_URL_C}

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=${DB_HOST_C}
DB_PORT=${DB_PORT_C}
DB_DATABASE=${DB_DATABASE_C}
DB_USERNAME=${DB_USERNAME_C}
DB_PASSWORD=${DB_PASSWORD_C}

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME_C}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=ap-northeast-1
AWS_BUCKET=

PUSHER_APP_ID=${PUSHER_APP_ID_C}
PUSHER_APP_KEY=${PUSHER_APP_KEY_C}
PUSHER_APP_SECRET=${PUSHER_APP_SECRET_C}
PUSHER_APP_CLUSTER=${PUSHER_APP_CLUSTER_C}

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY_C}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER_C}"

MIX_RECAPTCHA_SITE_KEY="${RECAPTCHA_SITE_KEY_C}"
MIX_APP_ENV="${APP_ENV_C}"
46 changes: 0 additions & 46 deletions .env.example

This file was deleted.

9 changes: 8 additions & 1 deletion .gitignore
Expand Up @@ -3,9 +3,16 @@
/public/storage
/public/js/app.js
/public/css/app.css
/bootstrap/cache
/storage/*.key
/storage/framework/cache
/storage/framework/sessions
/storage/framework/testing
/storage/framework/views
/storage/logs
/vendor
.env
/infrastructure/.env
#.env
.env.backup
.phpunit.result.cache
Homestead.json
Expand Down
34 changes: 34 additions & 0 deletions Makefile
@@ -0,0 +1,34 @@
.PHONY:


help:
cat Makefile


vendor: composer.json composer.lock
composer self-update
composer validate
composer install

dump:
composer dump-autoload

clear:
composer clear-cache
php artisan view:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache

opt: clear
php artisan cache:clear
#php artisan optimize

clr: opt dump


test:
vendor/bin/phpunit --configuration=phpunit.xml

#e2e:
# php artisan dusk
21 changes: 21 additions & 0 deletions infrastructure/.env.local
@@ -0,0 +1,21 @@
APP_NAME_C=SocialBooster
APP_ENV_C=local
APP_KEY_C=
APP_DEBUG_C=true
APP_URL_C=http://localhost:3080

WEB_PORT_C=3080

DB_HOST_C=db
DB_PORT_C=3306
DB_NAME_C=social-booster_local
DB_USER_C=user
DB_PASS_C=pass
DB_ROOT_PASS_C=secret

PUSHER_APP_ID_C=
PUSHER_APP_KEY_C=
PUSHER_APP_SECRET_C=
PUSHER_APP_CLUSTER_C=mt1

RECAPTCHA_SITE_KEY_C=
83 changes: 83 additions & 0 deletions infrastructure/README.md
@@ -0,0 +1,83 @@
# SocialBooster infrastructure

SocialBooster の環境整備コード一式


## PreRequirements

- `Docker` installed.
- `Docker Compose` installed.
- [social-booster](https://github.com/syuumu200/social-booster) cloned.


## 操作方法

### local

#### 起動

```
cd /path/to/social-booster/infrastructure

cp -p .env.local .env

docker-compose up -d

(・・・)

docker-compose exec app bash
```


(In container)

```
chmod 666 -R storage # コンテナ構築後の1回のみでOK
chmod 666 -R bootstrap/cache # コンテナ構築後の1回のみでOK

make vendor # composer install ほか を実行

php artisan migrate
```


#### Vue.js ビルド

(起動: docker-compose up -d されている前提)

```
cd /path/to/social-booster/infrastructure

docker-compose exec web ash
```


(In container)

```
npm i # コンテナ作成直後の1回だけでOK

npm run dev

# npm rebuild node-sass # npm run dev が失敗した場合に試してみてください
```


#### 画面表示

(Use your web browser)

```
open http://localhost:3080/
```




## Note
- Laravel のキャッシュ類をクリアする際は、appコンテナ内で
(docker-compose exec app bash)
`make clr` を行ってください

- この環境整備コード一式は、[最強のLaravel開発環境をDockerを使って構築する【新編集版】 - Qiita](https://qiita.com/ucan-lab/items/5fc1281cd8076c8ac9f4) を参考に整備しています
- https://github.com/ucan-lab/docker-laravel
55 changes: 55 additions & 0 deletions infrastructure/docker-compose.yml
@@ -0,0 +1,55 @@
version: "3"

volumes:
php-fpm-socket:
db-store:

services:
app:
build:
context: .
dockerfile: ./docker/php/Dockerfile
volumes:
- php-fpm-socket:/var/run/php-fpm
- ../:/work
environment:
- DB_HOST_C=${DB_HOST_C}
- DB_PORT_C=${DB_PORT_C}
- DB_DATABASE_C=${DB_NAME_C}
- DB_USERNAME_C=${DB_USER_C}
- DB_PASSWORD_C=${DB_PASS_C}
- APP_NAME_C=${APP_NAME_C}
- APP_ENV_C=${APP_ENV_C}
- APP_KEY_C=${APP_KEY_C}
- APP_DEBUG_C=${APP_DEBUG_C}
- APP_URL_C=${APP_URL_C}
- WEB_PORT_C=${WEB_PORT_C}
- PUSHER_APP_ID_C=${PUSHER_APP_ID_C}
- PUSHER_APP_KEY_C=${PUSHER_APP_KEY_C}
- PUSHER_APP_SECRET_C=${PUSHER_APP_SECRET_C}
- PUSHER_APP_CLUSTER_C=${PUSHER_APP_CLUSTER_C}

web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- ${WEB_PORT_C:-80}:80
volumes:
- php-fpm-socket:/var/run/php-fpm
- ../:/work
env_file:
- ../.env
db:
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
ports:
- ${DB_PORT_C}:3306
volumes:
- db-store:/var/lib/mysql
environment:
- MYSQL_DATABASE=${DB_NAME_C}
- MYSQL_USER=${DB_USER_C}
- MYSQL_PASSWORD=${DB_PASS_C}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASS_C}
5 changes: 5 additions & 0 deletions infrastructure/docker/mysql/Dockerfile
@@ -0,0 +1,5 @@
FROM mysql:8.0

ENV TZ=UTC

COPY ./docker/mysql/my.cnf /etc/my.cnf
26 changes: 26 additions & 0 deletions infrastructure/docker/mysql/my.cnf
@@ -0,0 +1,26 @@
[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_0900_ai_ci

# timezone
default-time-zone = SYSTEM
log_timestamps = SYSTEM

# Error Log
log-error = mysql-error.log

# Slow Query Log
slow_query_log = 1
slow_query_log_file = mysql-slow.log
long_query_time = 1.0
log_queries_not_using_indexes = 0

# General Log
general_log = 1
general_log_file = mysql-general.log

[mysql]
default-character-set = utf8mb4

[client]
default-character-set = utf8mb4
21 changes: 21 additions & 0 deletions infrastructure/docker/nginx/Dockerfile
@@ -0,0 +1,21 @@
#FROM node:14.2-alpine as node
FROM node:12.3.1-alpine as node
FROM nginx:1.18-alpine

SHELL ["/bin/ash", "-oeux", "pipefail", "-c"]

ENV TZ=UTC

RUN apk update && \
apk add --update --no-cache --virtual=.build-dependencies g++

# node command
COPY --from=node /usr/local/bin /usr/local/bin
# npm command
COPY --from=node /usr/local/lib /usr/local/lib
# yarn command
COPY --from=node /opt /opt
# nginx config file
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /work