Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
karser committed May 5, 2021
0 parents commit de91844
Show file tree
Hide file tree
Showing 217 changed files with 23,253 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.git
/.env.local
**/.env.*
**/.app_env*
**/*.log
**/._*
**/.DS_Store
**/.gitignore
**/.gitattributes
**/Thumbs.db
**/*.md
**/.dockerignore
Dockerfile*
docs/
node_modules/
public/build/
public/bundles/
var/
vendor/
44 changes: 44 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=3247a721904471e968b39c1652eff071
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# For a PostgreSQL database, use: "postgresql://db_user:[email protected]:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://dev:[email protected]:3316/qb_api?serverVersion=mariadb-10.2.22
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
MAILER_DSN=smtp://localhost
###< symfony/mailer ###

###> symfony/amazon-mailer ###
# MAILER_DSN=ses://ACCESS_KEY:SECRET_KEY@default?region=eu-west-1
# MAILER_DSN=ses+smtp://ACCESS_KEY:SECRET_KEY@default?region=eu-west-1
###< symfony/amazon-mailer ###

DOMAIN=app.easyquickimport.com
WEBDAV_URL=
WEBDAV_USERNAME=
WEBDAV_PASSWORD=
WEBDAV_PATH=
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='s$cretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/.idea
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
80 changes: 80 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ENV variables: https://docs.gitlab.com/ce/ci/variables/
image: karser/docker-compose-ci

stages:
- test
- build
- deploy

before_script:
- docker -v && docker-compose -v

test dev:
stage: test
only:
refs:
- branches
variables:
COMPOSE_PROJECT_NAME: "easyquickimport_test${CI_JOB_ID}"
DOCKER_ENV: test
APP_ENV: test
script:
- cd docker
- bin/copy-env.sh
- bin/build.sh
- docker-compose run --rm php sh -c "bin/run-tests.sh"
after_script:
- cd docker
- docker-compose down --remove-orphans
artifacts:
expire_in: 1 week
when: always
paths:
- var/log

build image:
stage: build
variables:
DOCKER_ENV: prod
APP_ENV: prod
script:
- cd docker
- bin/copy-env.sh
- bin/build.sh
- bin/push.sh

deploy prod:
stage: deploy
environment:
name: easyquickimport-prod
url: https://app.easyquickimport.com/
only:
- tags
- branches
when: manual
variables:
DOCKER_ENV: prod
ENVIRONMENT: prod
APP_ENV: prod
COMPOSE_PROJECT_NAME: easyquickimport
VIRTUAL_HOST: app.easyquickimport.com
DATABASE_HOST: ${HZ4_DB_HOST}
MAILER_DSN: ${PROD_MAILER_DSN}
DATABASE_URL: ${PROD_DATABASE_URL}
# connect to the server
DOCKER_TLS_VERIFY: "1"
DOCKER_HOST: $HZ4_DOCKER_HOST
DOCKER_CERT_PATH: "/tmp/certs"
before_script:
- mkdir -p $DOCKER_CERT_PATH
- echo "$HZ4_CA" > $DOCKER_CERT_PATH/ca.pem
- echo "$HZ4_CLIENT_CERT" > $DOCKER_CERT_PATH/cert.pem
- echo "$HZ4_CLIENT_KEY" > $DOCKER_CERT_PATH/key.pem
- ls -alh $DOCKER_CERT_PATH
- echo ${CI_REGISTRY_PASSWORD} | docker login ${CI_REGISTRY} -u ${CI_REGISTRY_USER} --password-stdin
script:
- cd docker
- bin/copy-env.sh
- docker-compose config | docker stack deploy --with-registry-auth -c - ${COMPOSE_PROJECT_NAME}
after_script:
- rm -rf $DOCKER_CERT_PATH
152 changes: 152 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
ARG PHP_VERSION=7.4
ARG NGINX_VERSION=1.18.0


# "php base" stage
FROM php:${PHP_VERSION}-fpm-alpine AS app_php_base

# persistent / runtime deps
RUN apk add --no-cache \
acl \
bash \
fcgi \
file \
gettext \
git \
freetype \
libjpeg-turbo \
libpng \
nano \
;

ARG APCU_VERSION=5.1.18
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
postgresql-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/ \
; \
docker-php-ext-install -j$(nproc) \
gd \
intl \
mysqli \
pdo \
pdo_mysql \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
gd \
apcu \
# opcache \
mysqli \
pdo_mysql \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; \
\
apk del .build-deps

COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer

RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/app.ini

RUN set -eux; \
{ \
echo '[www]'; \
echo 'ping.path = /ping'; \
echo 'clear_env = no'; \
} | tee /usr/local/etc/php-fpm.d/docker-config.conf

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
RUN set -eux; \
composer global require "symfony/flex" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /var/www/app

# "php prod" stage
FROM app_php_base AS app_php

# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock ./
RUN set -eux; \
composer install --prefer-dist --no-dev --no-scripts --no-progress --no-suggest; \
composer clear-cache

# do not use .env files in production
COPY .env ./
RUN composer dump-env prod; \
rm .env

# copy only specifically what we need
COPY bin bin/
COPY config config/
COPY public public/
COPY src src/
COPY templates templates/
COPY translations translations/

RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
VOLUME /var/www/app/var

COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]


# "nginx" stage
# depends on the "php" stage above
FROM nginx:${NGINX_VERSION}-alpine AS app_nginx

ADD ./docker/nginx/nginx.conf /etc/nginx/
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /var/www/app/public

COPY --from=app_php /var/www/app/public ./

ARG PUID=1000
ARG PGID=1000

RUN if [[ -z $(getent group ${PGID}) ]] ; then \
addgroup -g ${PGID} www-data; \
else \
addgroup www-data; \
fi; \
adduser -D -u ${PUID} -G www-data www-data
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Dmitrii Poddubnyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit de91844

Please sign in to comment.