update readme and allow to copy .env file when needed

This commit is contained in:
Radosław Kukuczka
2025-05-20 00:27:37 +02:00
parent 6174611933
commit 90f83b775e
2 changed files with 49 additions and 13 deletions

View File

@@ -11,20 +11,26 @@ Robustly deploy your Docker Compose files to Docker Swarm or regular Docker Comp
- 🔍 **Remote validation of Docker Compose files** - 🔍 **Remote validation of Docker Compose files**
- 🧹 **Automatic cleanup of temporary files** - 🧹 **Automatic cleanup of temporary files**
- 📋 **Detailed debug logs for easy troubleshooting** - 📋 **Detailed debug logs for easy troubleshooting**
- 📂 **Optional copying of Docker build context**
- 📄 **Optional copying of `.env` files**
--- ---
## 📥 Inputs ## 📥 Inputs
| Input | Description | Required | Default | | Input | Description | Required | Default |
|--------------------|--------------------------------------------------|----------|---------| |-----------------------|----------------------------------------------------------------|----------|------------------|
| `stack_name` | Docker stack or compose project name | ✅ Yes | - | | `stack_name` | Docker stack or compose project name | ✅ Yes | - |
| `ssh_host` | SSH host | ✅ Yes | - | | `ssh_host` | SSH host | ✅ Yes | - |
| `ssh_user` | SSH username | ✅ Yes | - | | `ssh_user` | SSH username | ✅ Yes | - |
| `ssh_key` | SSH private key | ✅ Yes | - | | `ssh_key` | SSH private key | ✅ Yes | - |
| `deploy_file` | Path to the processed deployment file | ✅ Yes | - | | `deploy_file` | Path to the processed deployment file | ✅ Yes | - |
| `deploy_mode` | Deployment mode: `swarm` or `compose` | ❌ No | `swarm` | | `deploy_mode` | Deployment mode: `swarm` or `compose` | ❌ No | `swarm` |
| `remote_temp_dir` | Remote temporary directory for deployment files | ❌ No | `/tmp` | | `remote_temp_dir` | Remote temporary directory for deployment files | ❌ No | `/tmp` |
| `copy_build_context` | Whether to copy Docker build context to remote host | ❌ No | `false` |
| `build_context_path` | Local path to Docker build context | ❌ No | `build-context` |
| `copy_env_file` | Whether to copy `.env` file to remote host | ❌ No | `false` |
| `env_file_path` | Local path to `.env` file | ❌ No | `.env` |
--- ---
@@ -56,7 +62,7 @@ This action supports two deployment modes:
deploy_mode: swarm deploy_mode: swarm
``` ```
### Deploying with Docker Compose 🐳 ### Deploying with Docker Compose 🐳 (including build context and `.env` file)
```yaml ```yaml
- name: Deploy using Docker Compose 🐳 - name: Deploy using Docker Compose 🐳
@@ -68,6 +74,10 @@ This action supports two deployment modes:
ssh_key: ${{ secrets.SSH_KEY }} ssh_key: ${{ secrets.SSH_KEY }}
deploy_file: docker-compose.processed.yml deploy_file: docker-compose.processed.yml
deploy_mode: compose deploy_mode: compose
copy_build_context: true
build_context_path: ./docker-context
copy_env_file: true
env_file_path: ./production.env
``` ```
--- ---
@@ -79,9 +89,11 @@ This action performs the following steps:
1. 🔑 **Securely creates a temporary SSH key file** for authentication. 1. 🔑 **Securely creates a temporary SSH key file** for authentication.
2. 📁 **Creates a secure temporary directory** on the remote host. 2. 📁 **Creates a secure temporary directory** on the remote host.
3. 📤 **Copies your processed Docker Compose file** to the remote host. 3. 📤 **Copies your processed Docker Compose file** to the remote host.
4. 🔍 **Validates the Docker Compose file remotely** to ensure correctness. 4. 📂 **Optionally copies Docker build context** to the remote host.
5. 🚢🐳 **Deploys your stack/project** based on the selected deployment mode. 5. 📄 **Optionally copies `.env` file** to the remote host.
6. 🧹 **Cleans up temporary files** both locally and remotely. 6. 🔍 **Validates the Docker Compose file remotely** to ensure correctness.
7. 🚢🐳 **Deploys your stack/project** based on the selected deployment mode.
8. 🧹 **Cleans up temporary files** both locally and remotely.
--- ---

View File

@@ -35,6 +35,15 @@ inputs:
description: 'Local path to Docker build context (directory containing Dockerfile). Defaults to ./build-context' description: 'Local path to Docker build context (directory containing Dockerfile). Defaults to ./build-context'
required: false required: false
default: 'build-context' default: 'build-context'
copy_env_file:
description: 'Whether to copy .env file to remote host'
required: false
default: 'false'
env_file_path:
description: 'Local path to .env file'
required: false
default: '.env'
runs: runs:
using: 'composite' using: 'composite'
@@ -97,6 +106,21 @@ runs:
"ls -lha '$REMOTE_TEMP_DIR'" "ls -lha '$REMOTE_TEMP_DIR'"
fi fi
# Optionally copy env file
COPY_ENV_FILE="${{ inputs.copy_env_file }}"
ENV_FILE_PATH="${{ inputs.env_file_path }}"
if [ "$COPY_ENV_FILE" == "true" ]; then
if [ ! -f "$ENV_FILE_PATH" ]; then
echo "❌ ERROR: .env file '$ENV_FILE_PATH' does not exist."
exit 1
fi
echo "📄 DEBUG: Copying .env file from '$ENV_FILE_PATH' to remote host"
scp -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \
"$ENV_FILE_PATH" \
"$SSH_USER@$SSH_HOST:$REMOTE_TEMP_DIR/.env"
fi
# Validate docker-compose file remotely before deploying # Validate docker-compose file remotely before deploying
echo "🔍 DEBUG: Validating Docker Compose file remotely" echo "🔍 DEBUG: Validating Docker Compose file remotely"
ssh -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \ ssh -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \