You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce safe headless mode functionality to the application
This enhances its flexibility, robustness, and compatibility with various
environments, including development containers and Docker containers.
Key Changes:
1. **Added headless mode argument**:
- Introduced a `--headless` argument in the main function. This
allows the application to run in headless mode, which is
particularly useful in environments without a display or graphical
interface.
2. **Environment Check for Display**:
- Implemented `is_display_available()` to check if a display
environment is available (i.e., checking the `DISPLAY` environment
variable). This ensures that the application can intelligently
default to headless mode when necessary.
3. **Conditional Display Rendering**:
- Modified the main loop to conditionally display the video feed
using `cv2.imshow` only when not in headless mode. This change
prevents the application from attempting to render visuals when no
display is available or when running in headless mode.
4. **Error Handling for Display Issues**:
- Added a try-except block around `cv2.imshow` to gracefully handle
scenarios where displaying the image is not possible. If an
exception is thrown due to display issues, the application will
switch to headless mode, ensuring continuous operation without
manual intervention.
5. **Dynamic Adjustment to Headless Mode**:
- The application now dynamically adjusts to headless mode if it
detects that no display is available or if it encounters an error
while attempting to show the image. This dynamic adjustment
enhances the application's resilience and usability across
different environments.
6. **Enhanced Container Compatibility**:
- With the addition of headless mode, the application can now be run
in both devcontainers and Docker containers without requiring a
graphical user interface. This enables seamless operation in
headless mode for various development, testing, and production
scenarios, especially in containerized environments.
This update significantly increases the application's deployment
flexibility, allowing it to run seamlessly in various environments, from
development machines with full graphical support to servers and
containers where a graphical interface might not be available.
Testing Done:
* Added tests for ensuring headless mode is set and verified that it works
* Ran the program manually in devcontainer and ensured that it worked.
Copy file name to clipboardExpand all lines: README.md
+54-3
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,49 @@ To use `main.py`:
92
92
93
93
This script will utilize the camera to detect and track faces, and control the T-Shirt launcher based on the tracked positions.
94
94
95
+
96
+
### Headless Mode Operation
97
+
98
+
#### Overview
99
+
100
+
The application now supports a headless mode, allowing it to run without a graphical user interface. This is particularly useful when running in environments that do not have a display, such as Docker containers or servers. The headless mode ensures that all functionalities of the application are available, even without a graphical output, making it ideal for automated, background, or server deployments.
101
+
102
+
#### Running in Headless Mode
103
+
104
+
To run the application in headless mode, use the `--headless` flag when starting the application. This can be combined with other existing flags as needed.
105
+
106
+
**Example Command:**
107
+
108
+
```bash
109
+
python main.py --headless --simulate
110
+
```
111
+
112
+
### Running in Docker Container
113
+
114
+
You could build a Docker container using the information in .devcontainer.json. To run the built image:
115
+
116
+
```bash
117
+
docker run -it --device /dev/video0:/dev/video0 -v /home/user/code/pygptcourse:/tmp/pygptcourse bash
118
+
```
119
+
120
+
**Note:**
121
+
122
+
Ensure that `/dev/video0` is readable and writable by the user running the process.
123
+
124
+
#### Automatic Headless Detection
125
+
126
+
The application automatically detects if it's running in an environment without a display (like a Docker container or a devcontainer) and switches to headless mode. It checks for the DISPLAY environment variable and adjusts its behavior accordingly. This ensures smooth operation across various environments without needing explicit configuration.
127
+
128
+
#### Docker and Devcontainer Support
129
+
130
+
The application is compatible with containerized environments. When running in Docker or devcontainers, the application can automatically operate in headless mode, ensuring that it functions correctly even without a graphical interface. This makes it suitable for a wide range of development, testing, and production scenarios.
131
+
132
+
#### Error Handling in Headless Mode
133
+
134
+
In headless mode, the application gracefully handles any graphical operations that typically require a display. If an attempt is made to perform such operations, the application will log the incident and continue running without interruption. This robust error handling ensures continuous operation, making the application reliable for long-running and automated tasks.
135
+
136
+
Note: The headless mode is an advanced feature aimed at improving the application's flexibility and deployment options. While it allows the application to run in more environments, the visualization and interactive features will not be available when operating in this mode.
137
+
95
138
### Running Face Recognition Functionality Standalone
96
139
97
140
If you do not have the USB micro T-Shirt launcher available or you want to test the facial recognition on a different machine, you can do so.
@@ -463,14 +506,22 @@ Following the [security hardening guidelines for self-hosted runners](https://do
463
506
464
507
#### 3. Repository Configuration
465
508
466
-
To further enhance security, we've configured the repository to restrict which actions can run on our self-hosted runners and who can approve these runs. As outlined in the [managing GitHub Actions settings for a repository](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests), we have:
509
+
To further enhance security, we've configured the repository to restrict which actions can run on our self-hosted runners
510
+
and who can approve these runs.
511
+
512
+
As outlined in the managing GitHub Actions settings for a repository
- **Limited Workflow Runs**: Configured the repository to prevent GitHub Actions from creating or approving pull requests unless they are from trusted users.
469
-
- **Scoped Permissions**: Ensured that the self-hosted runners are used only by this repository and will not run any workflow that is outside of this repo. See .
517
+
- **Scoped Permissions**: Ensured that the self-hosted runners are used only by this repository and will not run any workflow that is outside of this repository.
518
+
See .
470
519
471
520
#### 4. Monitoring and Auditing
472
521
473
-
Continuous monitoring and periodic auditing are vital to maintaining the security of our CI/CD pipeline. Our team regularly checks the logs and monitors the activity of our self-hosted runners to detect and respond to any unusual or unauthorized activity promptly.
522
+
Continuous monitoring and periodic auditing are vital to maintaining the security of our CI/CD pipeline.
523
+
I turn off the self-hosted runner most of the time and do checks the logs and monitors the activity of my
524
+
self-hosted runners to detect and respond to any unusual or unauthorized activity promptly.
0 commit comments