diff --git a/.github/workflows/deny-test.yml b/.github/workflows/deny-test.yml index 9efba087e88..fea4e4c6ef4 100644 --- a/.github/workflows/deny-test.yml +++ b/.github/workflows/deny-test.yml @@ -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 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 1318e4fa5cd..ba237276473 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} @@ -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 \ No newline at end of file diff --git a/docker-compose.mysql.yml b/docker-compose.mysql.yml index dbdff19f635..76367640394 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 @@ -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 \ No newline at end of file diff --git a/docker-compose.pgsql.yml b/docker-compose.pgsql.yml index 38ddbb798df..f6594d2b7d3 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 @@ -15,7 +16,6 @@ services: postgres: image: postgres:14 environment: - POSTGRES_DB: eccubedb POSTGRES_USER: dbuser POSTGRES_PASSWORD: secret ports: @@ -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 \ 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..e77990554b3 100755 --- a/dockerbuild/docker-php-entrypoint +++ b/dockerbuild/docker-php-entrypoint @@ -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` 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