Skip to content

Commit

Permalink
feat: database service removed
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo committed Apr 3, 2024
1 parent ee8386d commit da61529
Show file tree
Hide file tree
Showing 35 changed files with 10 additions and 2,703 deletions.
139 changes: 10 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<div style="width:100%;float:left;clear:both;margin-bottom:50px;">
<a href="https://github.com/pabloripoll?tab=repositories">
<img
style="width:150px;float:left;"
src="https://pabloripoll.com/files/logo-light-100x300.png"/>
<img style="width:150px;float:left;" src="https://pabloripoll.com/files/logo-light-100x300.png"/>
</a>
</div>

<div style="width:100%;float:left;clear:both;margin-bottom:50px;">
<a href="resources/doc/laravel-11-screenshot.png">
<img
style="width:100%;float:left;"
src="resources/doc/laravel-11-screenshot.png"/>
<img style="width:100%;float:left;" src="resources/doc/laravel-11-screenshot.png"/>
</a>
</div>

Expand All @@ -32,13 +28,12 @@ As client end user both services can be accessed through `localhost:${PORT}` but

- [Alpine Linux 3.19](https://www.alpinelinux.org/)

### MariaDB Docker Container Service
### Database Container Service

- [MariaDB 10.11](https://mariadb.com/kb/en/changes-improvements-in-mariadb-1011/)
To connect this service to a SQL database, it can be used the following [MariaDB 10.11](https://mariadb.com/kb/en/changes-improvements-in-mariadb-1011/) service:
- [https://github.com/pabloripoll/docker-mariadb-10.11](https://github.com/pabloripoll/docker-mariadb-10.11)

- [Alpine Linux 3.19](https://www.alpinelinux.org/)

### Project objetives with Docker
### Project objetives

* Built on the lightweight and secure Alpine 3.19 [2024 release](https://www.alpinelinux.org/posts/Alpine-3.19.1-released.html) Linux distribution
* Multi-platform, supporting AMD4, ARMv6, ARMv7, ARM64
Expand All @@ -53,15 +48,15 @@ As client end user both services can be accessed through `localhost:${PORT}` but

#### PHP config

To use a different PHP 8 version the following [Dockerfile](docker/nginx-php/docker/Dockerfile) arguments and variable must be modified:
To use a different PHP 8 version the following [Dockerfile](docker/nginx-php/docker/Dockerfile) arguments and variable has to be modified:
```Dockerfile
ARG PHP_VERSION=8.3
ARG PHP_ALPINE=83
...
ENV PHP_V="php83"
```

And must be inform to [Supervisor Config](docker/nginx-php/docker/config/supervisord.conf) the FPM version to run.
Also, it has to be informed to [Supervisor Config](docker/nginx-php/docker/config/supervisord.conf) the PHP-FPM version to run.
```bash
...
[program:php-fpm]
Expand Down Expand Up @@ -106,11 +101,6 @@ Directories and main files on a tree architecture description
.
├── docker
│ ├── mariadb
│ │ ├── ...
│ │ ├── .env.example
│ │ └── docker-compose.yml
│ │
│ └── nginx-php
│ ├── ...
│ ├── .env.example
Expand Down Expand Up @@ -155,19 +145,6 @@ Makefile laravel-build builds the Laravel PHP container from Docker
Makefile laravel-start starts up the Laravel PHP container running
Makefile laravel-stop stops the Laravel PHP container but data will not be destroyed
Makefile laravel-destroy stops and removes the Laravel PHP container from Docker network destroying its data
Makefile database-ssh enters the database container shell
Makefile database-set sets the database enviroment file to build the container
Makefile database-build builds the database container from Docker image
Makefile database-start starts up the database container running
Makefile database-stop stops the database container but data will not be destroyed
Makefile database-destroy stops and removes the database container from Docker network destroying its data
Makefile database-replace replace the build empty database copying the .sql backfile file into the container raplacing the pre-defined database
Makefile database-backup creates a copy as .sql file from container to a determined local host directory
Makefile project-set sets both Laravel and database .env files used by docker-compose.yml
Makefile project-build builds both Laravel and database containers from their Docker images
Makefile project-start starts up both Laravel and database containers running
Makefile project-stop stops both Laravel and database containers but data will not be destroyed
Makefile project-destroy stops and removes both Laravel and database containers from Docker network destroying their data
Makefile repo-flush clears local git repository cache specially to update .gitignore
```

Expand All @@ -177,8 +154,6 @@ $ make ports-check

Checking configuration for Laravel container:
Laravel > port:8888 is free to use.
Checking configuration for Laravel DB container:
Laravel DB > port:8889 is free to use.
```

Checkout local machine IP to set connection between containers using the following makefile recipe
Expand All @@ -188,29 +163,12 @@ $ make hostname
192.168.1.41
```

**Before running the project** checkout database connection health using a database mysql client.

- [MySQL Workbench](https://www.mysql.com/products/workbench/)
- [DBeaver](https://dbeaver.io/)
- [HeidiSQL](https://www.heidisql.com/)
- Or whatever you like. This Docker project doesn't come with [PhpMyAdmin](https://www.phpmyadmin.net/) to make it lighter.

## Build the project

```bash
$ make project-build

LARAVEL docker-compose.yml .env file has been set.
LARAVEL DB docker-compose.yml .env file has been set.

[+] Building 9.1s (10/10) FINISHED docker:default
=> [mariadb internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.13kB
...
=> => naming to docker.io/library/lara-db:mariadb-15 0.0s
[+] Running 1/2
⠧ Network lara-db_default Created 0.7s
✔ Container lara-db Started 0.6s

[+] Building 49.7s (25/25) docker:default
=> [wordpress internal] load build definition from Dockerfile 0.0s
Expand All @@ -227,77 +185,19 @@ LARAVEL DB docker-compose.yml .env file has been set.
```bash
$ make project-start

[+] Running 1/0
✔ Container lara-db Running 0.0s
[+] Running 1/0
✔ Container lara-app Running 0.0s
```

Now, Laravel should be available on local machine by visiting [http://localhost:8888/](http://localhost:8888/)

## Database

Every time the containers are built or up and running it will be like start from a fresh installation.

So, you can follow the Wordpress Wizard steps to configure the project at requirements *(language, ip and port, etc)* with fresh database tables.

On he other hand, you can continue using this repository with the pre-set database executing the command `$ make database-install`

Follow the next recommendations to keep development stages clear and safe.

*On first installation* once Laravel app is running with an admin back-office user set, I suggest to make a initialization database backup manually, saving as [resources/database/laravel-backup.sql](resources/database/laravel-backup.sql) but renaming as [resources/database/laravel-init.sql](resources/database/laravel-init.sql) to have that init database for any Docker compose rebuild / restart on next time.

**The following three commands are very useful for *Continue Development*.**

### DB Backup

When the project is already in an advanced development stage, making a backup is recommended to avoid start again from installation step by keeping lastest database registers.
```bash
$ make database-backup

LARAVEL database backup has been created.
```

### DB Install

If it is needed to restart the project from base installation step, you can use the init database .sql file to restart at that point in time. Though is not common to use, helps to check and test installation health.
```bash
$ make database-install

LARAVEL database has been installed.
```

This repository comes with an initialized .sql with a main database user. See [.env.example](.env.example)

### DB Replace

Replace the database set on container with the latest .sql backup into current development stage.
```bash
$ make database-replace

LARAVEL database has been replaced.
```

#### Notes

- Notice that both files in [resources/database/](resources/database/) have the database name that has been set on the main `.env` file to automate processes.

- Remember that on any change in the main `.env` file will be necessary to execute the following Makefile recipe
```bash
$ make project-set

LARAVEL docker-compose.yml .env file has been set.
LARAVEL DB docker-compose.yml .env file has been set.
```

## Docker Info

Docker container
```bash
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ecd27aeae010 lara... "docker-php-entrypoi…" 3 mins... 9000/tcp, 0.0.0.0:8888->80/tcp, :::8888->80/tcp laravel-app
52a9994c31b0 lara... "/init" 4 mins... 0.0.0.0:8889->3306/tcp, :::8889->3306/tcp laravel-db

```

Expand All @@ -306,7 +206,6 @@ Docker image
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
laravel-app lara... 373f6967199b 5 minutes ago 200MB
laravel-db lara... 1f1775f7e1db 6 minutes ago 333MB
```

Docker stats
Expand Down Expand Up @@ -374,13 +273,8 @@ GET: http://localhost:8888/api/v1/health/db

Using the following Makefile recipe stops application and database containers, keeping database persistance and application files binded without any loss
```bash
$ make project-stop
$ make laravel-stop

[+] Killing 1/1
✔ Container laravel-db Killed 0.5s
Going to remove laravel-db
[+] Removing 1/0
✔ Container laravel-db Removed 0.0s
[+] Killing 1/1
✔ Container laravel-app Killed 0.5s
Going to remove laravel-app
Expand All @@ -392,15 +286,7 @@ Going to remove laravel-app

To stop and remove both application and database containers from docker network use the following Makefile recipe
```bash
$ make project-destroy

[+] Killing 1/1
✔ Container laravel-db Killed 0.4s
Going to remove laravel-db
[+] Removing 1/0
✔ Container laravel-db Removed 0.0s
[+] Running 1/1
✔ Network laravel-db_default Removed 0.3s
$ make laravel-destroy

[+] Killing 1/1
✔ Container laravel-app Killed 0.4s
Expand All @@ -411,11 +297,6 @@ Going to remove laravel-app
✔ Network laravel-app_default Removed
```

The, remove the Docker images created for containers by its tag name reference
```bash
$ docker rmi $(docker images --filter=reference="*:laravel-*" -q)
```

Prune Docker system cache
```bash
$ sudo docker system prune
Expand Down
File renamed without changes.
121 changes: 0 additions & 121 deletions docker/mariadb/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions docker/mariadb/docker/.dockerignore

This file was deleted.

Loading

0 comments on commit da61529

Please sign in to comment.