Skip to content

Commit 2c226ec

Browse files
author
dmitriy
committed
docker-symfony-api v1.0.0
0 parents  commit 2c226ec

File tree

387 files changed

+51257
-0
lines changed

Some content is hidden

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

387 files changed

+51257
-0
lines changed

.circleci/config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/html
5+
machine: true
6+
branches:
7+
ignore:
8+
- develop
9+
steps:
10+
- checkout
11+
12+
- run:
13+
name: Start container and verify it's working
14+
command: |
15+
make start-test
16+
17+
- run:
18+
name: Wait for DB container is running and initialize DB
19+
command: |
20+
make wait-for-db
21+
make drop-migrate
22+
make generate-jwt-keys
23+
24+
- run:
25+
name: Run unit/functional tests
26+
command: |
27+
make phpunit
28+
29+
- run:
30+
name: Report code coverage
31+
command: |
32+
make report-code-coverage
33+
34+
- store_artifacts:
35+
path: reports
36+
37+
- store_test_results:
38+
path: reports

.dockerignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/.git*
2+
/.idea*
3+
.dockerignore
4+
.editorconfig
5+
6+
/.env.local
7+
/.env.*.local
8+
.env.local.php
9+
/public/bundles/
10+
var/mysql-data
11+
var/rabbitmq
12+
vendor/
13+
14+
Dockerfile
15+
docker-compose.yml
16+
docker-compose-test-ci.yml
17+
docker-compose-prod.yml
18+
Makefile

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2
16+
17+
[{composer.json,Makefile}]
18+
indent_style = tab

.env

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the later taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_ENV=dev
18+
APP_DEBUG=1
19+
APP_SECRET=42f011ec3a7bde0bec87364b1d967193
20+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
21+
#TRUSTED_HOSTS='^localhost|example\.com$'
22+
###< symfony/framework-bundle ###
23+
24+
###> doctrine/doctrine-bundle ###
25+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
26+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
27+
# Configure your db driver and server_version in config/packages/doctrine.yaml
28+
DATABASE_URL=mysql://root:secret@mysql:3306/symfony
29+
###< doctrine/doctrine-bundle ###
30+
31+
###> symfony/swiftmailer-bundle ###
32+
# For Gmail as a transport, use: "gmail://username:password@localhost"
33+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
34+
# Delivery is disabled by default via "null://localhost"
35+
MAILER_URL=null://localhost
36+
###< symfony/swiftmailer-bundle ###
37+
38+
###> symfony/messenger ###
39+
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages
40+
###< symfony/messenger ###
41+
42+
###> lexik/jwt-authentication-bundle ###
43+
JWT_SECRET_KEY=config/jwt/private.pem
44+
JWT_PUBLIC_KEY=config/jwt/public.pem
45+
JWT_PASSPHRASE=3a37d3afd9accc7959f952b2ae555d21
46+
JWT_TOKEN_TTL=3600
47+
###< lexik/jwt-authentication-bundle ###
48+
49+
###> nelmio/cors-bundle ###
50+
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
51+
###< nelmio/cors-bundle ###
52+
53+
# how many days health history will be stored in the db
54+
DATABASE_HEALTH_HISTORY_DAYS=7

.env.prod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the prod env here
2+
APP_ENV=prod
3+
APP_SECRET=42f011ec3a7bde0bec87364b1d967194
4+
APP_DEBUG=0

.env.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# define your env variables for the test env here
2+
APP_ENV=test
3+
KERNEL_CLASS='App\Kernel'
4+
APP_SECRET='$ecretf0rt3st'
5+
APP_DEBUG=0
6+
SYMFONY_DEPRECATIONS_HELPER=999999
7+
DATABASE_URL=mysql://root:secret@mysql:3306/symfony_testing

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Symfony Rest API
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
pull_request:
9+
branches:
10+
- master
11+
- develop
12+
release:
13+
types: [published]
14+
15+
jobs:
16+
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v1
23+
- name: Build the docker images
24+
run: docker-compose -f docker-compose-test-ci.yml build
25+
- name: Start the docker images
26+
run: make start-test
27+
- name: Check running containers
28+
run: docker ps -a
29+
- name: Wait for database connection
30+
run: make wait-for-db
31+
- name: Run migrations
32+
run: make drop-migrate
33+
- name: Generate keys
34+
run: make generate-jwt-keys
35+
- name: Run test suite
36+
run: make phpunit
37+
- name: Stop the docker images
38+
run: make stop-test

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/.idea
2+
reports/*
3+
!reports/.gitkeep
4+
.phpunit.result.cache
5+
6+
###> symfony/framework-bundle ###
7+
/.env.local
8+
/.env.local.php
9+
/.env.*.local
10+
/public/bundles/
11+
/var/
12+
/vendor/
13+
###< symfony/framework-bundle ###
14+
15+
###> symfony/phpunit-bridge ###
16+
.phpunit
17+
/phpunit.xml
18+
###< symfony/phpunit-bridge ###
19+
20+
###> lexik/jwt-authentication-bundle ###
21+
/config/jwt/*.pem
22+
###< lexik/jwt-authentication-bundle ###

Dockerfile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
FROM php:7.4-fpm
2+
3+
# set main params
4+
ARG BUILD_ARGUMENT_DEBUG_ENABLED=false
5+
ENV DEBUG_ENABLED=$BUILD_ARGUMENT_DEBUG_ENABLED
6+
ARG BUILD_ARGUMENT_ENV=dev
7+
ENV ENV=$BUILD_ARGUMENT_ENV
8+
ENV APP_HOME /var/www/html
9+
10+
# check environment
11+
RUN if [ "$BUILD_ARGUMENT_ENV" = "default" ]; then echo "Set BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev" && exit 2; \
12+
elif [ "$BUILD_ARGUMENT_ENV" = "dev" ]; then echo "Building development environment."; \
13+
elif [ "$BUILD_ARGUMENT_ENV" = "test" ]; then echo "Building test environment."; \
14+
elif [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then echo "Building production environment."; \
15+
else echo "Set correct BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev. Available choices are dev,test,prod." && exit 2; \
16+
fi
17+
18+
# install all the dependencies and enable PHP modules
19+
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
20+
procps \
21+
nano \
22+
git \
23+
unzip \
24+
libicu-dev \
25+
zlib1g-dev \
26+
libxml2 \
27+
libxml2-dev \
28+
libreadline-dev \
29+
supervisor \
30+
cron \
31+
libzip-dev \
32+
librabbitmq-dev \
33+
&& pecl install amqp \
34+
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
35+
&& docker-php-ext-install \
36+
pdo_mysql \
37+
sockets \
38+
intl \
39+
zip \
40+
&& docker-php-ext-enable amqp && \
41+
rm -fr /tmp/* && \
42+
rm -rf /var/list/apt/* && \
43+
rm -r /var/lib/apt/lists/* && \
44+
apt-get clean
45+
46+
# create document root
47+
RUN mkdir -p $APP_HOME/public
48+
49+
# change owner
50+
RUN chown -R www-data:www-data $APP_HOME
51+
52+
# put php config for Symfony
53+
COPY ./docker/$BUILD_ARGUMENT_ENV/www.conf /usr/local/etc/php-fpm.d/www.conf
54+
COPY ./docker/$BUILD_ARGUMENT_ENV/php.ini /usr/local/etc/php/php.ini
55+
56+
# install Xdebug in case dev/test environment
57+
COPY docker/general/do_we_need_xdebug.sh /tmp/
58+
COPY ./docker/dev/xdebug.ini /tmp/
59+
RUN chmod u+x /tmp/do_we_need_xdebug.sh && /tmp/do_we_need_xdebug.sh
60+
61+
# install composer
62+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
63+
64+
# add supervisor
65+
RUN mkdir -p /var/log/supervisor
66+
COPY --chown=root:root ./docker/general/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
67+
COPY --chown=root:root ./docker/general/cron /var/spool/cron/crontabs/root
68+
RUN chmod 0600 /var/spool/cron/crontabs/root
69+
70+
# set working directory
71+
WORKDIR $APP_HOME
72+
73+
# create composer folder for user www-data
74+
RUN mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www/.composer
75+
76+
USER www-data
77+
78+
# copy source files
79+
COPY --chown=www-data:www-data . $APP_HOME/
80+
81+
# install all PHP dependencies
82+
RUN if [ "$BUILD_ARGUMENT_ENV" = "dev" ] || [ "$BUILD_ARGUMENT_ENV" = "test" ]; then composer install --optimize-autoloader --no-interaction --no-progress; \
83+
else export APP_ENV=$BUILD_ARGUMENT_ENV && composer install --optimize-autoloader --no-interaction --no-progress --no-dev; \
84+
fi
85+
86+
# create cached config file .env.local.php in case prod environment
87+
RUN if [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then composer dump-env $BUILD_ARGUMENT_ENV; \
88+
fi
89+
90+
USER root

0 commit comments

Comments
 (0)