Add Windows support, but it could be unstable ⚠️

"tr -d '\r'" is used to avoid Windows errors, reference:
https://github.com/stedolan/jq/issues/92
This commit is contained in:
Tortue Torche 2021-09-23 17:22:15 +02:00
parent 8261c27949
commit 34d1d9bfec
4 changed files with 63 additions and 22 deletions

View File

@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- macOS support
- [macOS](https://apple.com/macos) support
- [Windows](https://microsoft.com/windows) support, but it could be unstable ⚠️
### Changed
- Remove parallel requests improvement, because it's buggy in some situations...

View File

@ -30,7 +30,9 @@ _Based on previous work by [@vladbabii](https://github.com/vladbabii) on [docker
### Standalone
Just clone the repo and use the script:
> **Note**: The easiest way to install `psu` is to use [Docker method](#docker-image-and-variants), instead of this one
Check the [Requirements](#requirements) section then [git] clone the repo and use the [bash] script below:
```bash
git clone https://gitlab.com/psuapp/psu.git
@ -50,17 +52,37 @@ For detailed instructions, see [How to use](#how-to-use) section.
You will need these dependencies installed:
- [bash](https://www.gnu.org/software/bash/)<sup title="required">*</sup> <small>(>= 5.0.3)</small>
- [curl](https://curl.se/)<sup title="required">*</sup> <small>(>= 7.64.0, but >= 7.76.0 is recommended)</small>
- [jq](https://stedolan.github.io/jq/)<sup title="required">*</sup> <small>(>= 1.5.1)</small>
- [timeout](https://man7.org/linux/man-pages/man1/timeout.1.html)<sup title="required">*</sup> <small>For macOS run: `brew install coreutils`</small>
- [uuidgen](https://man7.org/linux/man-pages/man1/uuidgen.1.html) only for some <abbr title="Operating System">OS</abbr> <small>(Debian and Alpine work fine without it)</small>
- greadlink <small>Only for macOS run: `brew install coreutils`</small>
##### For [Linux] based systems <small>([Alpine], [Debian], [Ubuntu]...)</small>
- [bash]<sup title="required">\*</sup> <small>(>= 4.4.23)</small>
- [curl]<sup title="required">\*</sup> <small>(>= 7.64.0, but >= 7.76.0 is recommended)</small>
- [jq]<sup title="required">\*</sup> <small>(>= 1.5.1)</small>
- [uuidgen] recommended only for some <abbr title="Operating System">OS</abbr> <small>(Alpine and Debian work fine without it)</small>
For [Debian] and similar apt-powered [Linux] systems, run: `apt install bash curl jq`
##### For [macOS]
- [bash]<sup title="required">\*</sup> <small>(>= 4.4.23)</small>
- [curl]<sup title="required">\*</sup> <small>(>= 7.64.0, but >= 7.76.0 is recommended)</small>
- [jq]<sup title="required">\*</sup> <small>(>= 1.5.1)</small>
- [timeout]<sup title="required">\*</sup> <small>(included in the [coreutils] package)</small>
- greadlink <small>(included in the [coreutils] package)</small>
You should install [Homebrew], then run: `brew install bash coreutils jq`
##### For [Windows]
- [bash]<sup title="required">\*</sup> <small>(>= 4.4.23)</small>
- [curl]<sup title="required">\*</sup> <small>(>= 7.64.0, but >= 7.76.0 is recommended)</small>
- [jq]<sup title="required">\*</sup> <small>(>= 1.5.1)</small>
> **Note**: `psu`should work with [Windows], but it could be unstable ⚠️
You should download and install [Git](https://git-scm.com/download/win) and [jq](https://stedolan.github.io/jq/download) for [Windows]
##### For all systems
- [docker-compose] is recommended but not required <small>(useful for linting docker compose/stack files)</small>
<sup>\*</sup> = required
For Debian and similar apt-powered systems: `apt install bash curl jq`
### Docker image and variants
If you don't want or can't install `psu` and its dependencies, you can run it with the default [published Docker image](https://hub.docker.com/r/psuapp/psu), like this:
@ -246,3 +268,19 @@ For detailed instructions, see the [CLI Commands](docs/README.md) documentation.
Source code contained by this project is licensed under the [GNU General Public License version 3](https://www.gnu.org/licenses/gpl-3.0.en.html).
See [LICENSE](LICENSE) file for reference.
[Linux]: https://kernel.org
[Alpine]: https://alpinelinux.org
[Debian]: https://debian.org
[Ubuntu]: https://ubuntu.com/
[macOS]: https://apple.com/macos
[Homebrew]: https://brew.sh
[coreutils]: https://formulae.brew.sh/formula/coreutils
[Windows]: https://microsoft.com/windows
[bash]: https://www.gnu.org/software/bash
[curl]: https://curl.se
[jq]: https://stedolan.github.io/jq
[timeout]: https://man7.org/linux/man-pages/man1/timeout.1.html
[uuidgen]: https://man7.org/linux/man-pages/man1/uuidgen.1.html
[docker-compose]: https://docs.docker.com/compose/install
[git]: https://git-scm.com/

18
psu
View File

@ -170,7 +170,7 @@ main() {
echo "$services"
else
# Only display service(s) name in quiet mode
echo "$services" | jq -r '.[] | [.Spec.Name] | add'
echo "$services" | jq -r '.[] | [.Spec.Name] | add' | tr -d '\r'
fi
exit 0
fi
@ -229,7 +229,7 @@ main() {
echo "$tasks"
else
# Only display task(s) id in quiet mode
echo "$tasks" | jq -r '.[] | [.ID] | add'
echo "$tasks" | jq -r '.[] | [.ID] | add' | tr -d '\r'
fi
exit 0
fi
@ -248,7 +248,7 @@ main() {
echo "$containers"
else
# Only display container(s) id in quiet mode
echo "$containers" | jq -r '.[] | [.Id] | add'
echo "$containers" | jq -r '.[] | [.Id] | add' | tr -d '\r'
fi
exit 0
fi
@ -277,7 +277,7 @@ main() {
echo "$STACKS"
else
# Only display stack names in quiet mode
echo "$STACKS" | jq -r '.[] | [.Name] | add'
echo "$STACKS" | jq -r '.[] | [.Name] | add' | tr -d '\r'
fi
exit 0
fi
@ -912,7 +912,7 @@ unique_temp_file_path() {
if [ -w "$temp_path" ]; then
local file_uuid
# Generate universally unique identifier (UUID)
file_uuid=$(if [ -x "$(command -v uuidgen)" ]; then uuidgen; else cat /proc/sys/kernel/random/uuid; fi)
file_uuid=$(if [ -x "$(command -v uuidgen)" ]; then uuidgen; else cat /proc/sys/kernel/random/uuid 2> /dev/null || od -vAn -N4 -t u4 < /dev/urandom | tr -d ' '; fi)
if [ -z "$file_uuid" ]; then
echo_error "You must install the 'uuidgen' program, to generate universally unique identifier"
exit 1
@ -1340,11 +1340,13 @@ lint() {
###################################################
env_file_to_json() {
local jq_command
local sh_command
# For macOS compatibility
jq_command="$(which jq)"
# For macOS and Windows compatibility
jq_command="$(command -v jq)"
sh_command="$(command -v sh)"
env -i sh -c "(unset \$(env | sed 's/=.*//'); set -a; . $(readlink_wrapper -f $ENVIRONMENT_VARIABLES_FILE); set +a; \"$jq_command\" -njc 'env | to_entries | map({name: .key, value: .value})')"
env -i "$sh_command" -c "(unset \$(env | sed 's/=.*//'); set -a; . $(readlink_wrapper -f $ENVIRONMENT_VARIABLES_FILE); set +a; \"$jq_command\" -njc 'env | to_entries | map({name: .key, value: .value})')"
}
# Set the ACTIONS variable who's a list of all psu actions

View File

@ -15,11 +15,11 @@ fi
SWARM_NODE_NAME=${SWARM_NODE_NAME:-cluster}
SWARM_NODE_IP=${SWARM_NODE_IP:-$(getent hosts "${SWARM_NODE_NAME}" | awk '{ print $1 }')}
export BASE_DOMAIN="$SWARM_NODE_IP.nip.io"
export BASE_DOMAIN=${SWARM_NODE_IP}.nip.io
export PSU_STACK_NAME="web-app"
PSU_URL="https://portainer.$BASE_DOMAIN"
PSU_USER="admin"
PSU_PASSWORD=${PSU_PASSWORD:-"$(openssl rand -hex 50)"}
PSU_URL="${PSU_URL:-"https://portainer.${BASE_DOMAIN}"}"
PSU_USER="${PSU_USER:-admin}"
PSU_PASSWORD="${PSU_PASSWORD:-"$(openssl rand -hex 50)"}"
PSU_TAG=$(if [ -n "$PSU_TAG" ]; then
eval echo "$PSU_TAG";