Using Symfony Doctrine Migrations with Gitlab CI: GitLab CI interprets "Nothing to migrate" as error - symfony

We are using the Doctrine migrations bundle for update database in our deployment process. Currently, we are switching to Gitlab-CI.
The problem: The CI is aborting the deployment process because the output of command php sf doctrine:migrations:diff contains stderr.
The part of our .gitlab-ci.yml:
deploy_live:
type: deploy
environment:
name: live
url: 1.2.3.4
script:
- ssh root#1.2.3.4 "cd /var/www/html/ && git pull origin master && exit"
- ssh root#11.2.3.4 "cd /var/www/html/ && composer install -n && exit"
- ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
- ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:migrate -n --env=prod && exit"
- 'ssh root#1.2.3.4 "cd /var/www/html/ && chown www-data:www-data . -R && exit"'
only:
- master
Output of Gitlab CI:
$ ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
#!/usr/bin/env php
In NoChangesDetected.php line 13:
No changes detected in your mapping information.
doctrine:migrations:diff [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--editor-cmd [EDITOR-CMD]] [--filter-expression [FILTER-EXPRESSION]] [--formatted] [--line-length [LINE-LENGTH]] [--check-database-platform [CHECK-DATABASE-PLATFORM]] [--db DB] [--em [EM]] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
ERROR: Job failed: exit code 1
This may be a bug, but maybe it can be circumvented?
FYI: sf is a symlink to bin/console.

I just found a solution:
move the commands excecuted directly from the gitlab-ci.yml file unter script to an shell script deploy.sh
move this script via scp to the server
gitlab-ci.yml
deploy_live:
type: deploy
environment:
name: live
url: 1.2.3.4
script:
- scp deploy.sh root#1.2.3.4:/var/www/html/
- ssh root#1.2.3.4 "cd /var/www/html/ && chmod +x deploy.sh && ./deploy.sh && exit"
only:
- master
deploy.sh
cd /var/www/html/
git add --all
git commit -m "changes"
git pull origin master
composer install -n
php sf doctrine:cache:clear-metadata --env=prod
php sf doctrine:migrations:diff --env=prod
php sf doctrine:migrations:migrate -n --env=prod
php sf cache:clear --env=prod
exit

They added option for such case: --allow-no-migration - can you try it?
see: https://github.com/doctrine/migrations/blob/ebd2551c7767375fcbc762b48d7dee4c18ceae97/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php#L64

Related

Installing rpy2 with Docker is unable to find R path

A Django application using Docker needs to install rpy2 as a dependency. Although I install r-base container and specify it as a dependency, when installing django requirements I keep getting:
Collecting rpy2==2.8.3 (from -r /requirements/base.txt (line 55))
Downloading rpy2-2.8.3.tar.gz (186kB)
Complete output from command python setup.py egg_info:
Error: Tried to guess R's HOME but no command 'R' in the PATH.
How can specify inside Docker where the R path is?
My server.yml looks like this:
version: '2'
services:
r:
build: ./services/r
django:
build:
context: ./myproject/
dockerfile: ./compose/django/Dockerfile
env_file:
- .env
- .env-server
environment:
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}#postgres:5432/${POSTGRES_USER}
depends_on:
- postgres
- r
command: /gunicorn.sh
volumes:
- ./myproject:/app
The Dockerfile for django is:
FROM python:2.7
ENV PYTHONUNBUFFERED 1
COPY ./requirements /requirements
RUN pip install -r /requirements/production.txt \
&& pip install -r /requirements/test.txt \
&& groupadd -r django \
&& useradd -r -g django django
COPY . /app
RUN chown -R django /app
COPY ./compose/django/gunicorn.sh /gunicorn.sh
COPY ./compose/django/entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r//' /entrypoint.sh \
&& sed -i 's/\r//' /gunicorn.sh \
&& chmod +x /entrypoint.sh \
&& chown django /entrypoint.sh \
&& chmod +x /gunicorn.sh \
&& chown django /gunicorn.sh
WORKDIR /app
ENTRYPOINT ["/entrypoint.sh"]
The Dockerfile for R is:
FROM r-base
It was easier to just install r inside the django container. So removing the r container and modifiying the django docker file adding this lines, worked:
RUN apt-get --force-yes update \
&& apt-get --assume-yes install r-base-core

Symfony cache permissions with docker with nginx rsync

Following #sveneisenschmidt's workaround which utilizes rsync in a container to speed up Symfony on OSX:
https://forums.docker.com/t/how-to-speed-up-shared-folders/9322/15
I seem to have Symfony running this way, but I'm running into permissions issues with the web server that I'm not sure how to resolve in Docker.
I'm able to clear the cache via the CLI in my php-fom instance (cache:clear --env=prod --no-debug)
But the problem is when I view Symfony via app_dev.php, nginx cannot seem to write to the cache/logs directories:
Unable to write in the cache directory (/app/app/cache/dev)
I'm confused about how rsync fits into the permissions, but it seems that nginx needs more permissions than it has. Any ideas on how to resolve this?
docker_compose.yml
# Web server
nginx:
container_name: insight_nginx
build: docker/nginx
ports:
- "80:80"
links:
- php
- sync:sync
volumes_from:
- sync
# Data alias
data:
container_name: insight_data
build: docker/data/.
# Database
db:
container_name: insight_db
build: docker/db
ports:
- 3306:3306
volumes:
- "./.data/db:/var/lib/mysql"
- ./db-dump:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: root
# Application server
php:
container_name: insight_php
build: docker/php-fpm
external_links:
- insight_db:docker-mysql
environment:
DB_HOST: docker-mysql
# Syncing
volumes_from:
- sync
links:
- sync:sync
# Synchronization
### Symfony rsync workaround from here: https://forums.docker.com/t/how-to-speed-up-shared-folders/9322/15
sync:
container_name: insight_sync
build: docker/sync
command: "lsyncd -delay 1 -nodaemon -rsync /src /app"
volumes:
- /app
- "./:/src"
working_dir: /src
stdin_open: true
tty: true
nginx/Dockerfile
FROM nginx:latest
COPY symfony3.conf /etc/nginx/conf.d/symfony3.conf
#RUN usermod -u 1000 www-data
#RUN chown -R www-data:www-data /app/cache
#RUN chown -R www-data:www-data /app/logs
php-fpm/Dockerfile
FROM pvlltvk/ubuntu-trusty-php-fpm-5.6
RUN apt-get install -y \
php5-curl \
php5-sybase \
freetds-dev \
libxml2-dev
ADD freetds.conf /etc/freetds/freetds.conf
RUN echo 'alias sf="php /app/app/console"' >> ~/.bashrc
#RUN chmod -R 0777 /tmp/symfony/logs
#RUN chmod -R 0777 /tmp/symfony/cache
#ADD start.sh /start.sh
#RUN chmod +x /start.sh
WORKDIR /app
sync/Dockerfile
FROM ubuntu:16.04
RUN PACKAGES="\
rsync \
lsyncd \
" && \
apt-get update && \
apt-get install -y $PACKAGES && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#RUN rm -rf /src/app/cache/* \
# rm -rf /src/app/logs/* \
# sudo chmod +R 777 /src/app/cache /src/app/logs
#RUN chmod -R 0777 ./app/logs
#RUN chmod -R 0777 ./app/cache
CMD instruction allows you to set a default command, which will be executed only when you run container without specifying a command. *
RUN executes the command(s) that you give in a new layer and creates a new image.**
try
CMD chown -R www-data:www-data /var/www && nginx
*http://goinbigdata.com/docker-run-vs-cmd-vs-entrypoint/
**https://til.codes/docker-run-vs-cmd-vs-entrypoint/

(Docker) How to install dependencies, using separate Composer container, in WordPress container?

Dockerfile
FROM wordpress
ENV REFRESHED_AT 2015-08-12
ADD \
composer.json /var/www/html
ADD \
composer.lock /var/www/html
# install the PHP extensions
RUN \
apt-get -qq update && \
apt-get -y upgrade && \
apt-get install -y vim wget && \
rm -rf /var/lib/apt/lists/*
# Symlink User's "wp-content" folder into the newly installed Wordpress
RUN \
rm -rf /usr/src/wordpress/wp-content/plugins/* && \
rm -rf /usr/src/wordpress/wp-content/themes/* && \
cp -fr /usr/src/wordpress/* /var/www/html/ && \
chown -R www-data:www-data /var/www/html/
# volume for mysql database and wordpress install
VOLUME ["/var/www/html/wp-content/plugins", "/var/www/html/wp-content/themes"]
# Define working directory.
WORKDIR /var/www/html/
EXPOSE 80 3306
CMD ["apache2-foreground"]
Docker Compose File
wordpress:
build: .
links:
- mysql
- composer
volumes:
- wp-content/plugins/:/var/www/html/wp-content/plugins
- wp-content/themes/:/var/www/html/wp-content/themes
environment:
- WORDPRESS_DB_PASSWORD=__WORDPRESS_DB_PASSWORD__
- WORDPRESS_DB_NAME=__WORDPRESS_DB_NAME__
# - WORDPRESS_DB_USER=__WORDPRESS_DB_USER__
ports:
- "9888:80"
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=__WORDPRESS_DB_PASSWORD__
- MYSQL_DATABASE=__WORDPRESS_DB_NAME__
composer:
image: composer/composer
Question details
I'm able to ADD the composer.json and composer.lock files to the working directory. I can confirm that these two files are in the working directory.
What I need is for the Dockerfile (or wherever) to also automatically install the dependencies into the working directory.
According to Docker Hub, https://hub.docker.com/r/composer/composer/,
I should be able to docker run -v $(pwd):/app composer/composer install to install the dependencies but how do I do this in Dockerfile?
Also I'm confused because the -v flag, https://docs.docker.com/engine/userguide/dockervolumes/, has to do with mounting the specified host directory into the a container but I've already ADDed the necessary files to the working directory. All I want to do is install the dependencies.
Thank you for your help.
You just need to mount the current directory to /app when running your composer container. I've put together a simple example to illustrate this working at https://gist.github.com/andyshinn/e2c428f2cd234b718239.
The key parts here are the volumes for the composer part of the application and the restart: 'yes' on the primary PHP application (the application likely will not run until Composer has run so you will want it to restart).

Why does my command 'cd /var/www && php bin/console doctrine:database:create' not work when being passed in ssh?

Would anyone know why if i run:
vagrant ssh -- -t cd /var/www && php bin/console doctrine:database:create
I get:
SQLSTATE[HY000] [2002] Connection refused
But if i vagrant ssh and then run:
cd /var/www && php bin/console doctrine:database:create
It works!?
Fixed with
vagrant ssh -c 'cd /var/www && php bin/console doctrine:database:create'
Thank you John Smith

error about dependencies again and again

I took my project to another local computer and Im getting this error after requesting app_dev.php:
You must set up the project dependencies by running the following
commands: curl -s http://getcomposer.org/installer | php php
composer.phar install.
So I run those commands but the error is the same again...
You sure you use 2.0 version? Because composer is used in symfony 2.1
Can you show logs which occur when executing php composer.phar install?
Else try to:
Remove extra php word in curl -s http://getcomposer.org/installer | php php composer.phar install
Delete cache and make cache dir writable: sudo rm -rf app/cache/* && chmod a+rwx -R app/cache/*

Resources