From 4047d13095899a99d4d21188922d4075817ebe88 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Thu, 26 May 2022 22:47:42 +0900 Subject: [PATCH 1/6] =?UTF-8?q?SKIP=5FINSTALL=5FSCRIPT=5FON=5FDOCKER=5FBUI?= =?UTF-8?q?LD=E3=82=92=E5=BB=83=E6=AD=A2=E3=81=97=E3=81=A6=E5=88=9D?= =?UTF-8?q?=E5=9B=9E=E5=AE=9F=E8=A1=8C=E6=99=82=E3=81=AB=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 40 ------------------------------- composer.json | 2 +- docker-compose.mysql.yml | 8 ++++++- docker-compose.pgsql.yml | 8 ++++++- docker-compose.yml | 4 ---- dockerbuild/docker-php-entrypoint | 17 +++++++++++++ 6 files changed, 32 insertions(+), 47 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1318e4fa5cd..f01206b91d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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} @@ -98,20 +75,3 @@ RUN find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune && find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or \( -type d -print0 \) \ | 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 diff --git a/composer.json b/composer.json index 2fdb32fdbda..f4be62b304a 100644 --- a/composer.json +++ b/composer.json @@ -156,7 +156,7 @@ "assets:install --symlink --relative html": "symfony-cmd" }, "installer-scripts": { - "doctrine:database:create": "bin/console doctrine:database:create", + "doctrine:database:create": "bin/console doctrine:database:create --if-not-exists", "doctrine:schema:create": "bin/console doctrine:schema:create", "eccube:fixtures:load": "bin/console eccube:fixtures:load" }, diff --git a/docker-compose.mysql.yml b/docker-compose.mysql.yml index dbdff19f635..b5558c75e5d 100644 --- a/docker-compose.mysql.yml +++ b/docker-compose.mysql.yml @@ -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 @@ -25,3 +26,8 @@ services: - 13306:3306 networks: - backend + healthcheck: + test: mysqladmin ping + interval: 3s + timeout: 3s + retries: 3 \ No newline at end of file diff --git a/docker-compose.pgsql.yml b/docker-compose.pgsql.yml index 38ddbb798df..58491df9854 100644 --- a/docker-compose.pgsql.yml +++ b/docker-compose.pgsql.yml @@ -7,7 +7,8 @@ volumes: services: ec-cube: depends_on: - - postgres + postgres: + condition: service_healthy environment: DATABASE_URL: "postgres://dbuser:secret@postgres/eccubedb" DATABASE_SERVER_VERSION: 14 @@ -24,3 +25,8 @@ services: - pg-database:/var/lib/postgresql/data networks: - backend + healthcheck: + test: pg_isready -U dbuser + interval: 3s + timeout: 3s + retries: 3 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cacdd309ea1..f1d4e72a349 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/dockerbuild/docker-php-entrypoint b/dockerbuild/docker-php-entrypoint index d6a715602e1..81ef8db4de3 100755 --- a/dockerbuild/docker-php-entrypoint +++ b/dockerbuild/docker-php-entrypoint @@ -1,6 +1,23 @@ #!/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 +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 +) + echo "PassEnv APP_ENV APP_DEBUG TRUSTED_PROXIES TRUSTED_HOSTS" > /etc/apache2/conf-enabled/eccube_env.conf # first arg is `-f` or `--some-option` From a5651ac5cbfb8377458601ea98c67441c09e5472 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Fri, 27 May 2022 19:02:55 +0900 Subject: [PATCH 2/6] =?UTF-8?q?www-data=E3=81=A7=E5=AE=9F=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dockerbuild/docker-php-entrypoint | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dockerbuild/docker-php-entrypoint b/dockerbuild/docker-php-entrypoint index 81ef8db4de3..f1120e06357 100755 --- a/dockerbuild/docker-php-entrypoint +++ b/dockerbuild/docker-php-entrypoint @@ -8,14 +8,14 @@ if [ ! -d /var/www/html/vendor/bin ]; then --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 + su www-data -s /bin/sh -c 'cp .env.dist .env' fi - composer run-script installer-scripts - composer run-script auto-scripts + su www-data -s /bin/sh -c 'composer run-script installer-scripts && composer run-script auto-scripts' ) echo "PassEnv APP_ENV APP_DEBUG TRUSTED_PROXIES TRUSTED_HOSTS" > /etc/apache2/conf-enabled/eccube_env.conf From 8f2f8696327b49b9d3eb58bfc2dfb8f935bad656 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Fri, 27 May 2022 19:08:50 +0900 Subject: [PATCH 3/6] =?UTF-8?q?ec-cube=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A?= =?UTF-8?q?=E3=81=8C=E8=B5=B7=E5=8B=95=E3=81=99=E3=82=8B=E3=81=BE=E3=81=A7?= =?UTF-8?q?=E5=BE=85=E6=A9=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dockerbuild.yml | 8 +++----- Dockerfile | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index 2fe7b5dc642..e1cebcfa1ae 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index f01206b91d2..ba237276473 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,3 +75,5 @@ RUN find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune && find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or \( -type d -print0 \) \ | xargs -0 chmod g+s \ ; + +HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD pgrep apache \ No newline at end of file From 0ad0fbcde95b772647d946eab55d30afd518a372 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Fri, 27 May 2022 19:42:48 +0900 Subject: [PATCH 4/6] =?UTF-8?q?SQLite=E3=81=A7=E5=88=A9=E7=94=A8=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E3=81=AE=E3=81=A7`--if-not-exists`?= =?UTF-8?q?=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- docker-compose.mysql.yml | 2 +- docker-compose.pgsql.yml | 1 - dockerbuild/docker-php-entrypoint | 9 +++++++-- dockerbuild/grant_to_dbuser.sql | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 dockerbuild/grant_to_dbuser.sql diff --git a/composer.json b/composer.json index f4be62b304a..2fdb32fdbda 100644 --- a/composer.json +++ b/composer.json @@ -156,7 +156,7 @@ "assets:install --symlink --relative html": "symfony-cmd" }, "installer-scripts": { - "doctrine:database:create": "bin/console doctrine:database:create --if-not-exists", + "doctrine:database:create": "bin/console doctrine:database:create", "doctrine:schema:create": "bin/console doctrine:schema:create", "eccube:fixtures:load": "bin/console eccube:fixtures:load" }, diff --git a/docker-compose.mysql.yml b/docker-compose.mysql.yml index b5558c75e5d..76367640394 100644 --- a/docker-compose.mysql.yml +++ b/docker-compose.mysql.yml @@ -17,11 +17,11 @@ 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: diff --git a/docker-compose.pgsql.yml b/docker-compose.pgsql.yml index 58491df9854..f6594d2b7d3 100644 --- a/docker-compose.pgsql.yml +++ b/docker-compose.pgsql.yml @@ -16,7 +16,6 @@ services: postgres: image: postgres:14 environment: - POSTGRES_DB: eccubedb POSTGRES_USER: dbuser POSTGRES_PASSWORD: secret ports: diff --git a/dockerbuild/docker-php-entrypoint b/dockerbuild/docker-php-entrypoint index f1120e06357..e77990554b3 100755 --- a/dockerbuild/docker-php-entrypoint +++ b/dockerbuild/docker-php-entrypoint @@ -13,9 +13,14 @@ fi bin/console doctrine:query:sql 'select * from dtb_base_info' > /dev/null 2>&1 || ( if [ -z ${DATABASE_URL} ]; then - su www-data -s /bin/sh -c 'cp .env.dist .env' + cp .env.dist .env fi - su www-data -s /bin/sh -c 'composer run-script installer-scripts && composer run-script auto-scripts' + 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 diff --git a/dockerbuild/grant_to_dbuser.sql b/dockerbuild/grant_to_dbuser.sql new file mode 100644 index 00000000000..088d458f684 --- /dev/null +++ b/dockerbuild/grant_to_dbuser.sql @@ -0,0 +1 @@ +GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%'; \ No newline at end of file From 7372f65a2c4e0857766b9f53477856608ac4414a Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 7 Jun 2022 22:05:56 +0900 Subject: [PATCH 5/6] =?UTF-8?q?ec-cube=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A?= =?UTF-8?q?=E3=81=8C=E8=B5=B7=E5=8B=95=E3=81=99=E3=82=8B=E3=81=BE=E3=81=A7?= =?UTF-8?q?=E5=BE=85=E3=81=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deny-test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deny-test.yml b/.github/workflows/deny-test.yml index 9efba087e88..538361b3b2e 100644 --- a/.github/workflows/deny-test.yml +++ b/.github/workflows/deny-test.yml @@ -96,6 +96,12 @@ jobs: - 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 From fc93eea56d2c58f1151e0de858f642fa4b9f06b0 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 7 Jun 2022 23:05:14 +0900 Subject: [PATCH 6/6] =?UTF-8?q?SKIP=5FINSTALL=5FSCRIPT=5FON=5FDOCKER=5FBUI?= =?UTF-8?q?LD=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deny-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deny-test.yml b/.github/workflows/deny-test.yml index 538361b3b2e..fea4e4c6ef4 100644 --- a/.github/workflows/deny-test.yml +++ b/.github/workflows/deny-test.yml @@ -91,7 +91,7 @@ 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: |