Skip to content

Commit 29f847c

Browse files
committed
✏️ Adjust the options setting of *docker run* command line to be more flexible in usage.
1 parent f7a1ce5 commit 29f847c

File tree

7 files changed

+77
-42
lines changed

7 files changed

+77
-42
lines changed

.github/tag_and_release/intent.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ docker:
4747
port: 8000 # Port for container health checks
4848
path: "/health" # Health check endpoint path
4949

50-
application:
51-
env_var_name: "API_TOKEN" # Environment variable name for application
52-
env_var_value: "test_token" # Environment variable value for testing
50+
# Flexible Docker run options - supports multiple env vars, volumes, networks, etc.
51+
run_options: "-e API_TOKEN=test_token -e DEBUG=true" # Custom Docker run options for testing
5352

5453
# === VALIDATION CONFIGURATION ===
5554
validation:
@@ -83,9 +82,13 @@ docs:
8382
# health_check:
8483
# port: 3000
8584
# path: "/api/health"
86-
# application:
87-
# env_var_name: "CUSTOM_TOKEN"
88-
# env_var_value: "custom_test_value"
85+
# # Flexible Docker run options - supports any Docker run parameters
86+
# run_options: "-e CUSTOM_TOKEN=custom_test_value -e NODE_ENV=production"
87+
#
88+
# 4. Advanced Docker configuration examples:
89+
# docker:
90+
# run_options: "-e API_KEY=test123 -e DB_HOST=localhost -v /tmp:/app/tmp --network mynet"
91+
# # Multiple environment variables, volume mounts, custom networks, etc.
8992
#
9093
# 4. Documentation versioning examples:
9194
# # Legacy format (backward compatible):

.github/workflows/release-staging.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ jobs:
113113
enable-signing: true
114114
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
115115
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
116-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
117-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
116+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
118117

119118
ghcr-rc:
120119
name: Staging Release to GHCR
@@ -129,8 +128,7 @@ jobs:
129128
enable-signing: true
130129
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
131130
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
132-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
133-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
131+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
134132

135133
docs-preview:
136134
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docs_operations.yaml@master

.github/workflows/release-validate.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ jobs:
7979
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
8080
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
8181
enable-signing: true
82-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
83-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
82+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
8483

8584
docker-build-ghcr:
8685
name: Validate GHCR Build
@@ -94,8 +93,7 @@ jobs:
9493
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
9594
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
9695
enable-signing: true
97-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
98-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
96+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
9997

10098
docs-build:
10199
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docs_operations.yaml@master
@@ -115,8 +113,7 @@ jobs:
115113
version: ${{ needs.config.outputs.validation_test_version }}
116114
enable-sbom: true
117115
enable-signing: true
118-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
119-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
116+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
120117

121118
validation-summary:
122119
name: Validation Summary

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ jobs:
378378
checkout-sha: ${{ needs.bump_version.outputs.new_sha }}
379379
enable-sbom: true
380380
enable-signing: true
381-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
382-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
381+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
383382

384383
release_docker_ghcr:
385384
name: Release to GHCR
@@ -393,8 +392,7 @@ jobs:
393392
checkout-sha: ${{ needs.bump_version.outputs.new_sha }}
394393
enable-sbom: true
395394
enable-signing: true
396-
app-env-var-name: ${{ needs.config.outputs.docker_app_env_var_name }}
397-
app-env-var-value: ${{ needs.config.outputs.docker_app_env_var_value }}
395+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
398396

399397
release_docs:
400398
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docs_operations.yaml@master

.github/workflows/rw_docker_operations.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,10 @@ on:
5858
required: false
5959
default: ''
6060
type: string
61-
app-env-var-name:
62-
description: 'Application environment variable name for testing'
61+
docker-run-options:
62+
description: 'Additional Docker run options (environment variables, volumes, networks, etc.)'
6363
required: false
64-
default: 'API_TOKEN'
65-
type: string
66-
app-env-var-value:
67-
description: 'Application environment variable value for testing'
68-
required: false
69-
default: 'test_token'
64+
default: '-e API_TOKEN=test_token'
7065
type: string
7166

7267
secrets:
@@ -187,7 +182,7 @@ jobs:
187182
# Start container in background
188183
docker run -d --name test-container \
189184
-p ${{ inputs.health-check-port }}:${{ inputs.health-check-port }} \
190-
-e ${{ inputs.app-env-var-name }}=${{ inputs.app-env-var-value }} \
185+
${{ inputs.docker-run-options }} \
191186
$IMAGE_TAG
192187
193188
# Wait for container to be ready and test health endpoint

.github/workflows/rw_parse_project_config.yaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ jobs:
124124
docker_registry_ghcr: ${{ steps.parse.outputs.docker_registry_ghcr }}
125125
docker_health_check_port: ${{ steps.parse.outputs.docker_health_check_port }}
126126
docker_health_check_path: ${{ steps.parse.outputs.docker_health_check_path }}
127-
docker_app_env_var_name: ${{ steps.parse.outputs.docker_app_env_var_name }}
128-
docker_app_env_var_value: ${{ steps.parse.outputs.docker_app_env_var_value }}
127+
docker_run_options: ${{ steps.parse.outputs.docker_run_options }}
129128

130129
# Validation Configuration
131130
validation_version: ${{ steps.parse.outputs.validation_version }}
@@ -204,8 +203,20 @@ jobs:
204203
docker_registry_ghcr=$(get_config ".docker.registries.ghcr" "ghcr.io")
205204
docker_health_check_port=$(get_config ".docker.health_check.port" "8000")
206205
docker_health_check_path=$(get_config ".docker.health_check.path" "/health")
207-
docker_app_env_var_name=$(get_config ".docker.application.env_var_name" "API_TOKEN")
208-
docker_app_env_var_value=$(get_config ".docker.application.env_var_value" "test_token")
206+
207+
# Parse flexible Docker run options
208+
docker_run_options=$(get_config ".docker.run_options" "-e API_TOKEN=test_token")
209+
210+
# Legacy support: If run_options is not set but old env var settings exist, build compatibility string
211+
if [[ "$docker_run_options" == "-e API_TOKEN=test_token" ]] && [[ "$use_defaults" == "false" ]]; then
212+
legacy_env_name=$(yq eval ".docker.application.env_var_name" "$config_file" 2>/dev/null || echo "null")
213+
legacy_env_value=$(yq eval ".docker.application.env_var_value" "$config_file" 2>/dev/null || echo "null")
214+
215+
if [[ "$legacy_env_name" != "null" && "$legacy_env_value" != "null" ]]; then
216+
docker_run_options="-e ${legacy_env_name}=${legacy_env_value}"
217+
echo "⚠️ Using legacy docker.application.env_var_* format. Consider migrating to docker.run_options."
218+
fi
219+
fi
209220
210221
# Parse Validation Configuration
211222
validation_version=$(get_config ".validation.version" "1.0.0-validation")
@@ -237,8 +248,7 @@ jobs:
237248
echo "docker_registry_ghcr=$docker_registry_ghcr" >> $GITHUB_OUTPUT
238249
echo "docker_health_check_port=$docker_health_check_port" >> $GITHUB_OUTPUT
239250
echo "docker_health_check_path=$docker_health_check_path" >> $GITHUB_OUTPUT
240-
echo "docker_app_env_var_name=$docker_app_env_var_name" >> $GITHUB_OUTPUT
241-
echo "docker_app_env_var_value=$docker_app_env_var_value" >> $GITHUB_OUTPUT
251+
echo "docker_run_options=$docker_run_options" >> $GITHUB_OUTPUT
242252
243253
echo "validation_version=$validation_version" >> $GITHUB_OUTPUT
244254
echo "validation_test_version=$validation_test_version" >> $GITHUB_OUTPUT

docs_with_docusarus/contents/development/ci-cd/release-system.mdx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -960,18 +960,34 @@ docker:
960960
health_check:
961961
path: "/health" # string - Health check endpoint
962962
port: 8000 # number - Health check port
963-
application:
964-
env_var_name: "API_TOKEN" # string - Application environment variable name
965-
env_var_value: "test_token" # string - Application environment variable value
963+
run_options: "-e API_TOKEN=test_token -e DEBUG=true -v /host/data:/app/data --network mynetwork"
966964
```
967965

968966
**Configuration Options:**
969967
- **`registries.dockerhub`**: Docker Hub registry URL for dual publishing
970968
- **`registries.ghcr`**: GitHub Container Registry URL for dual publishing
971969
- **`health_check.path`**: HTTP health check endpoint path
972970
- **`health_check.port`**: Port for health check operations
973-
- **`application.env_var_name`**: Environment variable name for application testing
974-
- **`application.env_var_value`**: Environment variable value for application testing
971+
- **`run_options`**: Flexible string for Docker run options (environment variables, volumes, networks, etc.)
972+
973+
**Advanced Docker Run Options Examples:**
974+
```yaml
975+
# Basic environment variables
976+
docker:
977+
run_options: "-e API_TOKEN=test_token -e DEBUG=true"
978+
979+
# Multiple environment variables with volumes
980+
docker:
981+
run_options: "-e API_TOKEN=test_token -e DB_URL=postgresql://localhost:5432/app -v /host/data:/app/data -v /host/logs:/app/logs"
982+
983+
# Complex configuration with network and resource limits
984+
docker:
985+
run_options: "-e API_TOKEN=test_token -e REDIS_URL=redis://localhost:6379 --network mynetwork --memory=512m --cpus=0.5 -v /host/config:/app/config:ro"
986+
987+
# Production-ready configuration
988+
docker:
989+
run_options: "-e NODE_ENV=production -e API_TOKEN=prod_token -e DB_URL=postgresql://prod-db:5432/app -e REDIS_URL=redis://prod-redis:6379 --network prod-network --restart unless-stopped -v /data/app:/app/data -v /logs/app:/app/logs"
990+
```
975991

976992
**Usage in Workflows:**
977993
```yaml
@@ -980,15 +996,33 @@ DOCKERHUB_REGISTRY: ${{ needs.config.outputs.docker_registry_dockerhub }}
980996
GHCR_REGISTRY: ${{ needs.config.outputs.docker_registry_ghcr }}
981997
HEALTH_CHECK_PATH: ${{ needs.config.outputs.docker_health_check_path }}
982998
HEALTH_CHECK_PORT: ${{ needs.config.outputs.docker_health_check_port }}
983-
APP_ENV_NAME: ${{ needs.config.outputs.docker_app_env_name }}
984-
APP_ENV_VALUE: ${{ needs.config.outputs.docker_app_env_value }}
999+
DOCKER_RUN_OPTIONS: ${{ needs.config.outputs.docker_run_options }}
1000+
1001+
# Example: Using the flexible Docker run options in workflows
1002+
jobs:
1003+
docker-operations:
1004+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docker_operations.yaml@master
1005+
needs: config
1006+
with:
1007+
operation: 'push'
1008+
registry: ${{ needs.config.outputs.docker_registry_dockerhub }}
1009+
version: '1.0.0'
1010+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
9851011
9861012
# Example: Health check validation
9871013
- name: Test Health Check
9881014
run: |
9891015
curl -f "http://localhost:${{ needs.config.outputs.docker_health_check_port }}${{ needs.config.outputs.docker_health_check_path }}"
9901016
```
9911017

1018+
**Benefits of Flexible Docker Run Options:**
1019+
- **Multiple Environment Variables**: Pass any number of environment variables in a single string
1020+
- **Volume Mounts**: Configure data persistence and file sharing between host and container
1021+
- **Network Configuration**: Specify custom Docker networks for container connectivity
1022+
- **Resource Limits**: Set memory and CPU constraints for container resource management
1023+
- **Runtime Options**: Configure restart policies, security contexts, and other Docker runtime settings
1024+
- **Child Project Flexibility**: Each project using the template can customize Docker behavior without modifying workflows
1025+
9921026
##### 9. Validation Configuration
9931027

9941028
**`validation`** (object)

0 commit comments

Comments
 (0)