diff --git a/Makefile b/Makefile index 1956a71..a186d5a 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ MAKEFLAGS += --warn-undefined-variables SHELL := /bin/bash .SHELLFLAGS := -o pipefail -euc .DEFAULT_GOAL := install +ENGINE := $(shell { command -v podman || command -v docker; } 2>/dev/null) include Makefile.variables @@ -33,7 +34,7 @@ clean: ## prefix before other make targets to run in your local dev environment local: | quiet - @$(eval DOCKRUN= ) + @$(eval ENGINERUN= ) @mkdir -p tmp @touch tmp/dev_image_id quiet: # this is silly but shuts up 'Nothing to be done for `local`' @@ -42,9 +43,9 @@ quiet: # this is silly but shuts up 'Nothing to be done for `local`' prepare: tmp/dev_image_id tmp/dev_image_id: Dockerfile.dev scripts/devtools.sh @mkdir -p tmp - @docker rmi -f ${DEV_IMAGE} > /dev/null 2>&1 || true - @docker build -t ${DEV_IMAGE} -f Dockerfile.dev . - @docker inspect -f "{{ .ID }}" ${DEV_IMAGE} > tmp/dev_image_id + @${ENGINE} rmi -f ${DEV_IMAGE} > /dev/null 2>&1 || true + @${ENGINE} build -t ${DEV_IMAGE} -f Dockerfile.dev . + @${ENGINE} inspect -f "{{ .ID }}" ${DEV_IMAGE} > tmp/dev_image_id # ---------------------------------------------- # build @@ -54,60 +55,61 @@ build: build/dev .PHONY: build/dev build/dev: test *.go @mkdir -p bin/ - ${DOCKRUN} go build --ldflags "$(LDFLAGS)" - ${DOCKRUN} bash ./scripts/acceptance.sh + ${ENGINERUN} go build --ldflags "$(LDFLAGS)" + ${ENGINERUN} bash ./scripts/acceptance.sh ## Compile the project for multiple OS and Architectures. xcompile: check @rm -rf build/ @mkdir -p build - ${DOCKRUN} bash ./scripts/xcompile.sh + ${ENGINERUN} bash ./scripts/xcompile.sh @find build -type d -exec chmod 755 {} \; || : @find build -type f -exec chmod 755 {} \; || : .PHONY: install install: build - ${DOCKRUN} go install + ${ENGINERUN} go install # Each of the fetch should be an entry within vendor.json; not currently included within project .PHONY: vendor vendor: tmp/dev_image_id - ${DOCKRUN} go mod vendor + @mkdir -p vendor + ${ENGINERUN} go mod vendor # ---------------------------------------------- # develop and test .PHONY: format format: vendor - ${DOCKRUN} bash ./scripts/format.sh + ${ENGINERUN} bash ./scripts/format.sh .PHONY: secure secure: format - ${DOCKRUN} bash ./scripts/secure.sh + ${ENGINERUN} bash ./scripts/secure.sh .PHONY: check check: secure - ${DOCKRUN} bash ./scripts/check.sh + ${ENGINERUN} bash ./scripts/check.sh .PHONY: test test: check - ${DOCKRUN} bash ./scripts/test.sh + ${ENGINERUN} bash ./scripts/test.sh .PHONY: cover cover: check @rm -rf cover/ @mkdir -p cover - ${DOCKRUN} bash ./scripts/coverage.sh + ${ENGINERUN} bash ./scripts/coverage.sh @find cover -type d -exec chmod 755 {} \; || : @find cover -type f -exec chmod 644 {} \; || : .PHONY: release release: xcompile - ${DOCKRUN} bash ./scripts/publish.sh + ${ENGINERUN} bash ./scripts/publish.sh # ---------------------------------------------- # utilities diff --git a/Makefile.variables b/Makefile.variables index 406bac3..b1968ba 100644 --- a/Makefile.variables +++ b/Makefile.variables @@ -29,7 +29,7 @@ endif DEV_IMAGE := ${PROJECT}_dev -DOCKRUN := docker run --rm \ +ENGINERUN := ${ENGINE} run --rm \ -e LDFLAGS="${LDFLAGS}" \ -e GITHUB_TOKEN="${GITHUB_TOKEN}" \ -v ${ROOT}/vendor:/go/src \ diff --git a/README.md b/README.md index 7c12d6b..9dd86b0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ a lightweight and portable command-line YAML processor. `yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml files as well as json. It doesn't yet support everything `jq` does - but it does support the most common operations and functions, and more is being added continuously. -yq is written in go - so you can download a dependency free binary for your platform and you are good to go! If you prefer there are a variety of package managers that can be used as well as docker, all listed below. +yq is written in go - so you can download a dependency free binary for your platform and you are good to go! If you prefer there are a variety of package managers that can be used as well as Docker and Podman, all listed below. ## Quick Usage Guide @@ -96,7 +96,7 @@ sudo mv /etc/myfile.tmp /etc/myfile rm /etc/myfile.tmp ``` -### Run with Docker +### Run with Docker or Podman #### Oneshot use: @@ -104,6 +104,10 @@ rm /etc/myfile.tmp docker run --rm -v "${PWD}":/workdir mikefarah/yq [flags] [expression ]FILE... ``` +```bash +podman run --rm -v "${PWD}":/workdir mikefarah/yq [flags] [expression ]FILE... +``` + #### Pipe in via STDIN: You'll need to pass the `-i\--interactive` flag to docker: @@ -112,12 +116,20 @@ You'll need to pass the `-i\--interactive` flag to docker: cat myfile.yml | docker run -i --rm mikefarah/yq e . - ``` +```bash +cat myfile.yml | podman run -i --rm mikefarah/yq e . - +``` + #### Run commands interactively: ```bash docker run --rm -it -v "${PWD}":/workdir --entrypoint sh mikefarah/yq ``` +```bash +podman run --rm -it -v "${PWD}":/workdir --entrypoint sh mikefarah/yq +``` + It can be useful to have a bash function to avoid typing the whole docker command: ```bash @@ -126,17 +138,27 @@ yq() { } ``` +```bash +yq() { + podman run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" +} +``` + #### Running as root: -`yq`'s docker image no longer runs under root (https://github.com/mikefarah/yq/pull/860). If you'd like to install more things in the docker image, or you're having permissions issues when attempting to read/write files you'll need to either: +`yq`'s container image no longer runs under root (https://github.com/mikefarah/yq/pull/860). If you'd like to install more things in the container image, or you're having permissions issues when attempting to read/write files you'll need to either: ``` docker run --user="root" -it --entrypoint sh mikefarah/yq ``` -Or, in your docker file: +``` +podman run --user="root" -it --entrypoint sh mikefarah/yq +``` + +Or, in your Dockerfile: ``` FROM mikefarah/yq @@ -266,4 +288,4 @@ Use "yq [command] --help" for more information about a command. - `yq` attempts to preserve comment positions and whitespace as much as possible, but it does not handle all scenarios (see https://github.com/go-yaml/yaml/tree/v3 for details) - Powershell has its own...[opinions on quoting yq](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#quotes-in-windows-powershell) -See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions. \ No newline at end of file +See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions.