Skip to content

Commit 8f89c23

Browse files
authored
ci: test flex images (#435)
* ci: test flex images * chore(docker): obsolete 6.1.0 * chore(docker): obsolete flex-3.18 * ci(test workflows): collect prod docker dirs automatically * ci(test workflow): automatically build test matrix
1 parent d9a267b commit 8f89c23

33 files changed

+125
-56
lines changed

.github/README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
# OpenEMR Docker Testing
22

3-
This directory contains a GitHub Actions workflow to test the OpenEMR 7.0.4 Docker image.
3+
## Workflow: Production Docker Test (test-prod.yml)
44

5-
## Workflow: OpenEMR Docker Test
5+
The `test-prod.yml` workflow verifies that the production OpenEMR Docker images can be built correctly and function with a database connection. These images have the OpenEMR code embedded within them and are identified by version numbers (e.g., 7.0.4).
66

7-
The `build-test.yml` workflow verifies that the OpenEMR Docker image can be built correctly and functions with a database connection. It performs the following steps:
7+
The workflow performs the following steps:
88

9-
1. Builds the OpenEMR 7.0.4 Docker image
9+
1. Builds OpenEMR Docker images defined in docker/openemr for numbered versions (e.g., 6.1.0, 7.0.4)
1010
2. Sets up a test environment using Docker Compose with:
1111
- MariaDB 11.4 database
1212
- OpenEMR container connected to the database
1313
3. Verifies that the web server is responding correctly
14+
4. Runs the OpenEMR installation process
15+
5. Executes multiple test suites including unit, fixtures, services, validators, and controllers tests
1416

15-
### Triggers
17+
### Triggers for Production Tests
1618

1719
The workflow runs automatically when:
18-
- Files in the `docker/openemr/7.0.4/` directory are changed on the main branch
19-
- A pull request targeting the main branch changes files in the `docker/openemr/7.0.4/` directory
20+
- Files in the `docker/openemr/[0-9]*.[0-9]*.[0-9]/**` directory are changed on the main branch
21+
- A pull request targeting the main branch changes files in the numbered version directories
2022

21-
It can also be run manually through the GitHub Actions tab using workflow_dispatch.
23+
## Workflow: Flex Docker Test (test-flex.yml)
2224

23-
## Running the Test Manually
25+
The `test-flex.yml` workflow tests the development-oriented "flex" Docker images. Unlike production images, flex builds don't embed the OpenEMR code within the image - they're designed for development purposes where the code is mounted separately.
2426

25-
To run the test manually:
26-
1. Go to the GitHub Actions tab in the repository
27-
2. Select "OpenEMR Docker Test" from the workflows list
28-
3. Click "Run workflow"
29-
4. Choose the branch to run the test on
30-
5. Click "Run workflow"
27+
The workflow performs the following steps:
3128

32-
For debugging purposes, you can enable the tmate debugging option when running the workflow manually. This will provide an SSH connection to the GitHub Actions runner for interactive debugging.
29+
1. Checks out both the openemr-devops repository and the OpenEMR code repository
30+
2. Builds the flex Docker images defined in docker/openemr
31+
3. Sets up a test environment using Docker Compose with:
32+
- MariaDB database
33+
- OpenEMR container with mounted code
34+
4. Verifies that the web server is responding correctly
3335

34-
## Adding Tests for Other OpenEMR Versions
36+
### Triggers for Flex Tests
3537

36-
To add tests for other OpenEMR versions:
37-
1. Copy the existing workflow and update the version number
38-
2. Update the paths in the workflow triggers
39-
3. Update the image tags and other version-specific information
38+
The workflow runs automatically when:
39+
- Files in the `docker/openemr/**` directory are changed on the main branch
40+
- A pull request targeting the main branch changes files in the docker/openemr directory

.github/workflows/test.yml

Lines changed: 93 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,96 @@ on:
55
branches:
66
- master
77
paths:
8-
- '.github/workflows/test.yml'
9-
- 'docker/openemr/**'
8+
- '.github/workflows/test-prod.yml'
9+
- 'docker/openemr/[0-9]*.[0-9]*.[0-9]/**'
10+
- 'docker/openemr/flex-*/**'
1011
pull_request:
1112
branches:
1213
- master
1314
paths:
14-
- '.github/workflows/test.yml'
15-
- 'docker/openemr/**'
15+
- '.github/workflows/test-prod.yml'
16+
- 'docker/openemr/[0-9]*.[0-9]*.[0-9]/**'
17+
- 'docker/openemr/flex-*/**'
18+
19+
env:
20+
COMPOSE_BAKE: "1"
21+
DOCKER_BUILDKIT: "1"
1622

1723
jobs:
24+
collect:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Collect OpenEMR Prod Dockerfiles
29+
id: docker-dirs
30+
##
31+
# Parse out the test parameters from subdirectories of docker/openemr
32+
# Use that output as a test matrix in github actions.
33+
run: |
34+
shopt -s nullglob
35+
dirs=( docker/openemr/*/Dockerfile )
36+
if (( "${#dirs[@]}" == 0 )); then
37+
echo 'No Dockerfiles found in docker/openemr subdirectories.' >&2
38+
exit 1
39+
fi
40+
dirs=( "${dirs[@]%/Dockerfile}" )
41+
dirs=( "${dirs[@]#docker/openemr/}" )
42+
# Use jq to ensure that the output is valid JSON or fail trying.
43+
# The output (after '=') must be valid JSON for GitHub Actions to use it as a matrix.
44+
{
45+
printf 'docker_dirs='
46+
printf '"%s"\n' "${dirs[@]}" | jq -sc '.'
47+
} >> "$GITHUB_OUTPUT"
48+
outputs:
49+
docker_dirs: ${{ steps.docker-dirs.outputs.docker_dirs }}
1850
build-and-test:
1951
name: Test OpenEMR Image
2052
runs-on: ubuntu-latest
53+
needs: collect
2154
strategy:
2255
fail-fast: false
2356
matrix:
24-
docker-dir:
25-
- 6.1.0
26-
- 7.0.0
27-
- 7.0.1
28-
- 7.0.2
29-
- 7.0.3
30-
- 7.0.4
57+
docker-dir: ${{ fromJson(needs.collect.outputs.docker_dirs) }}
3158
defaults:
3259
run:
33-
working-directory: docker/openemr
60+
working-directory: openemr-devops/docker/openemr
61+
env:
62+
COMPOSE_PROFILES: "${{ startsWith(matrix.docker-dir, 'flex-') && 'flex' || 'prod' }}"
63+
DOCKER_CONTEXT_PATH: "${{ matrix.docker-dir }}"
64+
OPENEMR_SERVICE_NAME: "${{ startsWith(matrix.docker-dir, 'flex-') && 'openemr-flex' || 'openemr' }}"
3465

3566
steps:
3667
- name: Checkout
3768
uses: actions/checkout@v3
69+
with:
70+
path: openemr-devops
71+
72+
- name: Checkout OpenEMR
73+
if: ${{ startsWith(matrix.docker-dir, 'flex-') }}
74+
uses: actions/checkout@v3
75+
with:
76+
repository: openemr/openemr
77+
path: openemr
78+
79+
- name: Verify Docker Compose Configuration
80+
run: docker compose config
3881

3982
- name: Build the Docker image
40-
env:
41-
COMPOSE_BAKE: "1"
42-
DOCKER_BUILDKIT: "1"
43-
DOCKER_CONTEXT_PATH: "${{matrix.docker-dir}}"
4483
run: docker compose build
4584

4685
- name: Run the containers
47-
run: docker compose up --detach --wait --wait-timeout 180
86+
run: docker compose up --detach --wait --wait-timeout 600
4887

4988
- name: Check container status
89+
if: always()
5090
run: |
5191
docker compose ps
52-
docker compose logs openemr
92+
docker compose logs "${OPENEMR_SERVICE_NAME}"
93+
94+
- name: Get PHP Configuration
95+
if: always()
96+
run: |
97+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" php -i
5398
5499
- name: Test web connectivity
55100
run: |
@@ -63,42 +108,56 @@ jobs:
63108
echo "OpenEMR web server is not responding correctly!"
64109
exit 1
65110
66-
- name: Install and configure
111+
- name: Install
67112
run: |
68113
docker compose exec --workdir /var/www/localhost/htdocs/openemr/contrib/util/installScripts \
69-
openemr sh -c 'sed -e "s@^exit;@ @" InstallerAuto.php |
70-
php -- rootpass=root server=mysql loginhost=%'
71-
docker compose exec openemr mysql -u openemr --password="openemr" -h mysql -e 'INSERT INTO product_registration (opt_out) VALUES (1);
72-
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_api";
73-
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_fhir_api";
74-
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_portal_api";
75-
UPDATE globals SET gl_value = 3 WHERE gl_name = "oauth_password_grant";
76-
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_system_scopes_api";' openemr
77-
docker compose exec openemr composer install --dev --no-interaction --optimize-autoloader
114+
"${OPENEMR_SERVICE_NAME}" sh -c 'sed -e "s@^exit;@ @" InstallerAuto.php |
115+
php -- rootpass=root server=mysql loginhost=%'
116+
- name: Initialize MySQL
117+
run: |
118+
docker compose exec "${OPENEMR_SERVICE_NAME}" mysql -u openemr --password="openemr" -h mysql -e '
119+
INSERT INTO product_registration (opt_out) VALUES (1);
120+
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_api";
121+
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_fhir_api";
122+
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_portal_api";
123+
UPDATE globals SET gl_value = 3 WHERE gl_name = "oauth_password_grant";
124+
UPDATE globals SET gl_value = 1 WHERE gl_name = "rest_system_scopes_api";
125+
' openemr
126+
127+
- name: Install Dev Tools
128+
run: |
129+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
130+
composer install --dev --no-interaction --optimize-autoloader --ignore-platform-reqs
78131
79132
- name: Unit Test
80133
run: |
81-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite unit
134+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
135+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite unit
82136
83137
- name: Fixtures testing
84138
run: |
85-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite fixtures
139+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
140+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite fixtures
86141
87142
- name: Services testing
88143
run: |
89-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite services
144+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
145+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite services
90146
91147
- name: Validators testing
92148
run: |
93-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite validators
149+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
150+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite validators
94151
95152
- name: Controllers testing
96153
run: |
97-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite controllers
154+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
155+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite controllers
98156
99157
- name: Common testing
100158
run: |
101-
docker compose exec openemr php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite common
159+
docker compose exec --workdir /var/www/localhost/htdocs/openemr "${OPENEMR_SERVICE_NAME}" \
160+
php -d memory_limit=8G ./vendor/bin/phpunit --colors=always --testdox --stop-on-failure --testsuite common
102161
103162
- name: Cleanup
104163
if: always()

docker/openemr/compose.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ services:
1919
timeout: 5s
2020
retries: 3
2121
openemr:
22+
profiles:
23+
- prod
2224
build:
2325
context: ${DOCKER_CONTEXT_PATH}
2426
ports:
@@ -40,8 +42,15 @@ services:
4042
- curl
4143
- -fsSLo/dev/null
4244
- http://localhost/
43-
start_period: 1m
45+
start_period: 10m
4446
start_interval: 10s
4547
interval: 1m
4648
timeout: 5s
4749
retries: 3
50+
openemr-flex:
51+
extends:
52+
service: openemr
53+
profiles: !override
54+
- flex
55+
volumes:
56+
- ../../openemr:/var/www/localhost/htdocs/openemr
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)