Skip to content

Commit

Permalink
Merge branch 'main' into feature/#161-sign-up-as-a-registered-user
Browse files Browse the repository at this point in the history
  • Loading branch information
aida-rodi committed Jun 11, 2024
2 parents 26a3752 + f5b23d5 commit 1e60326
Show file tree
Hide file tree
Showing 48 changed files with 2,975 additions and 3,656 deletions.
2 changes: 2 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
APP_ENV=development
APP_KEY=
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=user
DB_PASSWORD=password
CACHE_DRIVER=array
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/.fleet
/.idea
/.vscode
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
/build
/storage/api-docs/api-docs.json
.env
.env.backup
Expand All @@ -15,6 +19,4 @@ Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode

41 changes: 0 additions & 41 deletions BackendDockerFile

This file was deleted.

41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:22.2.0 AS node-stage

WORKDIR /var/www/html

RUN mkdir -p /var/www/html/build
RUN npm install -g typescript


FROM php:8.1-fpm as php-stage

WORKDIR /var/www/html

RUN apt-get update && apt-get install -y \
libzip-dev libfreetype6-dev \
libjpeg62-turbo-dev libpng-dev libonig-dev \
libxml2-dev libpq-dev libicu-dev libxslt1-dev \
libmcrypt-dev libssl-dev git zip unzip && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo pdo_mysql mbstring exif pcntl bcmath gd
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY .env.docker /var/www/html/.env

EXPOSE 9000

COPY ./entrypoint.sh /var/www/html/entrypoint.sh
RUN chmod +x /var/www/html/entrypoint.sh
ENTRYPOINT ["/var/www/html/entrypoint.sh"]

CMD ["php-fpm"]


FROM nginx:latest as nginx-stage
COPY ./nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=php-stage /var/www/html /var/www/html
COPY --from=node-stage /var/www/html/build /var/www/html/build
RUN chmod -R 777 /var/www/html/build

EXPOSE 80
EXPOSE 8000

CMD ["nginx", "-g", "daemon off;"]
25 changes: 0 additions & 25 deletions FrontendDockerFile

This file was deleted.

105 changes: 92 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,120 @@
.PHONY: up down full-restart start composer-install composer-update ssh run-tests swagger-generate logs kill-containers help
.PHONY: up down full-restart start composer-install composer-update ssh run-tests swagger-generate logs kill-containers help status

CONTAINER ?= php

up: ## Bring up the Docker containers and build images if necessary
docker compose up --build -d
docker compose build --no-cache
docker compose up -d

down: ## Stop and remove the Docker containers
docker compose down

full-restart: ## Perform a full restart: stop containers, remove all data, and bring up again
docker compose down && docker system prune --all -f && docker compose up --build -d
reboot: ## Perform a full restart: stop containers, remove all data, and bring up again
docker compose down
docker system prune --all -f
docker volume prune -f
docker network prune -f
if [ $$(docker network ls | grep app-network) ]; then sh ./bin/disconnect_and_remove_network.sh; fi
docker network create app-network
if [ -d "./node_modules" ]; then sudo rm -Rf ./node_modules; fi
if [ -d "./vendor" ]; then sudo rm -Rf ./vendor; fi
docker compose --verbose build --no-cache
docker compose up -d
docker network connect app-network mysql
docker network connect app-network php
docker network connect app-network node
docker network connect app-network webserver

start: ## Start the Laravel server in the container
docker exec -it itaprofilesbackend-app php artisan serve --host=0.0.0.0 --port=8000
serve: ## Start the Laravel server in the container
docker exec -it php php artisan serve --host=0.0.0.0 --port=8000

composer-install: ## Run 'composer install' inside the container
docker exec -it itaprofilesbackend-app composer install
docker exec -it php composer install

composer-update: ## Run 'composer update' inside the container
docker exec -it itaprofilesbackend-app composer update
docker exec -it php composer update

setup: ## Does the setup of basic project's features like composer install, migrations, seeds, swagger, resets caches, key, passport...
docker exec -it php bash -c 'if [ -f /var/www/html/bootstrap/cache/config.php ]; then rm /var/www/html/bootstrap/cache/config.php; fi'
docker exec -it php composer install
docker exec -it php composer clear-cache
docker exec -it php composer dump-autoload
docker exec -it php cp .env.docker .env
docker exec -it php php artisan cache:clear
docker exec -it php php artisan config:clear
docker exec -it php php artisan optimize
docker exec -it php php artisan clear-compiled
docker exec -it php php artisan key:generate
docker exec -it php php artisan config:cache
docker exec -it php chmod 777 -R storage
docker exec -it php php artisan migrate:fresh --seed
docker exec -it php php artisan l5-swagger:generate
docker exec -it php php artisan config:clear
docker exec -it php php artisan config:cache
docker exec -it php php artisan cache:clear
docker exec -it php php artisan key:generate
docker exec -it php php artisan passport:install --force --no-interaction

render-setup:
bash -c 'if [ -f /var/www/html/bootstrap/cache/config.php ]; then rm /var/www/html/bootstrap/cache/config.php; fi'
composer install
composer clear-cache
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan optimize
php artisan clear-compiled
php artisan key:generate
php artisan config:cache
php artisan migrate:fresh --seed
php artisan l5-swagger:generate
cp .env.docker .env
php artisan config:clear
php artisan config:cache
php artisan cache:clear
php artisan key:generate
php artisan passport:install --force --no-interaction

ssh: ## Open a bash session inside the container
docker exec -it itaprofilesbackend-app bash
cache-clear: ## Clear the cache
docker exec -it php php artisan config:clear
docker exec -it php php artisan config:cache
docker exec -it php php artisan cache:clear

run-tests: ## Run PHPUnit tests inside the container
docker exec -it itaprofilesbackend-app ./vendor/bin/phpunit -c phpunit.xml ./tests/ --testdox
shell: ## Enters the specified container. Usage: make shell CONTAINER=<container_name>
docker exec -it $(CONTAINER) bash

test: ## Run PHPUnit tests inside the container
docker exec -it php ./vendor/bin/phpunit -c phpunit.xml ./tests/ --testdox

swagger-generate: ## Generate Swagger documentation
docker exec -it itaprofilesbackend-app php artisan l5-swagger:generate
docker exec -it php php artisan l5-swagger:generate

logs: ## Show logs from all services in real time
docker compose logs -f

status: ## Shows the table of the containers withe its status
docker ps

kill-containers: ## Kill all running Docker containers
@if [ "$$(docker ps -q)" ]; then \
docker kill $$(docker ps -q); \
else \
echo "No containers are running."; \
fi

test-connectivity:
docker exec -it php bash -c "timeout 1 bash -c '</dev/tcp/mysql/3306' && echo 'php to mysql: OK' || echo 'php to mysql: Failed'"
docker exec -it php bash -c "timeout 1 bash -c '</dev/tcp/webserver/80' && echo 'php to webserver: OK' || echo 'php to webserver: Failed'"
docker exec -it php bash -c "timeout 1 bash -c '</dev/tcp/node/80' && echo 'php to node: OK' || echo 'php to node: Failed'"
docker exec -it webserver bash -c "timeout 1 bash -c '</dev/tcp/php/9000' && echo 'webserver to php: OK' || echo 'webserver to php: Failed'"
docker exec -it webserver bash -c "timeout 1 bash -c '</dev/tcp/mysql/3306' && echo 'webserver to mysql: OK' || echo 'webserver to mysql: Failed'"
docker exec -it webserver bash -c "timeout 1 bash -c '</dev/tcp/node/80' && echo 'webserver to node: OK' || echo 'webserver to node: Failed'"
docker exec -it mysql bash -c "timeout 1 bash -c '</dev/tcp/php/9000' && echo 'mysql to php: OK' || echo 'mysql to php: Failed'"
docker exec -it mysql bash -c "timeout 1 bash -c '</dev/tcp/webserver/80' && echo 'mysql to webserver: OK' || echo 'mysql to webserver: Failed'"
docker exec -it mysql bash -c "timeout 1 bash -c '</dev/tcp/node/80' && echo 'mysql to node: OK' || echo 'mysql to node: Failed'"
docker exec -it node bash -c "timeout 1 bash -c '</dev/tcp/php/9000' && echo 'node to php: OK' || echo 'node to php: Failed'"
docker exec -it node bash -c "timeout 1 bash -c '</dev/tcp/webserver/80' && echo 'node to webserver: OK' || echo 'node to webserver: Failed'"
docker exec -it node bash -c "timeout 1 bash -c '</dev/tcp/mysql/3306' && echo 'node to mysql: OK' || echo 'node to mysql: Failed'"

help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ ITA Profiles is a project from IT Academy post-specialization course that allows

The project now integrates both frontend and backend functionalities to provide a seamless experience for users.

We have a "production" url for this project placed here:

Backend: https://ita-profiles.onrender.com/api/documentation

Frontend: https://ita-profiles.netlify.app/

## How to install the project

Expand All @@ -22,22 +17,16 @@ We use docker containers to share the same versions of PHP and MySQL around all
2. Once Docker is installed, go to the project's root folder and build the containers by running:

```shell
docker compose up -d
```

3. After the containers are built, run the following command to ensure Swagger styles and JavaScript run properly:

```shell
docker compose exec -it laravel-docker php artisan config:cache
docker compose up --build -d
```

4. Verify that the containers are running by executing:
3. Verify that the containers are running by executing:

```shell
docker ps
```

5. You can now run commands inside the container using the following format:
4. You can now run commands inside the container using the following format:

```shell
docker exec -it <app-container-name> <the-command>
Expand All @@ -46,9 +35,9 @@ docker exec -it <app-container-name> <the-command>
For example:

```shell
docker exec -it laravel-docker composer install
docker exec -it laravel-docker php artisan migrate:fresh
docker exec -it laravel-docker php artisan db:seed
docker exec -it php composer install
docker exec -it php php artisan migrate:fresh
docker exec -it php php artisan db:seed
```

### Local Addresses
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Annotations\OpenApi\ControllersAnnotations\RegisterUserAnnotations;
namespace App\Annotations\OpenApi\controllersAnnotations\registerUserAnnotations;

class AnnotationsRegisterUser
{
Expand Down
16 changes: 16 additions & 0 deletions bin/disconnect_and_remove_network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Name of the network to remove
NETWORK_NAME="app-network"

# Get all containers connected to the network
CONTAINERS=$(docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' $NETWORK_NAME)

# Disconnect each container from the network
for CONTAINER in $CONTAINERS
do
docker network disconnect -f $NETWORK_NAME $CONTAINER
done

# Remove the network
docker network rm $NETWORK_NAME
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.1",
"ext-pdo": "*",
"darkaonline/l5-swagger": "^8.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
Expand All @@ -30,7 +31,7 @@
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/",
"Service\\": "app/Service/"
"Service\\": "app/Service/"
}
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit 1e60326

Please sign in to comment.