getsentry / sentry-laravel

The official Laravel SDK for Sentry (sentry.io)
https://sentry.io
MIT License
1.26k stars 188 forks source link

It works on Local, but when I create Docker Image, It gives `returned a non-zero code: 255`. #352

Closed codexyash closed 4 years ago

codexyash commented 4 years ago

Hello,

I installed the latest version of sentry-laravel, when I run it on my local.. it works absolutely fine, but when I create the docker image for it.. the build fails with returned a non-zero code: 255.

When I add it to dont-discover, the build succeeds.

Here I am adding my composer.json and dockerfile, Please have a look and let me know If I am doing anything wrong.

Docker

FROM composer:latest as vendor

COPY .ssh/id_rsa /root/.ssh/id_rsa
COPY .ssh/id_rsa.pub /root/.ssh/id_rsa.pub

COPY database/ database/
COPY composer.json composer.json
COPY composer.json composer.lock

RUN mkdir -p ~/.ssh && \
    ssh-keyscan -t rsa git.comfisoft.com >> ~/.ssh/known_hosts && \
    chmod 600 /root/.ssh/id_rsa && \
    chmod 600 /root/.ssh/id_rsa.pub

RUN composer global require hirak/prestissimo --prefer-dist --no-progress --classmap-authoritative

RUN composer install --ignore-platform-reqs \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --prefer-dist \
    --no-dev \
    --no-progress

COPY app/ app/
COPY bootstrap/ bootstrap/
COPY config/ config/
COPY artisan artisan
COPY routes/ routes/
COPY terms/ terms/

RUN mkdir -p bootstrap/cache

RUN composer dump-autoload \
    --classmap-authoritative \
    --no-dev

FROM node:10 as frontend

WORKDIR /app

COPY webpack.mix.js /app
COPY package.json /app
COPY package-lock.json /app
COPY yarn.lock /app
COPY resources/ /app/resources/
COPY public/ /app/public/

RUN yarn install && yarn production

FROM php:7.3-apache

RUN apt-get update && \
    apt-get install -y libfreetype6-dev libpng-dev libjpeg-dev libxml2-dev autoconf g++ imagemagick libmagickcore-dev libmagickwand-dev libtool make gnupg2 && \
    curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get install -y nodejs && \
    docker-php-ext-configure gd \
        --with-gd \
        --with-freetype-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ && \
    pecl install imagick && \
    docker-php-ext-enable imagick

RUN apt-get install -y git openssh-client zip unzip gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
                       libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
                       libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
                       libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
                       ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y nodejs \
    npm 

RUN apt-get install -y fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst libzip-dev \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get purge --auto-remove -y curl \
    && rm -rf /src/*.deb \
    && npm i puppeteer

RUN docker-php-ext-install intl pdo_mysql zip soap gd pcntl \
    && pecl install redis \
    && docker-php-ext-enable --ini-name 01-redis.ini redis \
    && docker-php-ext-enable --ini-name 02-opcache.ini opcache \
    && docker-php-ext-enable --ini-name 03-gd.ini gd \
    && docker-php-ext-enable --ini-name 04-pcntl.ini pcntl

COPY docker/apache2.conf /etc/apache2/apache2.conf
COPY docker/host.conf /etc/apache2/sites-available/000-default.conf

RUN rm /etc/localtime && ln -s /usr/share/zoneinfo/UTC /etc/localtime

RUN a2enmod rewrite

ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

WORKDIR /var/www

COPY --chown=www-data . ./
COPY --chown=www-data --from=vendor /app/vendor/ vendor/
COPY --chown=www-data --from=vendor /app/bootstrap/ bootstrap/
COPY --chown=www-data --from=frontend /app/node_modules/ node_modules/
COPY --chown=www-data --from=frontend /app/public/js public/js/
COPY --chown=www-data --from=frontend /app/public/css public/css/
COPY --chown=www-data --from=frontend /app/public/mix-manifest.json public/mix-manifest.json

RUN mkdir -p storage/app \
    storage/app/public \
    storage/framework \
    storage/framework/cache \
    storage/framework/sessions \
    storage/framework/testing \
    storage/framework/views \
    storage/logs

COPY keyfile.json storage/app/keyfile.json

RUN ls -als

RUN chown www-data:www-data /var/www
RUN chown -R www-data /var/www/storage

RUN rm /etc/localtime && ln -s /usr/share/zoneinfo/UTC /etc/localtime

ENTRYPOINT ["dumb-init", "docker-php-entrypoint"]
CMD ["apache2-foreground"]
STOPSIGNAL SIGQUIT

Composer

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5",
        "erusev/parsedown": "^1.7",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.5",
        "jenssegers/agent": "^2.6",
        "laravel/cashier": "^11.2",
        "laravel/framework": "^7.0",
        "laravel/horizon": "^4.3",
        "laravel/slack-notification-channel": "^2.0",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^2.0",
        "mpociot/vat-calculator": "^2.4",
        "predis/predis": "^1.1",
        "sentry/sentry-laravel": "^1.8",
        "spatie/laravel-cookie-consent": "^2.12",
        "spatie/laravel-permission": "^3.13",
        "spatie/laravel-web-tinker": "^1.7",
        "stancl/tenancy": "^2.3",
        "superbalist/laravel-google-cloud-storage": "^2.2",
        "unicodeveloper/laravel-password": "^1.0"
    },
    "require-dev": {
        "facade/ignition": "^2.0",
        "friendsofphp/php-cs-fixer": "^2.16",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "sentry/sentry-laravel"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}
stayallive commented 4 years ago

It's a big Dockerfile so a bit impractical for me to try out, but there is 1 thing I notice, you copy the composer.json/.lock and run composer install and only then copy the application sources, possibly this could be an issue you could try to make sure all the application sources are in the container before running composer install.

I also can't see the config/sentry.php (if you have one) but if you have this code uncommented (it's commented by default) it tries to use Git to find a release version which might cause a error since the git repo (or maybe even the git binary) is not available inside your container:

   // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')),

It would really help to see the error output leading up to the non-zero code to see where it's getting stuck because I don't see much Sentry specific code running and I have no clue why a simple composer install would break otherwise.

stayallive commented 4 years ago

I am closing this issue because of inactivity, if there is still an issue please re-open / open a new issue so we can investigate 👍