Skip to content

Commit 16c9235

Browse files
authored
Merge pull request #219 from open-runtimes/refactor-docker-compose
refactor: docker compose
2 parents c21b97e + 2041815 commit 16c9235

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
/tests/resources/functions/**/code.tar.gz
55
/tests/resources/functions/**/code.zip
66
/tests/resources/sites/**/code.tar.gz
7-
/tests/resources/sites/**/code.zip
7+
/tests/resources/sites/**/code.zip

CONTRIBUTING.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ Next start the Docker Compose stack that includes executor server with nessessar
7676
docker compose up -d
7777
```
7878

79-
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.
79+
For development with live reload, use Docker Compose watch which automatically syncs code changes to the container:
80+
81+
```bash
82+
docker compose watch
83+
```
84+
85+
The `docker-compose.override.yml` file configures the development environment:
86+
- Changes to `app/` and `src/` sync and restart the container
87+
- Changes to `tests/` and `phpunit.xml` sync without restart
88+
- Changes to `composer.json` or `composer.lock` trigger a full rebuild
89+
90+
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.
8091

8192
## Testing
8293

@@ -97,19 +108,19 @@ To run tests, you need to start Docker Compose stack, and then run PHPUnit:
97108
```bash
98109
docker compose up -d
99110
# Wait for ~5 seconds for executor to start
100-
docker run --rm -v $PWD:/app --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c \ "composer test"
111+
docker run --rm -v $PWD:/app --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c \ "composer test:e2e"
101112
```
102113

103-
To run linter, you need to run Pint:
114+
To format, you can run Pint with:
104115

105116
```bash
106117
composer format
107118
```
108119

109-
To run static code analysis, you need to run PHPStan:
120+
To run static code analysis, you can run PHPStan with:
110121

111122
```bash
112-
composer check
123+
composer analyze
113124
```
114125

115126
## Introducing New Features
@@ -148,4 +159,4 @@ Submitting documentation updates, enhancements, designs, or bug fixes. Spelling
148159

149160
### Helping Someone
150161

151-
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!
162+
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!

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Install PHP libraries
2-
FROM composer:2.0 AS composer
2+
FROM composer:2.8 AS composer
33

44
WORKDIR /usr/local/src/
55

6-
COPY composer.lock /usr/local/src/
7-
COPY composer.json /usr/local/src/
6+
COPY composer.lock composer.json ./
87

98
RUN composer install --ignore-platform-reqs --optimize-autoloader \
109
--no-plugins --no-scripts --prefer-dist
@@ -15,13 +14,13 @@ FROM openruntimes/base:0.1.0 AS final
1514
ARG OPR_EXECUTOR_VERSION
1615
ENV OPR_EXECUTOR_VERSION=$OPR_EXECUTOR_VERSION
1716

18-
# Source code
17+
# Dependencies first (changes less frequently)
18+
COPY --from=composer /usr/local/src/vendor /usr/local/vendor
19+
20+
# Source code last (changes more frequently)
1921
COPY ./app /usr/local/app
2022
COPY ./src /usr/local/src
2123

22-
# Extensions and libraries
23-
COPY --from=composer /usr/local/src/vendor /usr/local/vendor
24-
2524
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 CMD curl -sf http://127.0.0.1:80/v1/health
2625

2726
CMD [ "php", "app/http.php" ]

docker-compose.override.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Development overrides - use with `docker compose watch`
2+
services:
3+
openruntimes-executor:
4+
restart: unless-stopped
5+
env_file:
6+
- .env
7+
volumes:
8+
- ./tests/resources/functions:/storage/functions:rw
9+
- ./tests/resources/sites:/storage/sites:rw
10+
develop:
11+
watch:
12+
- action: sync+restart
13+
path: ./app
14+
target: /usr/local/app
15+
- action: sync+restart
16+
path: ./src
17+
target: /usr/local/src
18+
- action: sync
19+
path: ./tests
20+
target: /usr/local/tests
21+
- action: sync
22+
path: ./phpunit.xml
23+
target: /usr/local/phpunit.xml
24+
- action: rebuild
25+
path: ./composer.json
26+
- action: rebuild
27+
path: ./composer.lock

docker-compose.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
# WARNING!
2-
# This is a development version of the docker-compose.yml file.
3-
# Avoid using this file in your production environment.
4-
# We're exposing here sensitive ports and mounting code volumes for rapid development and debugging of the server stack.
5-
6-
x-logging: &x-logging
7-
logging:
8-
driver: "json-file"
9-
options:
10-
max-file: "5"
11-
max-size: "10m"
12-
131
services:
142
openruntimes-executor:
153
hostname: executor
16-
<<: *x-logging
17-
stop_signal: SIGINT
184
build:
195
context: .
206
networks:
@@ -29,15 +15,9 @@ services:
2915
start_period: 120s
3016
volumes:
3117
- /var/run/docker.sock:/var/run/docker.sock
32-
- ./app:/usr/local/app:rw
33-
- ./src:/usr/local/src:rw
34-
- ./tests:/usr/local/tests:rw
35-
- ./phpunit.xml:/usr/local/phpunit.xml
3618
- openruntimes-builds:/storage/builds:rw
3719
- openruntimes-functions:/storage/functions:rw
3820
- /tmp:/tmp:rw
39-
- ./tests/resources/functions:/storage/functions:rw
40-
- ./tests/resources/sites:/storage/sites:rw
4121
environment:
4222
- OPR_EXECUTOR_ENV
4323
- OPR_EXECUTOR_IMAGES

0 commit comments

Comments
 (0)