diff --git a/.gitignore b/.gitignore index b91aab8..08cbe61 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ vendor/ .DS_Store .phpunit* *.cache -.vscode/ \ No newline at end of file +.vscode/ diff --git a/Dockerfile b/Dockerfile index 58412b9..ddcd6f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,16 @@ -# Default Dockerfile -# -# @link https://www.hyperf.io -# @document https://hyperf.wiki -# @contact group@hyperf.io -# @license https://github.com/hyperf/hyperf/blob/master/LICENSE +FROM composer:2.7 as vendor + +COPY . /app + +COPY composer.json composer.json +COPY composer.lock composer.lock + +RUN composer install \ + --ignore-platform-reqs \ + --no-interaction \ + --no-plugins \ + --no-scripts \ + --prefer-dist FROM hyperf/hyperf:8.1-alpine-v3.18-swoole LABEL maintainer="Hyperf Developers " version="1.0" license="MIT" app.name="Hyperf" @@ -42,12 +49,9 @@ RUN set -ex \ WORKDIR /opt/www -# Composer Cache -# COPY ./composer.* /opt/www/ -# RUN composer install --no-dev --no-scripts - COPY . /opt/www -RUN composer install --no-dev -o && php bin/hyperf.php + +COPY --from=vendor /app/vendor/ /opt/www/vendor/ EXPOSE 9501 diff --git a/docker-compose.yml b/docker-compose.yml index 8f6878a..8b08c48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,27 @@ version: '3' services: hyperf-skeleton: - container_name: hyperf-skeleton - image: hyperf-skeleton + container_name: labs-api + image: labs-api build: context: . volumes: - ./:/opt/www + - /opt/www/vendor ports: - 9501:9501 - 9500:9500 environment: - APP_ENV=dev - SCAN_CACHEABLE=false - entrypoint: ["php", "/opt/www/bin/hyperf.php", "server:watch"] + # entrypoint: ["php", "/opt/www/bin/hyperf.php", "server:watch"] + entrypoint: ["/opt/www/docker/entrypoint.sh"] + depends_on: + db-labs: + condition: service_healthy - db: - container_name: mysql8 + db-labs: + container_name: db-labs image: mysql:8.3 command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci environment: @@ -28,6 +33,10 @@ services: - './docker/db/data:/var/lib/mysql' - './docker/db/my.cnf:/etc/mysql/conf.d/my.cnf' - './docker/db/sql:/docker-entrypoint-initdb.d' + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 20s + retries: 10 networks: default: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..b71ab4d --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "Migrate" +php /opt/www/bin/hyperf.php migrate + +echo "Starting my application..." +php /opt/www/bin/hyperf.php start