Skip to content

Instantly share code, notes, and snippets.

@hallboav
Last active February 23, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallboav/ab3edf8f3a3496669b6a38e170bfad54 to your computer and use it in GitHub Desktop.
Save hallboav/ab3edf8f3a3496669b6a38e170bfad54 to your computer and use it in GitHub Desktop.
Passando variáveis de ambiente para o container do zend-server
FROM php-zendserver:2018.0
# Valor padrão (usuado quando --env não for passado no docker run)
ENV APPLICATION_ENV local
# Patch
# Encontrei dois grandes problemas:
# 1. A imagem inicia um processo chamado /usr/local/zs-init/init.php que faz uma série de passos. Um desses passos é
# iniciar o zend-server através do systemd (via service). Isso é considerado uma má prática, visto que não devemos
# ter mais do que um processo por container. Além disso, o systemd isola variáveis de ambiente.
# @see https://askubuntu.com/questions/813588/systemctl-failed-to-connect-to-bus-docker-ubuntu16-04-container
# 2. O /usr/local/zend/bin/zendctl.sh chama o /usr/local/zend/bin/apachectl que chama o /etc/init.d/apache2 para
# gerenciar o apache, mas segundo a documentação oficial o /etc/init.d/apache2 não deve ser chamado diretamente,
# somente através do apache2ctl.
# @see https://askubuntu.com/questions/146688/why-doesnt-apache2-respect-my-envvars-file
RUN sed -i "s/\/usr\/sbin\/service /\/etc\/init\.d\//" /usr/local/zs-init/src/Init/Steps/AbstractStep.php && \
sed -i "s/\/usr\/sbin\/service {\$service} {\$action}/\/etc\/init\.d\/zend-server {\$action}-apache/" /usr/local/zs-init/src/Init/Steps/DeploymentStep.php && \
sed -i "s/\/etc\/init\.d\/apache2/\/usr\/sbin\/apache2ctl/" /usr/local/zend/bin/apachectl
# Apenas pra ver funcionando
RUN echo "<?php phpinfo(INFO_ENVIRONMENT);" > /var/www/html/index.php && \
sed -i "14i\\\tSetEnv APPLICATION_ENV \${APPLICATION_ENV}" /etc/apache2/sites-available/000-default.conf && \
sed -i "s/\/var\/log\/zs-init\.log/php:\/\/stdout/" /usr/local/zs-init/src/Init/Process.php
run: build
docker run \
--publish 8080:80 \
--publish 10081:10081 \
--env APPLICATION_ENV=staging \
--env ZS_ADMIN_PASSWORD=admin \
--env ZEND_LICENSE_ORDER=FOO \
--env ZEND_LICENSE_KEY=BAR \
--name zs \
zs:latest
build:
docker build \
--no-cache \
--tag zs:latest \
.
clean:
docker rm -f zs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment