Skip to content

Commit 5165319

Browse files
committed
Initial commit
0 parents  commit 5165319

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+14410
-0
lines changed

.env

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is a "template" of which env vars need to be defined for your application
2+
# Copy this file to .env file for development, create environment variables when deploying to production
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=dev
7+
APP_SECRET=1f8f4ef84ceee309dbe490e966d788fb
8+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
9+
#TRUSTED_HOSTS=localhost
10+
###< symfony/framework-bundle ###
11+
12+
###> doctrine/doctrine-bundle ###
13+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
14+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
15+
# Configure your db driver and server_version in config/packages/doctrine.yaml
16+
DATABASE_NAME=symfony-rest-api-init
17+
DATABASE_URL=mysql://root:root@database/${DATABASE_NAME}
18+
###< doctrine/doctrine-bundle ###
19+
20+
RELEASE_NAME='local'
21+
22+
###> lexik/jwt-authentication-bundle ###
23+
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
24+
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
25+
JWT_PASSPHRASE=2d6e32416f8180d4b5a96ab3cb4cb8e6
26+
###< lexik/jwt-authentication-bundle ###

.gitignore

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
###> symfony/framework-bundle ###
2+
/var/cache/*
3+
/var/log/*
4+
/var/db/*
5+
!var/db/.keep
6+
/vendor/
7+
###< symfony/framework-bundle ###
8+
9+
# Managed by Composer
10+
/var/bootstrap.php.cache
11+
/bin/*
12+
!bin/console
13+
!bin/phpunit
14+
!bin/symfony_requirements
15+
16+
# Assets and user uploads
17+
/public/bundles/
18+
19+
# PHPUnit
20+
/phpunit.xml
21+
.phpunit
22+
.phpunit.result.cache
23+
/public/coverage/
24+
25+
###> friendsofphp/php-cs-fixer ###
26+
/.php_cs
27+
/.php_cs.cache
28+
###< friendsofphp/php-cs-fixer ###
29+
30+
/public/.DS_Store
31+
.DS_Store
32+
33+
###> lexik/jwt-authentication-bundle ###
34+
/config/jwt/*.pem
35+
###< lexik/jwt-authentication-bundle ###
36+
37+
**/Entity/*~
38+
.idea/
39+
/docker-compose.override.yml
40+
/docker/mysql
41+
config/firebase/service-account.json

.htaccess

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
RewriteEngine on
2+
RewriteBase /
3+
4+
# MAKE SURE WE USE HTTPS
5+
RewriteCond %{HTTPS} off
6+
RewriteCond %{HTTP_HOST} (www\.)?*
7+
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
8+
9+
# REDIRECT TO /public
10+
RewriteCond %{REQUEST_URI} !^/public/
11+
RewriteRule ^(.*)$ /public/$1 [L]
12+
13+
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:nafaa-azaiez.com
14+
RewriteEngine on
15+
RewriteCond %{HTTPS} off
16+
RewriteCond %{HTTP_HOST} (www\.)?nafaa-azaiez.com
17+
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
18+
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:nafaa-azaiez.com

Dockerfile

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
ARG PHP_VERSION=7.4
2+
ARG APP_ENV=dev
3+
4+
FROM php:${PHP_VERSION}-fpm-alpine as php_fpm
5+
6+
# persistent / runtime deps
7+
RUN apk add --no-cache \
8+
$PHPIZE_DEPS \
9+
acl \
10+
file \
11+
gettext \
12+
git \
13+
freetype-dev \
14+
bzip2-dev \
15+
icu-dev \
16+
libsodium-dev \
17+
libzip-dev \
18+
; \
19+
docker-php-ext-configure gd --with-freetype=/usr/include/ \
20+
&& docker-php-ext-install bz2 \
21+
&& docker-php-ext-install opcache \
22+
&& docker-php-ext-install intl \
23+
&& docker-php-ext-install zip \
24+
&& docker-php-ext-install pdo_mysql \
25+
&& docker-php-ext-install sodium \
26+
&& docker-php-ext-install bcmath
27+
28+
RUN pecl install apcu \
29+
&& docker-php-ext-enable apcu
30+
31+
COPY docker/php/config/php.ini /usr/local/etc/php/
32+
33+
RUN pecl install xdebug \
34+
&& docker-php-ext-enable xdebug \
35+
; \
36+
pecl clear-cache;
37+
38+
COPY docker/php/config/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
39+
40+
# install composer
41+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
42+
ENV COMPOSER_ALLOW_SUPERUSER=1
43+
RUN set -eux; \
44+
composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative;
45+
46+
WORKDIR /var/www/api
47+
48+
ENV PATH="${PATH}:/root/.composer/vendor/bin"
49+
50+
# copy only specifically what we need
51+
COPY composer.json composer.lock symfony.lock .env* behat.yml.* ./
52+
COPY bin bin/
53+
COPY config config/
54+
COPY features features/
55+
#COPY fixtures fixtures/
56+
COPY public public/
57+
COPY src src/
58+
COPY templates templates/
59+
COPY tests tests/
60+
COPY translations translations/
61+
62+
RUN set -eux; \
63+
composer install --prefer-dist --no-progress --no-suggest;
64+
65+
RUN set -eux; \
66+
mkdir -p var/cache var/log var/data config/jwt; \
67+
chmod +x bin/console; sync
68+
69+
VOLUME /var/www/api/var
70+
71+
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
72+
RUN chmod +x /usr/local/bin/docker-entrypoint
73+
74+
EXPOSE 9000
75+
76+
ENTRYPOINT ["docker-entrypoint"]
77+
78+
CMD ["php-fpm"]

Makefile

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
DC=docker-compose
2+
CONTAINER=php
3+
DATABASE_CONTAINER=database
4+
EXEC=$(DC) exec $(CONTAINER)
5+
PHP = php
6+
CON = $(PHP) bin/console
7+
AWK := $(shell command -v awk 2> /dev/null)
8+
9+
.DEFAULT_GOAL := help
10+
.PHONY: help
11+
12+
help: ## Show this help
13+
ifndef AWK
14+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
15+
else
16+
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
17+
endif
18+
19+
##
20+
## Project setup
21+
##---------------------------------------------------------------------------
22+
.PHONY: install update vendor-install vendor-update
23+
.PRECIOUS: .env docker-compose.override.yml
24+
25+
install: ## Process all step in order to setup the projects
26+
install: up vendor-install db-reset
27+
28+
update: ## Update the project
29+
update: up vendor-install db-migrate
30+
31+
vendor-install:
32+
$(EXEC) composer install --no-suggest --no-progress
33+
34+
vendor-update:
35+
$(EXEC) composer update
36+
37+
##
38+
## Database
39+
##---------------------------------------------------------------------------
40+
.PHONY: db-reset db-create db-drop db-make-migration db-migrate db-schema-validate db-schema-drop db-schema-update db-fixtures db-test
41+
42+
db-reset: ## Reset database
43+
db-reset: db-drop db-create db-migrate
44+
45+
db-create: ## Create database
46+
$(EXEC) $(CON) doctrine:database:create --if-not-exists
47+
48+
db-drop: ## Drop database
49+
$(EXEC) $(CON) doctrine:database:drop --force --if-exists
50+
51+
db-gen-migration: ## Drop database
52+
$(EXEC) $(CON) doctrine:migration:diff
53+
54+
db-make-migration: ## Migrate database schema to the latest available version
55+
$(EXEC) $(CON) make:migration
56+
57+
db-migrate: ## Migrate database schema to the latest available version
58+
$(EXEC) $(CON) doctrine:migrations:migrate -n
59+
60+
db-schema-validate: ## Validate the mapping files
61+
$(EXEC) $(CON) doctrine:schema:validate
62+
63+
db-schema-drop: ## Executes (or dumps) the SQL needed to drop the current database schema
64+
$(EXEC) $(CON) doctrine:schema:drop --force
65+
66+
db-schema-update: ## Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata
67+
$(EXEC) $(CON) doctrine:schema:update --force
68+
69+
db-fixtures: ## Reset the database fixtures
70+
$(EXEC) $(CON) hautelook:fixtures:load --purge-with-truncate -q
71+
72+
##
73+
## TESTS
74+
##
75+
76+
unit-tests: ## Run functional tests
77+
$(EXEC) bin/phpunit
78+
79+
unit-tests-coverage: ## Run functional tests
80+
$(EXEC) bin/phpunit --coverage-html public/coverage
81+
82+
##
83+
## Tools
84+
##---------------------------------------------------------------------------
85+
86+
cc: ## Clear and warm up the cache in dev env
87+
cc:
88+
$(EXEC) $(CON) cache:clear --no-warmup
89+
$(EXEC) $(CON) cache:warmup
90+
.PHONY: cc
91+
92+
##
93+
## Docker
94+
##---------------------------------------------------------------------------
95+
.PHONY: docker-files up down clear perm bash mysql-bash cs-fix-dry cs-fix
96+
.PRECIOUS: .env docker-compose.override.yml
97+
98+
docker-files: .env docker-compose.override.yml
99+
100+
# .env: .env.dist
101+
# @if [ -f .env ]; \
102+
# then\
103+
# echo '\033[1;41m/!\ The .env.dist file has changed. Please check your .env file (this message will not be displayed again).\033[0m';\
104+
# touch .env;\
105+
# exit 1;\
106+
# else\
107+
# echo cp .env.dist .env;\
108+
# cp .env.dist .env;\
109+
# fi
110+
111+
docker-compose.override.yml: docker-compose.yml
112+
@if [ -f docker-compose.override.yml ]; \
113+
then\
114+
echo '\033[1;41m/!\ The docker-compose.yml file has changed. Please check your docker-compose.override.yml file (this message will not be displayed again).\033[0m';\
115+
touch docker-compose.override.yml;\
116+
exit 1;\
117+
fi
118+
119+
up: ## Mount the containers
120+
up: docker-files
121+
$(DC) up -d
122+
123+
clear: ## Remove everything: the cache, the logs, the sessions
124+
clear: clear-files down
125+
126+
clear-files: docker-files perm
127+
-$(EXEC) rm -rf var/cache/*
128+
-$(EXEC) rm -rf var/sessions/*
129+
-$(EXEC) rm -rf var/logs/*
130+
131+
down: ## Stops, remove the containers and their volumes
132+
down: docker-files
133+
$(DC) down -v --remove-orphans
134+
135+
perm: docker-files
136+
-$(EXEC) chmod -R u+rwX,go+rX,go-w var
137+
138+
bash: ## Access the api container via shell
139+
$(DC) exec $(CONTAINER) sh
140+
141+
142+
jwt: docker-files perm
143+
-$(EXEC) mkdir -p config/jwt
144+
-$(EXEC) php -r "require'vendor/autoload.php';file_put_contents('passphrase.txt',\Symfony\Component\Yaml\Yaml::parse(file_get_contents('config/packages/lexik_jwt_authentication.yaml'))['lexik_jwt_authentication']['pass_phrase']);"
145+
-$(EXEC) openssl genpkey -out ./config/jwt/private.pem -aes256 -pass file:passphrase.txt -algorithm rsa -pkeyopt rsa_keygen_bits:4096
146+
-$(EXEC) openssl pkey -in ./config/jwt/private.pem -passin file:passphrase.txt -out config/jwt/public.pem -pubout
147+
-$(EXEC) rm -f passphrase.txt
148+
-$(EXEC) chown -R www-data:www-data ./config/jwt
149+
150+
build: docker-files
151+
-$(EXEC) rm -rf config/jwt/*
152+
-$(DC) build
153+
-make jwt
154+
-$(EXEC) chmod -R 777 ./var/*
155+
156+
build-no-chache: docker-files
157+
-$(EXEC) rm -rf config/jwt/*
158+
-$(DC) build --no-cache
159+
-make jwt
160+
-$(EXEC) chmod -R 777 ./var/*
161+
-docker-compose up -d --force-recreate
162+
-make db-drop
163+
-make db-create
164+
-make db-migrate
165+
166+
167+
mysql-bash: ## Access the database container via shell
168+
$(DC) exec $(DATABASE_CONTAINER) bash
169+
170+
cs-fix-dry: ## Runs the CS fixer in "dry-run" mode to fix the project coding style
171+
cs-fix-dry: docker-files vendor
172+
$(EXEC) vendor/bin/php-cs-fixer fix src -vvv --config=.php_cs --cache-file=.php_cs.cache --dry-run
173+
174+
cs-fix: ## Runs the CS fixer to fix the project coding style
175+
cs-fix: docker-files vendor
176+
$(EXEC) vendor/bin/php-cs-fixer fix src -vvv --config=.php_cs --cache-file=.php_cs.cache

0 commit comments

Comments
 (0)