Symfony部署在kubernetes-env问题上



我有一个symfony应用程序和三个kubernetes集群:dev、staging prod.

我正在使用env文件来设置环境。我用正确的.env构建docker镜像,并通过kubectl进行部署。但事实上,APP_ENV的值没有被考虑在内,即使其他参数是(例如数据库连接)。

我的暂存env被设置为";测试";但是composer仍然安装dev依赖项,日志转到/var/log/dev.log;测试";根据.env文件。我仍然发现";本地";相反

我做错了什么?

我的staging.env文件:

#  * .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

###> symfony/framework-bundle ###
APP_ENV=test
APP_SECRET=XXXXXXX
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#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:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=postgresql://root:root@postgres:5432/dbb
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
#CORS_ALLOW_ORIGIN=^https?://(localhost|127.0.0.1)(:[0-9]+)?$
CORS_ALLOW_ORIGIN=^https://my-domain.com
###< nelmio/cors-bundle ###
###> lexik/jwt-authentication-bundle ###
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
###< lexik/jwt-authentication-bundle ###
###> nzo/elk-bundle ###
ELK_APP_NAME=my-app
ELK_APP_ENVIRONMENT=test
###< nzo/elk-bundle ###

Docker文件:

FROM php:7.4-fpm
WORKDIR /app
# Install selected extensions (git, git-flow and other stuff)
RUN apt-get update 
&& apt-get install -y --no-install-recommends zlib1g-dev libpq-dev git git-flow libicu-dev libxml2-dev libzip-dev
&& docker-php-ext-configure intl 
&& docker-php-ext-install intl 
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql 
&& docker-php-ext-install pdo pdo_pgsql pgsql 
&& docker-php-ext-install zip xml 
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer 
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
COPY ./my-project/ /usr/src/my-project
COPY docker-dist/back/config/php/php.ini /usr/local/etc/php/
COPY docker-entrypoint.sh /entrypoint.sh
RUN composer install --working-dir=/usr/src/my-project
# WORKDIR is /var/www/html (inherited via "FROM php")
# "/entrypoint.sh" will populate it at container startup from /usr/src/my-project
VOLUME /var/www/app
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"]

似乎预热工作不正常。

我仔细查看了我的docker入口点,并设法在里面运行composer安装和缓存清理。

问题解决了。

谢谢大家。

entrypoint.sh:

set -e
cd /var/www/app
tar cf - --one-file-system -C /usr/src/myapp . | tar xf -
rm -rf var/cache var/log
composer install
php bin/console cache:clear --env=dev
chown -R www-data:www-data .
exec "$@"```

相关内容

  • 没有找到相关文章

最新更新