Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コンテナビルド時にEC-CUBEを初期化せずに、コンテナ初回起動時に初期化する。 #5369

Merged
merged 7 commits into from
Jul 12, 2022
8 changes: 7 additions & 1 deletion .github/workflows/deny-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ jobs:
run: ${{ github.event.repository.name }}/package.sh

- name: Build Container
run: docker build -t ec-cube --build-arg SKIP_INSTALL_SCRIPT_ON_DOCKER_BUILD=true .
run: docker build -t ec-cube .

- name: Container Run
run: |
docker run -e APP_ENV=prod -e APP_DEBUG=0 -e DATABASE_URL="sqlite:///var/eccube.db" -e DATABASE_SERVER_VERSION=3 --rm -d -p 8080:80 --name eccube ec-cube
echo -n $(docker inspect -f {{.State.Health.Status}} eccube)
until [ $(docker inspect -f {{.State.Health.Status}} eccube) != "starting" ]; do
echo -n .
sleep 10;
done;
docker inspect -f {{.State.Health.Status}} eccube
docker cp ../eccube.tar.gz eccube:/tmp/
docker exec -w /tmp eccube bash -c "rm -rf /var/www/html; tar xf /tmp/eccube.tar.gz -C /var/www; mv /var/www/ec-cube /var/www/html; chown -R www-data: /var/www/html"
docker exec -u www-data eccube bin/console eccube:install -n
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/checkout@master

- name: docker build
run: docker-compose build
run: docker compose build

- name: Get Composer Cache Directory
id: composer-cache
Expand All @@ -70,11 +70,9 @@ jobs:
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
run: |
docker-compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d
docker-compose -f docker-compose.yml -f docker-compose.pgsql.yml exec -T ec-cube bin/console doctrine:schema:create --env=dev
docker-compose -f docker-compose.yml -f docker-compose.pgsql.yml exec -T ec-cube bin/console eccube:fixtures:load --env=dev
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait
sed -i 's!APP_ENV: "dev"!APP_ENV: "prod"!g' docker-compose.yml
docker-compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait

- name: setup-chromedriver
uses: nanasess/setup-chromedriver@master
Expand Down
40 changes: 1 addition & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,12 @@ RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY dockerbuild/php.ini $PHP_INI_DIR/conf.d/
COPY dockerbuild/docker-php-entrypoint /usr/local/bin/

RUN chown www-data:www-data /var/www \
&& mkdir -p ${APACHE_DOCUMENT_ROOT}/vendor \
&& mkdir -p ${APACHE_DOCUMENT_ROOT}/var \
&& chown www-data:www-data ${APACHE_DOCUMENT_ROOT}/vendor \
&& chmod g+s ${APACHE_DOCUMENT_ROOT}/vendor \
&& chown www-data:www-data ${APACHE_DOCUMENT_ROOT}/var

RUN curl -sS https://getcomposer.org/installer \
| php \
&& mv composer.phar /usr/bin/composer

# 全体コピー前にcomposer installを先行完了させる(docker cache利用によるリビルド速度向上)

RUN composer config -g repos.packagist composer https://packagist.jp
COPY composer.json ${APACHE_DOCUMENT_ROOT}/composer.json
COPY composer.lock ${APACHE_DOCUMENT_ROOT}/composer.lock
RUN chown www-data:www-data ${APACHE_DOCUMENT_ROOT}/composer.*

USER www-data
RUN composer install \
--no-scripts \
--no-autoloader \
--no-plugins \
-d ${APACHE_DOCUMENT_ROOT} \
;

##################################################################
# ファイル変更時、以後のステップにはキャッシュが効かなくなる
USER root
COPY . ${APACHE_DOCUMENT_ROOT}
WORKDIR ${APACHE_DOCUMENT_ROOT}

Expand All @@ -99,19 +76,4 @@ RUN find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune
| xargs -0 chmod g+s \
;

USER www-data
RUN composer dumpautoload -o --apcu

RUN if [ ! -f ${APACHE_DOCUMENT_ROOT}/.env ]; then \
cp -p .env.dist .env \
; fi

# trueを指定した場合、DBマイグレーションやECCubeのキャッシュ作成をスキップする。
# ビルド時点でDBを起動出来ない場合等に指定が必要となる。
ARG SKIP_INSTALL_SCRIPT_ON_DOCKER_BUILD=false

RUN if [ ! -f ${APACHE_DOCUMENT_ROOT}/var/eccube.db ] && [ ! ${SKIP_INSTALL_SCRIPT_ON_DOCKER_BUILD} = "true" ]; then \
composer run-script installer-scripts && composer run-script auto-scripts \
; fi

USER root
HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD pgrep apache
10 changes: 8 additions & 2 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ volumes:
services:
ec-cube:
depends_on:
- mysql
mysql:
condition: service_healthy
environment:
DATABASE_URL: "mysql://dbuser:secret@mysql/eccubedb"
DATABASE_SERVER_VERSION: 5.7
Expand All @@ -16,12 +17,17 @@ services:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: eccubedb
MYSQL_USER: dbuser
MYSQL_PASSWORD: secret
volumes:
- mysql-database:/var/lib/mysql
- ./dockerbuild/grant_to_dbuser.sql:/docker-entrypoint-initdb.d/grant_to_dbuser.sql
ports:
- 13306:3306
networks:
- backend
healthcheck:
test: mysqladmin ping
interval: 3s
timeout: 3s
retries: 3
9 changes: 7 additions & 2 deletions docker-compose.pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ volumes:
services:
ec-cube:
depends_on:
- postgres
postgres:
condition: service_healthy
environment:
DATABASE_URL: "postgres://dbuser:secret@postgres/eccubedb"
DATABASE_SERVER_VERSION: 14

postgres:
image: postgres:14
environment:
POSTGRES_DB: eccubedb
POSTGRES_USER: dbuser
POSTGRES_PASSWORD: secret
ports:
Expand All @@ -24,3 +24,8 @@ services:
- pg-database:/var/lib/postgresql/data
networks:
- backend
healthcheck:
test: pg_isready -U dbuser
interval: 3s
timeout: 3s
retries: 3
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ services:
ec-cube:
build:
context: .
args:
# ビルド時のECCubeインストールスクリプトをスキップする場合にtrueを指定する。
# ビルド時点でDBサーバの起動や接続が出来ない、という場合等にエラーとなるため。
SKIP_INSTALL_SCRIPT_ON_DOCKER_BUILD: "true"
ports:
- 8080:80
- 4430:443
Expand Down
22 changes: 22 additions & 0 deletions dockerbuild/docker-php-entrypoint
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/bin/sh
set -e

if [ ! -d /var/www/html/vendor/bin ]; then
composer install \
--no-scripts \
--no-autoloader \
--no-plugins \
-d ${APACHE_DOCUMENT_ROOT}
composer dumpautoload -o --apcu
chown -R www-data: vendor
fi

bin/console doctrine:query:sql 'select * from dtb_base_info' > /dev/null 2>&1 || (
if [ -z ${DATABASE_URL} ]; then
cp .env.dist .env
fi
composer run-script installer-scripts
composer run-script auto-scripts
find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or -print0 \
| xargs -0 chown www-data:www-data
find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or \( -type d -print0 \) \
| xargs -0 chmod g+s
)

echo "PassEnv APP_ENV APP_DEBUG TRUSTED_PROXIES TRUSTED_HOSTS" > /etc/apache2/conf-enabled/eccube_env.conf

# first arg is `-f` or `--some-option`
Expand Down
1 change: 1 addition & 0 deletions dockerbuild/grant_to_dbuser.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%';