Skip to content

Commit 751f716

Browse files
authored
Minor Fixes and Improvements (#27)
1 parent c91ee94 commit 751f716

File tree

4 files changed

+66
-49
lines changed

4 files changed

+66
-49
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
uses: cssnr/update-version-tags-action@v1
1919

2020
- name: "Debug Tags"
21+
continue-on-error: true
2122
run: |
2223
echo "github.ref_name: ${{ github.ref_name }}"
2324
echo "steps.tags.outputs.tags: ${{ steps.tags.outputs.tags }}"

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> [!WARNING]
44
> This guide is a work in progress and may not be complete.
55
6-
Note: This guide is not updated for Compose but those tests work the same way.
6+
Note: This guide is not updated for Compose but those tests work similar.
77

88
## Workflow
99

@@ -52,7 +52,7 @@ act -j test -e event.json
5252

5353
The flag `-e event.json` disabled test #2 which tests SSH auth and registry auth.
5454

55-
To test both SSH and authb and registry auth (run test #2) do the following.
55+
To test both SSH and registry auth (run test #2) do the following.
5656

5757
1. Create a `.vars` file and add the vars and secrets from test #2 under [GitHub](#GitHub).
5858

README.md

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
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/graphs/commit-activity)
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 Top Language](https://img.shields.io/github/languages/top/cssnr/stack-deploy-action?logo=htmx)](https://github.com/cssnr/stack-deploy-action)
9+
[![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)
10+
[![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)
1011
[![GitHub Discussions](https://img.shields.io/github/discussions/cssnr/stack-deploy-action)](https://github.com/cssnr/stack-deploy-action/discussions)
1112
[![GitHub Forks](https://img.shields.io/github/forks/cssnr/stack-deploy-action?style=flat&logo=github)](https://github.com/cssnr/stack-deploy-action/forks)
1213
[![GitHub Repo Stars](https://img.shields.io/github/stars/cssnr/stack-deploy-action?style=flat&logo=github)](https://github.com/cssnr/stack-deploy-action/stargazers)
@@ -23,8 +24,8 @@
2324
- [Contributing](#Contributing)
2425

2526
> [!TIP]
26-
> 💡 Now works with vanilla Docker hosts using **Compose. No Swarm Required!**
27-
> Just set `mode: compose`. See the [Inputs](#Inputs) for more details...
27+
> Now works with Docker **Compose. No Swarm Required!**
28+
> ▶️ Set `mode: compose`. See [Inputs](#Inputs) for more details...
2829
2930
This action deploys a docker stack from a compose file to a remote docker host using SSH Password or Key File Authentication.
3031
You can also optionally authenticate against a private registry using a username and password.
@@ -41,30 +42,30 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh).
4142

4243
## Inputs
4344

44-
| Input | Required | Default | Description |
45-
| :------------------- | :----------: | :---------------------------------- | :---------------------------------------- |
46-
| `name` | **Yes** | - | Docker Stack/Project Name \* |
47-
| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File |
48-
| `mode`**¹** | - | `swarm` | Deploy Mode: [`swarm`, `compose`] \* |
49-
| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional Arguments for **Compose** \* |
50-
| `host` | **Yes** | - | Remote Docker Hostname or IP \* |
51-
| `port` | - | `22` | Remote Docker Port |
52-
| `user` | **Yes** | - | Remote Docker Username |
53-
| `pass` | or `ssh_key` | - | Remote Docker Password \* |
54-
| `ssh_key` | or `pass` | - | Remote SSH Key File \* |
55-
| `env_file` | - | - | Docker Environment File \* |
56-
| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* |
57-
| `prune`**²** | - | `false` | Prune Flag, `true`, to enable |
58-
| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* |
59-
| `registry_auth`**²** | - | - | Enable Registry Authentication \* |
60-
| `registry_host` | - | - | Registry Authentication Host \* |
61-
| `registry_user` | - | - | Registry Authentication Username \* |
62-
| `registry_pass` | - | - | Registry Authentication Password \* |
63-
| `summary` | - | `true` | Add Job Summary \* |
64-
65-
> **¹** Compose Only. View the [Docs](https://docs.docker.com/reference/cli/docker/compose/up/).
66-
> **²** Swarm Only. View the [Docs](https://docs.docker.com/reference/cli/docker/stack/deploy/).
67-
> \* See Below for more details...
45+
| Input Name | Is Required | Default Value | Input Description |
46+
| :------------------- | :--------------: | :---------------------------------- | :---------------------------------------- |
47+
| `name` | **Yes** | - | Docker Stack/Project Name \* |
48+
| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File |
49+
| `mode`**¹** | - | `swarm` | Deploy Mode: [`swarm`, `compose`] \* |
50+
| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional Arguments for **Compose** \* |
51+
| `host` | **Yes** | - | Remote Docker Hostname or IP \* |
52+
| `port` | - | `22` | Remote Docker Port |
53+
| `user` | **Yes** | - | Remote Docker Username |
54+
| `pass` | or `ssh_key` | - | Remote Docker Password \* |
55+
| `ssh_key` | or `pass` | - | Remote SSH Key File \* |
56+
| `env_file` | - | - | Docker Environment File \* |
57+
| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* |
58+
| `prune`**²** | - | `false` | Prune Flag, `true`, to enable |
59+
| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* |
60+
| `registry_auth`**²** | - | - | Enable Registry Authentication \* |
61+
| `registry_host` | - | - | Registry Authentication Host \* |
62+
| `registry_user` | - | - | Registry Authentication Username \* |
63+
| `registry_pass` | - | - | Registry Authentication Password \* |
64+
| `summary` | - | `true` | Add Job Summary \* |
65+
66+
> **¹** Compose Only, view the [Docs](https://docs.docker.com/reference/cli/docker/compose/up/).
67+
> **²** Swarm Only, view the [Docs](https://docs.docker.com/reference/cli/docker/stack/deploy/).
68+
> \* More details below...
6869
6970
<details><summary>📟 Click Here to see how the deployment command is generated</summary>
7071

@@ -92,7 +93,7 @@ Use an empty string to override. For more details, see the compose
9293
**host:** The hostname or IP address of the remote docker server to deploy too.
9394
If your hostname is behind a proxy like Cloudflare you will need to use the IP address.
9495

95-
**pass/ssh_key:** You must provide either a `pass` or `ssh_key`, but not both.
96+
**pass/ssh_key:** You must provide either a `pass` or `ssh_key`, not both.
9697

9798
**env_file:** Variables in this file are exported before running stack deploy.
9899
To use a docker `env_file` specify it in your compose file and make it available in a previous step.
@@ -122,7 +123,7 @@ To view a workflow run, click on a recent [Test](https://github.com/cssnr/stack-
122123
🚀 Swarm Stack `test_stack-deploy` Successfully Deployed.
123124

124125
```text
125-
docker stack deploy --detach=false --resolve-image=changed -c docker-compose.yaml test_stack-deploy
126+
docker stack deploy -c docker-compose.yaml --detach=false --resolve-image=changed test_stack-deploy
126127
```
127128

128129
<details><summary>Results</summary>
@@ -461,14 +462,17 @@ https://github.com/cssnr/stack-deploy-action/network/dependents
461462

462463
The following rolling [tags](https://github.com/cssnr/stack-deploy-action/tags) are maintained.
463464

464-
| Version&nbsp;Tag | Rolling | Bugs | Feat. | Target | Example |
465-
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :--: | :---: | :------- | :------- |
466-
| [![GitHub Tag Major](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*&style=for-the-badge&label=%20&color=44cc10)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ✅ | `vN.x.x` | `vN` |
467-
| [![GitHub Tag Minor](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*.*&style=for-the-badge&label=%20&color=blue)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ❌ | `vN.N.x` | `vN.N` |
468-
| [![GitHub Release](https://img.shields.io/github/v/release/cssnr/stack-deploy-action?style=for-the-badge&label=%20&color=red)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ❌ | ❌ | ❌ | `vN.N.N` | `vN.N.N` |
465+
| Version&nbsp;Tag | Rolling | Bugs | Feat. | Name | Target | Example |
466+
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :--: | :---: | :-------: | :------: | :------- |
467+
| [![GitHub Tag Major](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*&style=for-the-badge&label=%20&color=44cc10)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ✅ | **Major** | `vN.x.x` | `vN` |
468+
| [![GitHub Tag Minor](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*.*&style=for-the-badge&label=%20&color=blue)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ❌ | **Minor** | `vN.N.x` | `vN.N` |
469+
| [![GitHub Release](https://img.shields.io/github/v/release/cssnr/stack-deploy-action?style=for-the-badge&label=%20&color=red)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ❌ | ❌ | ❌ | **Micro** | `vN.N.N` | `vN.N.N` |
469470

470471
You can view the release notes for each version on the [releases](https://github.com/cssnr/stack-deploy-action/releases) page.
471472

473+
The **Major** tag is recommended. It is the most up-to-date and always backwards compatible.
474+
Breaking changes would result in a **Major** version bump. At a minimum you should use a **Minor** tag.
475+
472476
## Features
473477

474478
- Deploy to a remote host using SSH or Password authentication.

src/main.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ function cleanup_trap() {
2222

2323
## Check Variables
2424

25+
INPUT_MODE=$(echo "${INPUT_MODE}" | xargs | tr '[:upper:]' '[:lower:]')
26+
echo "::debug::INPUT_MODE: ${INPUT_MODE}"
27+
2528
if [[ "${INPUT_MODE}" == "swarm" ]];then
2629
if [[ "${INPUT_ARGS}" != "--remove-orphans --force-recreate" ]];then
2730
echo "::warning::You set compose args but mode is swarm!"
2831
fi
29-
else
30-
#elif [[ "${INPUT_MODE}" == "compose" ]];then
32+
elif [[ "${INPUT_MODE}" == "compose" ]];then
3133
if [[ "${INPUT_DETACH}" != "true" ]];then
3234
echo "::warning::You set detach but mode is compose!"
3335
fi
@@ -37,9 +39,10 @@ else
3739
if [[ "${INPUT_RESOLVE_IMAGE}" != "always" ]];then
3840
echo "::warning::You set resolve_image but mode is compose!"
3941
fi
40-
#else
41-
# echo "::error::Input mode must be set to swarm or compose!"
42-
# exit 1
42+
else
43+
echo "::error::Input mode must be set to swarm or compose!"
44+
echo "⛔ Input Parsing Failed. The mode must be set to swarm or compose."
45+
exit 1
4346
fi
4447

4548
## Setup Script
@@ -52,6 +55,7 @@ echo "Script: ${0}"
5255
echo "Current Directory: $(pwd)"
5356
echo "Home Directory: ${HOME}"
5457
echo "SSH Directory: ${SSH_DIR}"
58+
echo "Deploy Mode: ${INPUT_MODE}"
5559

5660
mkdir -p "${SSH_DIR}" ~/.ssh
5761
chmod 0700 "${SSH_DIR}" ~/.ssh
@@ -93,13 +97,18 @@ echo "::endgroup::"
9397

9498
## Export Environment File
9599

96-
if [[ -f "${INPUT_ENV_FILE}" ]];then
97-
echo -e "::group::Sourcing Environment File: \u001b[36;1m${INPUT_ENV_FILE}"
98-
stat "${INPUT_ENV_FILE}"
99-
set -a
100-
# shellcheck disable=SC1090
101-
source "${INPUT_ENV_FILE}"
102-
echo "::endgroup::"
100+
if [[ -n "${INPUT_ENV_FILE}" ]];then
101+
if [[ -f "${INPUT_ENV_FILE}" ]];then
102+
echo -e "::group::Sourcing Environment File: \u001b[36;1m${INPUT_ENV_FILE}"
103+
set -a
104+
# shellcheck disable=SC1090
105+
source "${INPUT_ENV_FILE}"
106+
echo "::endgroup::"
107+
else
108+
echo "::error::Environment File Not Found: ${INPUT_ENV_FILE}"
109+
fi
110+
else
111+
echo "::debug::No environment file specified, skipping export file..."
103112
fi
104113

105114
## Docker Login
@@ -110,6 +119,8 @@ if [[ -n "${INPUT_REGISTRY_USER}" && -n "${INPUT_REGISTRY_PASS}" ]];then
110119
docker login --username "${INPUT_REGISTRY_USER}" --password-stdin "${INPUT_REGISTRY_HOST}"
111120
INPUT_REGISTRY_AUTH="true"
112121
echo "::endgroup::"
122+
else
123+
echo "::debug::No registry user or password, skipping docker login..."
113124
fi
114125

115126
## Collect Arguments
@@ -143,6 +154,7 @@ else
143154
read -r -a args <<< "${INPUT_ARGS}"
144155
EXTRA_ARGS+=("${args[@]}")
145156
fi
157+
echo "::debug::EXTRA_ARGS: ${EXTRA_ARGS[*]}"
146158

147159
## Deploy Stack
148160

@@ -169,7 +181,7 @@ echo "::endgroup::"
169181
if [[ "${INPUT_SUMMARY}" == "true" ]];then
170182
echo "📝 Writing Job Summary"
171183
# shellcheck source=/src/summary.sh
172-
source /src/summary.sh >> "${GITHUB_STEP_SUMMARY}" ||\
184+
source /src/summary.sh >> "${GITHUB_STEP_SUMMARY}" ||
173185
echo "::error::Failed to Write Job Summary!"
174186
fi
175187

0 commit comments

Comments
 (0)