我正在尝试通过Docker站起一个PHP application。我可以手动使用它,但是我正在尝试按照最佳做法(例如:单责任形象等)对其进行改进(使其在CI / CD环境中更加可用)
TLDR:
问题:
TAO_CODE_TAG
的正确值,但在结帐期间失败(视为空)
RUN echo $var
一起工作的工作示例?./。env
PHP_VERSION=7.0
MYSQL_VERSION=5.7
APACHE_VERSION=2.4.32
TAO_CODE_TAG=v3.2-rc02
DB_ROOT_PWD=password ;-)
./ docker-compose.yml
version: "3.2"
services:
git:
build:
context: './git/'
args:
TAO_CODE_TAG: ${TAO_CODE_TAG:?err}
volumes:
- ./tao-src/:/build
container_name: git
composer:
image: composer/composer:php7 # Would be nice to use tag from .env for php version
command: install
depends_on:
- git
volumes:
- ./tao-src/:/app
container_name: composer
php:
build:
context: './php/'
args:
PHP_VERSION: ${PHP_VERSION:?err}
depends_on:
- composer
networks:
- backend
ports:
- 9000:9000
volumes:
- ./tao-src/:/var/www/html/
container_name: php
apache:
build:
context: './apache/'
args:
APACHE_VERSION: ${APACHE_VERSION:?err}
depends_on:
- git
- php
- mysql
networks:
- frontend
- backend
ports:
- 80:80
volumes:
- ./tao-src/:/var/www/html/
container_name: apache
mysql:
image: mysql:${MYSQL_VERSION:-latest}
networks:
- backend
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PWD:?err}
container_name: mysql
networks:
frontend:
backend:
./ apache / Dockerfile
ARG APACHE_VERSION=""
FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine
# Copy apache vhost file to proxy php requests to php-fpm container
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
>> /usr/local/apache2/conf/httpd.conf
./ apache / demo.apache.conf
ServerName localhost
LoadModule rewrite_module /usr/local/apache2/modules/mod_rewrite.so
LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
<VirtualHost *:80>
# Proxy .php requests to port 9000 of the php-fpm container
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
DocumentRoot /var/www/html/
<Directory /var/www/html/>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
ErrorLog /proc/self/fd/2
</VirtualHost>
.// git / Dockerfile
ARG TAO_CODE_TAG
FROM alpine/git:1.0.4
RUN apk add git \
&& mkdir /build \
&& git clone https://github.com/oat-sa/package-tao /build \
&& cd /build \
&& git checkout tags/v3.2-rc02 # Should use val from .env!
VOLUME ["/build"] # Last in file so as to not "disappear" during build
./ php / Dockerfile
ARG PHP_VERSION=""
FROM php:${PHP_VERSION:+${PHP_VERSION}-}fpm-alpine
# One run/layer as needed/able per recommendation in docs
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
RUN apk update \
# TAO requires zip support
&& apk add libzip-dev zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
# TAO requires pdo_mysql support
&& docker-php-ext-install pdo_mysql \
# TAO recommends opcache
&& docker-php-ext-install opcache \
&& docker-php-ext-configure opcache --enable-opcache \
# Ensure a php.ini is present
&& mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini;
PS:最终,诸如使用秘密服务器获取安全凭据等之类的事情以及将自动install script与.env
文件一起使用的事情将实现为好吧。
答案 0 :(得分:1)
我现在可以进入Web安装页面。所以,对于任何有兴趣的人...
我意识到我所需要的只是compose.json和index.php文件,我可以通过<?php // start
$stmt = $DB_con->prepare("SELECT * FROM cart WHERE cartuser = '$userid' and cartpend='IN CART'");
$stmt->execute();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row); //end ?>
<form method="get" action="btnchange.php">
<input type="hidden" name="prod_id" value="<?php echo $row['cartno']; ?>">
<tbody>
<tr>
<td><?php echo $row['cartno']; ?></td>
<td><?php echo $row['cartname']; ?></td>
<td><?php echo $row['cartprice']; ?></td>
<td><input type="text" name="qty" value="<?php echo $row['cartqty']; ?>"></td>
<td><?php echo $row['cartsub']; ?></td>
<td><span class="label label-primary"><?php echo $row['cartpend']; ?></span></td>
<td><button type="submit" name="submit">Submit Quantity</button></b>
<td><a class="btn btn-danger btn-xs" href="?delete_id=<?php echo $row['cartno']; ?>" title="click for delete" onclick="return confirm('Sure to Delete?')"><i class="fa fa-trash-o"></i> Remove</a></td>
</tr>
</tbody>
</form>
jsdeliver中的dockerfile statements来抓取,然后递归chown / chmod来获取php和apache ADD
文件夹中的新文件。
注意:这并不能真正解决通常从github获取源代码的问题,但足以满足我对特定代码库/项目的实际/即刻需求。
我通过...解决了标签问题
docker-compose.yml
/var/www/html
php / Dockerfile
version: "3.2"
services:
php:
build:
context: './php/'
args:
PHP_VERSION: ${PHP_VERSION:?err}
TAO_CODE_TAG: ${TAO_CODE_TAG:?err} # <-- IMPORTANT
我目前正在通过在php和apache派生的图像容器中复制一个多阶段构建来解决代码/ composer-install的问题,如以上各行所示,然后...
php / Dockerfile
FROM composer/composer as Composed
ARG TAO_CODE_TAG # <-- IMPORTANT
RUN mkdir /build && cd /build
WORKDIR /build
ADD https://cdn.jsdelivr.net/gh/oat-sa/package-tao@${TAO_CODE_TAG}/composer.json /build/composer.json # <-- IMPORTANT
RUN composer install --ignore-platform-reqs --no-scripts --no-suggest --no-dev
# ...continues
不幸的是,这对于php和apache实例都是重复的(要求将代码都放入这两个实例中。)我仍在研究一种创建共享的仅源资源的方法,该资源可以通过共享来访问和映射(大多数可能)。