diff --git a/.gitignore b/.gitignore index 0d8d136..68b1d3e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /tests/resources/functions/**/code.tar.gz /tests/resources/functions/**/code.zip /tests/resources/sites/**/code.tar.gz -/tests/resources/sites/**/code.zip \ No newline at end of file +/tests/resources/sites/**/code.zip diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d38398..a2bc26a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,7 +76,18 @@ Next start the Docker Compose stack that includes executor server with nessessar docker compose up -d ``` -You can now use `http://localhost:9800/v1/` endpoint to communicate with Open Runtimes Executor. You can see 'Getting Started' section of README to learn about endpoints. +For development with live reload, use Docker Compose watch which automatically syncs code changes to the container: + +```bash +docker compose watch +``` + +The `docker-compose.override.yml` file configures the development environment: +- Changes to `app/` and `src/` sync and restart the container +- Changes to `tests/` and `phpunit.xml` sync without restart +- Changes to `composer.json` or `composer.lock` trigger a full rebuild + +You can now use `http://localhost:9900/v1/` endpoint to communicate with Open Runtimes Executor. You can see 'Getting Started' section of README to learn about endpoints. ## Testing @@ -97,19 +108,19 @@ To run tests, you need to start Docker Compose stack, and then run PHPUnit: ```bash docker compose up -d # Wait for ~5 seconds for executor to start -docker run --rm -v $PWD:/app --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c \ "composer test" +docker run --rm -v $PWD:/app --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c \ "composer test:e2e" ``` -To run linter, you need to run Pint: +To format, you can run Pint with: ```bash composer format ``` -To run static code analysis, you need to run PHPStan: +To run static code analysis, you can run PHPStan with: ```bash -composer check +composer analyze ``` ## Introducing New Features @@ -148,4 +159,4 @@ Submitting documentation updates, enhancements, designs, or bug fixes. Spelling ### Helping Someone -Searching for Open Runtimes, GitHub or StackOverflow and helping someone else who needs help. You can also help by teaching others how to contribute to Open Runtimes repo! \ No newline at end of file +Searching for Open Runtimes, GitHub or StackOverflow and helping someone else who needs help. You can also help by teaching others how to contribute to Open Runtimes repo! diff --git a/Dockerfile b/Dockerfile index 8d05f7b..13a9eaa 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ # Install PHP libraries -FROM composer:2.0 AS composer +FROM composer:2.8 AS composer WORKDIR /usr/local/src/ -COPY composer.lock /usr/local/src/ -COPY composer.json /usr/local/src/ +COPY composer.lock composer.json ./ RUN composer install --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist @@ -15,13 +14,13 @@ FROM openruntimes/base:0.1.0 AS final ARG OPR_EXECUTOR_VERSION ENV OPR_EXECUTOR_VERSION=$OPR_EXECUTOR_VERSION -# Source code +# Dependencies first (changes less frequently) +COPY --from=composer /usr/local/src/vendor /usr/local/vendor + +# Source code last (changes more frequently) COPY ./app /usr/local/app COPY ./src /usr/local/src -# Extensions and libraries -COPY --from=composer /usr/local/src/vendor /usr/local/vendor - HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 CMD curl -sf http://127.0.0.1:80/v1/health CMD [ "php", "app/http.php" ] diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..d9d5685 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,27 @@ +# Development overrides - use with `docker compose watch` +services: + openruntimes-executor: + restart: unless-stopped + env_file: + - .env + volumes: + - ./tests/resources/functions:/storage/functions:rw + - ./tests/resources/sites:/storage/sites:rw + develop: + watch: + - action: sync+restart + path: ./app + target: /usr/local/app + - action: sync+restart + path: ./src + target: /usr/local/src + - action: sync + path: ./tests + target: /usr/local/tests + - action: sync + path: ./phpunit.xml + target: /usr/local/phpunit.xml + - action: rebuild + path: ./composer.json + - action: rebuild + path: ./composer.lock diff --git a/docker-compose.yml b/docker-compose.yml index 6e8700a..3c4f2b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,6 @@ -# WARNING! -# This is a development version of the docker-compose.yml file. -# Avoid using this file in your production environment. -# We're exposing here sensitive ports and mounting code volumes for rapid development and debugging of the server stack. - -x-logging: &x-logging - logging: - driver: "json-file" - options: - max-file: "5" - max-size: "10m" - services: openruntimes-executor: hostname: executor - <<: *x-logging - stop_signal: SIGINT build: context: . networks: @@ -29,15 +15,9 @@ services: start_period: 120s volumes: - /var/run/docker.sock:/var/run/docker.sock - - ./app:/usr/local/app:rw - - ./src:/usr/local/src:rw - - ./tests:/usr/local/tests:rw - - ./phpunit.xml:/usr/local/phpunit.xml - openruntimes-builds:/storage/builds:rw - openruntimes-functions:/storage/functions:rw - /tmp:/tmp:rw - - ./tests/resources/functions:/storage/functions:rw - - ./tests/resources/sites:/storage/sites:rw environment: - OPR_EXECUTOR_ENV - OPR_EXECUTOR_IMAGES