docker-caravane/README.md

282 lines
7.1 KiB
Markdown
Raw Normal View History

2024-06-18 15:03:29 +02:00
# Caravane des ruralité Docker Environement (drupal api + vuejs client)
2024-07-09 12:53:49 +02:00
Caravane des ruralités powered by druapl 10 in docker environement (nginx, php:8.3-fpm+drush, mysql, phpmyadmin, redis, npm)
2024-06-18 15:03:29 +02:00
## Install docker
```
sudo pacman -S docker docker-compose docker-machine
```
start the docker service
```
sudo systemctl start docker
```
For all the following, DO NOT run docker or make commande as root or with sudo, use this setup: add your user to the docker user group, re-login, and restart docker.service.
https://wiki.archlinux.org/index.php/Docker#Installation
## Clone this repos
this will clone this repos (main docker environement), the drupal 9 based api source code (without sites/default folder nor mysq ddb) and the vuejs app source code.
```
2024-06-18 16:24:55 +02:00
git clone --recursive -o figli https://figureslibres.io/gitea/bachir/docker-caravane.git
2024-06-18 15:03:29 +02:00
```
submodules :
2024-06-18 16:24:55 +02:00
- https://figureslibres.io/gitea/bachir/drupal-caravane
2024-06-18 15:03:29 +02:00
2024-06-18 17:20:10 +02:00
## touch log file
```
touch log/nginx/error.log
touch log/nginx/caravane/error.log
```
2024-06-18 15:03:29 +02:00
### setup /sites/default/settings.php
2024-07-09 12:52:27 +02:00
```cp -r ressources/api/* src/web/sites/default/```
2024-06-18 15:03:29 +02:00
2024-06-18 16:52:30 +02:00
### get the sites/default/salt.txt file (if you don't have it, you don't)
2024-06-18 15:03:29 +02:00
### get the sites/default/files folder
rsync the files from you know where (if you don't, you don't) to api/src/web/sites/default/files/
2024-06-18 16:52:30 +02:00
<!-- ### xdebug
on ```ressources/xdebug.ini``` edit the ```xdebug.remote_host``` ip to your host locale ip (e.g. : 192.168.0.23) (or once the docker is started to the host ip from the container point of vu e.g. 172.21.0.1) -->
2024-06-18 15:03:29 +02:00
## Mysql
Copy your-sql-dump.sql into ./ressources/caravane.sql
It will be automaticly imported into the mysql container db (only) on the first ```make up```
## Hosts and reverse proxy
add to your /etc/hosts :
```
127.0.0.1 dev.caravane.fr
127.0.0.1 dev.phpmyadmin.caravane.fr
```
configure your vhosts to add a reverse proxy that will redirect the dev.caravane.fr to our container
2024-06-18 15:09:32 +02:00
2024-06-18 15:03:29 +02:00
Apache
2024-06-18 15:09:32 +02:00
```apache
2024-06-18 15:03:29 +02:00
<Virtualhost *:80>
ServerName dev.caravane.fr
ProxyPass / http://127.0.0.1:8990/
ProxyPassReverse / http://127.0.0.1:8990/
ProxyRequests Off
ProxyPreserveHost On
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
</Virtualhost>
```
2024-06-18 15:09:32 +02:00
```apache
2024-06-18 15:03:29 +02:00
<Virtualhost *:80>
ServerName dev.phpmyadmin.caravane.fr
ProxyPass / http://127.0.0.1:8991/
ProxyPassReverse / http://127.0.0.1:8991/
ProxyRequests Off
ProxyPreserveHost On
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
</Virtualhost>
```
nginx
2024-06-18 15:09:32 +02:00
```nginx
2024-06-18 15:03:29 +02:00
server {
listen 80;
server_name dev.caravane.fr;
access_log off;
error_log /var/log/nginx/caravane/error.log error;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8990;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
}
server {
listen 80;
server_name dev.phpmyadmin.caravane.com;
location / {
proxy_pass http://127.0.0.1:8991;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
}
```
## Docker
### docker-compose pull
pull the latest image of services
```
make pull
```
### build
only before the first run (may take some time)
```
make build
```
/!\ DO NOT use ```docker-compose build```, it will faile
### run
then each time you want to launch the app
```
make up
```
Be aware that a first up, since the db is empty, it will be populated with your file db.sql. It may take some time depending of your db size.
## Drupal Composer install
Only at first up, finish to install drupal composer dependencies
```
2024-07-09 12:52:27 +02:00
make exec_php
2024-06-18 15:03:29 +02:00
composer install
```
## Visualize
2024-07-09 12:52:27 +02:00
You can now visit http://dev.caravane.fr on your browser
2024-06-18 15:03:29 +02:00
## Coding
### drush
you can access to drush by loging into the php container
```
2024-07-09 12:52:27 +02:00
make exec_php
2024-06-18 15:03:29 +02:00
```
once inside the php container in /var/www/html you can use drush as usual
## Updating code
```
git pull figli master
# then update all submodules
git submodule update --recursive --checkout
2024-07-09 12:52:27 +02:00
# or only
git submodule update --checkout src/
make maj_config
2024-06-18 15:03:29 +02:00
```
## Updating manualy mysql db
copy your db backup into the mysql container
```sh
sudo docker cp your-db-file.sql caravane_mysql_1:/root/
```
log into mysql container
```sh
make exec_mysql
```
once inside the mysql container you can use mysql command to drop then create and load the db with your file
```
mysql -uroot -pcaravane
> drop database caravane;
> create database caravane;
> exit;
mysql -uroot -pcaravane caravane < your-db-file.sql
```
## Makefile
DO NOT use directly docker or docker-compose to run this instance
use make instead like ```make up```
```makefile
2024-07-15 12:28:08 +02:00
#!/usr/bin/make
SHELL = /bin/sh
USER_UID := $(shell id -u)
USER_UNAME := $(shell id -un)
USER_GID := $(shell id -g)
USER_GNAME := $(shell id -gn)
export USER_UID
export USER_UNAME
export USER_GID
export USER_GNAME
2024-06-18 15:03:29 +02:00
pull:
docker-compose pull
build:
docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)
buildnc:
docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)
2024-07-09 12:52:27 +02:00
buildncphp:
docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) php
buildnginx:
docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) nginx
buildncnginx:
docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) nginx
2024-06-18 15:03:29 +02:00
downbuildup: down build up
up:
docker-compose up -d
ps:
docker-compose ps
logs:
docker-compose logs -f
2024-07-09 12:52:27 +02:00
maj_config: crd composer_install updb cim cr
2024-06-18 15:03:29 +02:00
2024-07-09 12:52:27 +02:00
crd:
2024-07-15 12:28:08 +02:00
docker exec caravane-php-1 /bin/bash -c "drush cache-clear drush"
2024-06-18 15:03:29 +02:00
2024-07-09 12:52:27 +02:00
cr:
2024-07-15 12:28:08 +02:00
docker exec caravane-php-1 /bin/bash -c "drush cr"
2024-06-18 15:03:29 +02:00
2024-07-09 12:52:27 +02:00
updb:
2024-07-15 12:28:08 +02:00
docker exec caravane-php-1 /bin/bash -c "drush updb -y"
2024-06-18 15:03:29 +02:00
2024-07-09 12:52:27 +02:00
cim:
2024-07-15 12:28:08 +02:00
docker exec caravane-php-1 /bin/bash -c "drush config-import -y"
2024-06-18 15:03:29 +02:00
2024-07-09 12:52:27 +02:00
composer_install:
2024-07-15 12:28:08 +02:00
docker exec caravane-php-1 /bin/bash -c "composer install --no-dev"
2024-06-18 15:03:29 +02:00
down:
docker-compose down
2024-07-15 12:28:08 +02:00
exec_php:
docker exec -it caravane-php-1 bash
2024-06-18 15:03:29 +02:00
2024-07-15 12:28:08 +02:00
restart_php:
docker-compose restart php
2024-06-18 15:03:29 +02:00
exec_mysql:
2024-07-09 12:52:27 +02:00
docker exec -it caravane-mysql-1 bash
restart_nginx:
docker-compose restart nginx
dump_db:
docker exec caravane-mysql-1 sh -c 'exec mysqldump -uroot -pcaravane caravane' > ./ressources/caravane-$(DATE_NOW)-local.sql
2024-07-15 12:28:08 +02:00
2024-06-18 15:03:29 +02:00
```