Skip to content

Commit d58b92b

Browse files
authored
Support Multiple Compose Files (#37)
1 parent 3ed3472 commit d58b92b

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Workflow Lint](https://img.shields.io/github/actions/workflow/status/cssnr/stack-deploy-action/lint.yaml?logo=github&label=lint)](https://github.com/cssnr/stack-deploy-action/actions/workflows/lint.yaml)
77
[![GitHub Last Commit](https://img.shields.io/github/last-commit/cssnr/stack-deploy-action?logo=github&label=updated)](https://github.com/cssnr/stack-deploy-action/pulse)
88
[![Codeberg Last Commit](https://img.shields.io/gitea/last-commit/cssnr/stack-deploy-action/master?gitea_url=https%3A%2F%2Fcodeberg.org%2F&logo=codeberg&logoColor=white&label=updated)](https://codeberg.org/cssnr/stack-deploy-action)
9-
[![GitHub Contributors](https://img.shields.io/github/contributors/cssnr/stack-deploy-action)](https://github.com/cssnr/stack-deploy-action/graphs/contributors)
9+
[![GitHub Contributors](https://img.shields.io/github/contributors/cssnr/stack-deploy-action?logo=github)](https://github.com/cssnr/stack-deploy-action/graphs/contributors)
1010
[![GitHub Repo Size](https://img.shields.io/github/repo-size/cssnr/stack-deploy-action?logo=bookstack&logoColor=white&label=size)](https://github.com/cssnr/stack-deploy-action)
1111
[![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/stack-deploy-action?logo=sharp&logoColor=white)](https://github.com/cssnr/stack-deploy-action)
1212
[![GitHub Discussions](https://img.shields.io/github/discussions/cssnr/stack-deploy-action?logo=github)](https://github.com/cssnr/stack-deploy-action/discussions)
@@ -44,27 +44,27 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh).
4444

4545
## Inputs
4646

47-
| Input Name | Is Required | Default Value | Input Description |
48-
| :------------------- | :--------------: | :---------------------------------- | :---------------------------------------- |
49-
| `name` | **Yes** | - | Docker Stack/Project Name \* |
50-
| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File |
51-
| `mode`**¹** | - | `swarm` | Deploy Mode: [`swarm`, `compose`] \* |
52-
| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional Arguments for **Compose** \* |
53-
| `host` | **Yes** | - | Remote Docker Hostname or IP \* |
54-
| `port` | - | `22` | Remote Docker Port |
55-
| `user` | **Yes** | - | Remote Docker Username |
56-
| `pass` | or `ssh_key` | - | Remote Docker Password \* |
57-
| `ssh_key` | or `pass` | - | Remote SSH Key File \* |
58-
| `disable_keyscan` | - | `false` | Disable SSH Key Scan: `ssh-keyscan` \* |
59-
| `env_file` | - | - | Docker Environment File \* |
60-
| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* |
61-
| `prune`**²** | - | `false` | Prune Flag, `true`, to enable |
62-
| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* |
63-
| `registry_auth`**²** | - | - | Enable Registry Authentication \* |
64-
| `registry_host` | - | - | Registry Authentication Host \* |
65-
| `registry_user` | - | - | Registry Authentication Username \* |
66-
| `registry_pass` | - | - | Registry Authentication Password \* |
67-
| `summary` | - | `true` | Add Job Summary \* |
47+
| Input Name | Required | Default Value | Short Description of Input |
48+
| :------------------- | :----------: | :---------------------------------- | :---------------------------------------- |
49+
| `name` | **Yes** | - | Docker Stack/Project Name \* |
50+
| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File(s) \* |
51+
| `mode`**¹** | - | `swarm` | Deploy Mode [`swarm`, `compose`] \* |
52+
| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional **Compose** Arguments \* |
53+
| `host` | **Yes** | - | Remote Docker Hostname or IP \* |
54+
| `port` | - | `22` | Remote Docker Port |
55+
| `user` | **Yes** | - | Remote Docker Username |
56+
| `pass` | or `ssh_key` | - | Remote Docker Password \* |
57+
| `ssh_key` | or `pass` | - | Remote SSH Key File \* |
58+
| `disable_keyscan` | - | `false` | Disable SSH Keyscan `ssh-keyscan` \* |
59+
| `env_file` | - | - | Docker Environment File \* |
60+
| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* |
61+
| `prune`**²** | - | `false` | Prune Flag, `true`, to enable |
62+
| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* |
63+
| `registry_auth`**²** | - | - | Enable Registry Authentication \* |
64+
| `registry_host` | - | - | Registry Authentication Host \* |
65+
| `registry_user` | - | - | Registry Authentication Username \* |
66+
| `registry_pass` | - | - | Registry Authentication Password \* |
67+
| `summary` | - | `true` | Add Job Summary \* |
6868

6969
> **¹** Compose Only, view the [Docs](https://docs.docker.com/reference/cli/docker/compose/up/).
7070
> **²** Swarm Only, view the [Docs](https://docs.docker.com/reference/cli/docker/stack/deploy/).
@@ -78,14 +78,19 @@ if [[ "${INPUT_MODE}" == "swarm" ]];then
7878
COMMAND=("docker" "stack" "deploy" "-c" "${INPUT_FILE}" "${EXTRA_ARGS[@]}" "${INPUT_NAME}")
7979
else
8080
DEPLOY_TYPE="Compose"
81-
COMMAND=("docker" "compose" "-f" "${INPUT_FILE}" "-p" "${INPUT_NAME}" "up" "-d" "-y" "${EXTRA_ARGS[@]}")
81+
COMMAND=("docker" "compose" "${STACK_FILES[@]}" "-p" "${INPUT_NAME}" "up" "-d" "-y" "${EXTRA_ARGS[@]}")
8282
fi
8383
```
8484

85+
Compose Note: `"${STACK_FILES[@]}"` is an array of `-f docker-compose.yaml` for every `file` in the argument.
86+
8587
</details>
8688

8789
**name:** Stack name for Swarm and project name for Compose.
8890

91+
**file:** Stack file or Compose file(s). Multiple files can be provided, space seperated, and a `-f` will be prepended to each.
92+
Example: `web.yaml db.yaml`.
93+
8994
**mode:** _Compose only._ Set this to `compose` to use `compose up` instead of `stack deploy` for non-swarm hosts.
9095

9196
**args:** _Compose only._ Compose arguments to pass to the `compose up` command. Only used for `mode: compose` deployments.

src/main.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function cleanup_trap() {
1111
ssh -o BatchMode=yes -o ConnectTimeout=30 -p "${INPUT_PORT}" "${INPUT_USER}@${INPUT_HOST}" \
1212
"sed -i '/docker-stack-deploy-action/d' ~/.ssh/authorized_keys"
1313
fi
14-
if [[ "${_ST}" != "0" ]]; then
14+
if [[ "${_ST}" != "0" ]];then
1515
echo -e "⛔ \u001b[31;1mFailed to deploy stack ${INPUT_NAME}"
1616
echo "::error::Failed to deploy stack ${INPUT_NAME}. See logs for details..."
1717
else
@@ -163,14 +163,25 @@ else
163163
fi
164164
echo "::debug::EXTRA_ARGS: ${EXTRA_ARGS[*]}"
165165

166+
## Collect Stack Files
167+
168+
if [[ "${INPUT_MODE}" == "compose" ]];then
169+
STACK_FILES=()
170+
read -r -a files <<< "${INPUT_FILE}"
171+
for file in "${files[@]}";do
172+
STACK_FILES+=("-f" "$file")
173+
done
174+
echo "::debug::STACK_FILES: ${STACK_FILES[*]}"
175+
fi
176+
166177
## Deploy Stack
167178

168179
if [[ "${INPUT_MODE}" == "swarm" ]];then
169180
DEPLOY_TYPE="Swarm"
170181
COMMAND=("docker" "stack" "deploy" "-c" "${INPUT_FILE}" "${EXTRA_ARGS[@]}" "${INPUT_NAME}")
171182
else
172183
DEPLOY_TYPE="Compose"
173-
COMMAND=("docker" "compose" "-f" "${INPUT_FILE}" "-p" "${INPUT_NAME}" "up" "-d" "-y" "${EXTRA_ARGS[@]}")
184+
COMMAND=("docker" "compose" "${STACK_FILES[@]}" "-p" "${INPUT_NAME}" "up" "-d" "-y" "${EXTRA_ARGS[@]}")
174185
fi
175186

176187
echo -e "::group::Deploying Docker ${DEPLOY_TYPE} Stack: \u001b[36;1m${INPUT_NAME}"

0 commit comments

Comments
 (0)