Commit 6707bbca authored by i.vasilenko@iq-adv.ru's avatar i.vasilenko@iq-adv.ru
Browse files

Merge branch 'init-docker' into 'main'

init docker

See merge request !1
parents c46b33ac 310b8bf9
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+2 −0
Original line number Diff line number Diff line
app/vendor/
app/node_modules/

.env.example

0 → 100644
+18 −0
Original line number Diff line number Diff line
CONTAINER_NAME=

APP_BASE_DIR=./app

# Nginx
HTTP_PORT=80

# База данных (PostreSQL)
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_ROOT_USERNAME=
DB_PORT=
GROUP_ID=1000
USER_ID=1000

# IDE
XDEBUG_IDE_KEY=myproject

.gitignore

0 → 100644
+4 −0
Original line number Diff line number Diff line
/.idea/
/.vscode/

.env

Makefile

0 → 100644
+67 −0
Original line number Diff line number Diff line
.DEFAULT_GOAL:=help

COMPOSE_PREFIX_CMD := DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1

COMMAND ?= /bin/sh

# --------------------------

.PHONY: deploy up build-up build down start stop logs images ps command \
	command-root shell-root shell restart rm help

deploy:			## Start using Prod Image in Prod Mode
	${COMPOSE_PREFIX_CMD} docker compose -f compose.prod.yaml up --build -d

up:				## Start service
	@echo "Starting Application \n (note: Web container will wait App container to start before starting)"
	${COMPOSE_PREFIX_CMD} docker compose up -d

build-up:       ## Start service, rebuild if necessary
	${COMPOSE_PREFIX_CMD} docker compose up --build -d

build:			## Build The Image
	${COMPOSE_PREFIX_CMD} docker compose build --no-cache

down:			## Down service and do clean up
	${COMPOSE_PREFIX_CMD} docker compose down

start:			## Start Container
	${COMPOSE_PREFIX_CMD} docker compose start

stop:			## Stop Container
	${COMPOSE_PREFIX_CMD} docker compose stop

logs:			## Tail container logs with -n 1000
	@${COMPOSE_PREFIX_CMD} docker compose logs --follow --tail=100

images:			## Show Image created by this Makefile (or docker compose in docker)
	@${COMPOSE_PREFIX_CMD} docker compose images

ps:			    ## Show Containers Running
	@${COMPOSE_PREFIX_CMD} docker compose ps

command:	    ## Execute command ( make command COMMAND=<command> )
	@${COMPOSE_PREFIX_CMD} docker compose run --rm app ${COMMAND}

command-root:	## Execute command as root ( make command-root COMMAND=<command> )
	@${COMPOSE_PREFIX_CMD} docker compose run --rm -u root app ${COMMAND}

shell-root:		## Enter container shell as root
	@${COMPOSE_PREFIX_CMD} docker compose exec -u root app /bin/sh

shell:			## Enter container shell
	@${COMPOSE_PREFIX_CMD} docker compose exec app /bin/sh

restart:		## Restart container
	@${COMPOSE_PREFIX_CMD} docker compose restart

rm:				## Remove current container
	@${COMPOSE_PREFIX_CMD} docker compose rm -f

clear:
	 docker image prune --filter dangling=true

help:       	## Show this help.
	@echo "\n\nMake Application Docker Images and Containers using Docker-Compose files"
	@echo "Make sure you are using \033[0;32mDocker Version >= 20.1\033[0m & \033[0;32mDocker-Compose >= 1.27\033[0m "
	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m<target>\033[0m ENV=<prod|dev> (default: dev)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
 No newline at end of file
+94 −93
Original line number Diff line number Diff line
# Symfony Trainee
# Docker Compose шаблон для PHP проекта
> Шаблон основан на репозитории https://github.com/sherifabdlnaby/kubephp.
> Отдельное спасибо Паше.

## Конфигурация

| image      | version |
|------------|---------|
| PHP        | 8.3.6   |
| Xdebug     | 3.3.2   |
| Nginx      | 1.25    |
| PostgreSQL | 16      | 

## Getting started
## Для каких проектов подходит этот шаблон?
Шаблон подходит для проектов, у которых публичные файлы находятся папке `{путь до корня проекта}/public/`.
В этой папке должны находиться такие файлы как:
1. index.php;
2. изображения и другие медиа файлы;
3. подключаемые css, js файлы;
4. другие файлы, к которым пользователь может получить доступ.

To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Примеры фреймворков, которые легко можно использовать в этом шаблоне:
1. Symfony
2. Laravel
3. Slim
4. Codeigniter

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
<details>
<summary>Для работы Yii</summary>

## Add your files
Чтобы работать с Yii, необходимо заменить путь `/app/public` на `/app/web`
1. изменить конфигурацию nginx
   в файле `docker/web/nginx/conf.d/app.conf` в 16 строчке заменить `root $base/public;` -> `root $base/web;`
2. в compose-файле изменить volume  `${APP_BASE_DIR-.}/public:/app/public` -> `${APP_BASE_DIR-.}/web:/app/web` 
3. в файле `docker/web/Dockerfile` в 12 строчке заменить `COPY --chown=www-data:www-data --from=app /app/public /app/public` -> `COPY --chown=www-data:www-data --from=app /app/web /app/web`

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
> Мог где-то что-то упустить. Разворачивать Yii не пробовал.
</details>

```
cd existing_repo
git remote add origin https://gl.iqdev.team/i.vasilenko/symfony-trainee.git
git branch -M main
git push -uf origin main
```
> В частных случаях может потребоваться доработка конфигураций.

## Integrate with your tools
## Инструкция

- [ ] [Set up project integrations](https://gl.iqdev.team/i.vasilenko/symfony-trainee/-/settings/integrations)
## Настройка Xdebug (PHPStorm)
<details>
<summary>Инструкция</summary>

## Collaborate with your team
1. Задать значение в `.env` для `XDEBUG_IDE_KEY`. Например: `xdebug_app_key`.
   При изменении настроек, необходимо пересобрать контейнер с php.
   <hr>
2. Settings -> Build, Execution, Deployment -> Docker:

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
   Нажимаем "+", указываем своё имя и настраиваем подключение в зависимости от Ваших настроек Docker.
   Внизу должна появиться надпись `Connection successful`.
   <hr>
3. Settings -> PHP -> CLI Interpreter -> 3 точки:
 
## Test and Deploy
   Нажимаем слева "+" -> `From Docker, Vargant ...`, выбираем пункт `Docker Compose`.

Use the built-in continuous integration in GitLab.
   Server -> выбираем тот, что создали на прошлом шаге.
   
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
   Configuration files -> выбираем `compose.yaml` из этого проекта.
   
***
   Service -> выбираем контейнер с PHP.

# Editing this README
   OK

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
   Остальное на Ваш вкус, но в графе Lifecycle лучше оставить connect to existing container.
   <hr>
4. Settings -> PHP -> CLI Interpreter:
   
## Suggestions for a good README
   Выбрать только что созданный конфиг.
   <hr>
5. Settings -> PHP -> Servers:

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
   Нажимаем "+", вводим названием (его нужно запомнить), указываем хост (127.0.0.1) и порт, который указали в `.env` для nginx.

## Name
Choose a self-explaining name for your project.
   Включаем галочку `Use path mappings` и раскрываем папку `Projects Files`, на против `app` указываем `/app`.
   <hr>
6. Settings -> PHP -> Debug:

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
   В блоке `Xdebug` находим поле `Debug port` и добавляем туда `9001`.
   <hr>
7. Run -> Edit configurations:
   
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
   Нажимаем на "+", переходим в `PHP Remote Debug`, указываем название.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
   В поле Server указываем тот, что создали в п.5

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
   IDE key (session_id) указываем тот, что указали в `.env` в поле `XDEBUG_IDE_KEY`

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
После, на верхней панели, где включается debug, выбираем вариант из п.7.
Теперь можно ставить breakpoints, запускать debug и посылать запросы.
</details>
Loading