Add support for Podman as well as Docker (#1026)

Would like to see this package work on systems without Docker installed
which have Podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2021-12-01 18:01:44 -05:00 committed by GitHub
parent 14f8f92b76
commit a0c2e6faf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 21 deletions

View File

@ -2,6 +2,7 @@ MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -euc .SHELLFLAGS := -o pipefail -euc
.DEFAULT_GOAL := install .DEFAULT_GOAL := install
ENGINE := $(shell { command -v podman || command -v docker; } 2>/dev/null)
include Makefile.variables include Makefile.variables
@ -33,7 +34,7 @@ clean:
## prefix before other make targets to run in your local dev environment ## prefix before other make targets to run in your local dev environment
local: | quiet local: | quiet
@$(eval DOCKRUN= ) @$(eval ENGINERUN= )
@mkdir -p tmp @mkdir -p tmp
@touch tmp/dev_image_id @touch tmp/dev_image_id
quiet: # this is silly but shuts up 'Nothing to be done for `local`' 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 prepare: tmp/dev_image_id
tmp/dev_image_id: Dockerfile.dev scripts/devtools.sh tmp/dev_image_id: Dockerfile.dev scripts/devtools.sh
@mkdir -p tmp @mkdir -p tmp
@docker rmi -f ${DEV_IMAGE} > /dev/null 2>&1 || true @${ENGINE} rmi -f ${DEV_IMAGE} > /dev/null 2>&1 || true
@docker build -t ${DEV_IMAGE} -f Dockerfile.dev . @${ENGINE} build -t ${DEV_IMAGE} -f Dockerfile.dev .
@docker inspect -f "{{ .ID }}" ${DEV_IMAGE} > tmp/dev_image_id @${ENGINE} inspect -f "{{ .ID }}" ${DEV_IMAGE} > tmp/dev_image_id
# ---------------------------------------------- # ----------------------------------------------
# build # build
@ -54,60 +55,61 @@ build: build/dev
.PHONY: build/dev .PHONY: build/dev
build/dev: test *.go build/dev: test *.go
@mkdir -p bin/ @mkdir -p bin/
${DOCKRUN} go build --ldflags "$(LDFLAGS)" ${ENGINERUN} go build --ldflags "$(LDFLAGS)"
${DOCKRUN} bash ./scripts/acceptance.sh ${ENGINERUN} bash ./scripts/acceptance.sh
## Compile the project for multiple OS and Architectures. ## Compile the project for multiple OS and Architectures.
xcompile: check xcompile: check
@rm -rf build/ @rm -rf build/
@mkdir -p build @mkdir -p build
${DOCKRUN} bash ./scripts/xcompile.sh ${ENGINERUN} bash ./scripts/xcompile.sh
@find build -type d -exec chmod 755 {} \; || : @find build -type d -exec chmod 755 {} \; || :
@find build -type f -exec chmod 755 {} \; || : @find build -type f -exec chmod 755 {} \; || :
.PHONY: install .PHONY: install
install: build install: build
${DOCKRUN} go install ${ENGINERUN} go install
# Each of the fetch should be an entry within vendor.json; not currently included within project # Each of the fetch should be an entry within vendor.json; not currently included within project
.PHONY: vendor .PHONY: vendor
vendor: tmp/dev_image_id vendor: tmp/dev_image_id
${DOCKRUN} go mod vendor @mkdir -p vendor
${ENGINERUN} go mod vendor
# ---------------------------------------------- # ----------------------------------------------
# develop and test # develop and test
.PHONY: format .PHONY: format
format: vendor format: vendor
${DOCKRUN} bash ./scripts/format.sh ${ENGINERUN} bash ./scripts/format.sh
.PHONY: secure .PHONY: secure
secure: format secure: format
${DOCKRUN} bash ./scripts/secure.sh ${ENGINERUN} bash ./scripts/secure.sh
.PHONY: check .PHONY: check
check: secure check: secure
${DOCKRUN} bash ./scripts/check.sh ${ENGINERUN} bash ./scripts/check.sh
.PHONY: test .PHONY: test
test: check test: check
${DOCKRUN} bash ./scripts/test.sh ${ENGINERUN} bash ./scripts/test.sh
.PHONY: cover .PHONY: cover
cover: check cover: check
@rm -rf cover/ @rm -rf cover/
@mkdir -p cover @mkdir -p cover
${DOCKRUN} bash ./scripts/coverage.sh ${ENGINERUN} bash ./scripts/coverage.sh
@find cover -type d -exec chmod 755 {} \; || : @find cover -type d -exec chmod 755 {} \; || :
@find cover -type f -exec chmod 644 {} \; || : @find cover -type f -exec chmod 644 {} \; || :
.PHONY: release .PHONY: release
release: xcompile release: xcompile
${DOCKRUN} bash ./scripts/publish.sh ${ENGINERUN} bash ./scripts/publish.sh
# ---------------------------------------------- # ----------------------------------------------
# utilities # utilities

View File

@ -29,7 +29,7 @@ endif
DEV_IMAGE := ${PROJECT}_dev DEV_IMAGE := ${PROJECT}_dev
DOCKRUN := docker run --rm \ ENGINERUN := ${ENGINE} run --rm \
-e LDFLAGS="${LDFLAGS}" \ -e LDFLAGS="${LDFLAGS}" \
-e GITHUB_TOKEN="${GITHUB_TOKEN}" \ -e GITHUB_TOKEN="${GITHUB_TOKEN}" \
-v ${ROOT}/vendor:/go/src \ -v ${ROOT}/vendor:/go/src \

View File

@ -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. 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 ## Quick Usage Guide
@ -96,7 +96,7 @@ sudo mv /etc/myfile.tmp /etc/myfile
rm /etc/myfile.tmp rm /etc/myfile.tmp
``` ```
### Run with Docker ### Run with Docker or Podman
#### Oneshot use: #### Oneshot use:
@ -104,6 +104,10 @@ rm /etc/myfile.tmp
docker run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression ]FILE... docker run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression ]FILE...
``` ```
```bash
podman run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression ]FILE...
```
#### Pipe in via STDIN: #### Pipe in via STDIN:
You'll need to pass the `-i\--interactive` flag to docker: 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 . - cat myfile.yml | docker run -i --rm mikefarah/yq e . -
``` ```
```bash
cat myfile.yml | podman run -i --rm mikefarah/yq e . -
```
#### Run commands interactively: #### Run commands interactively:
```bash ```bash
docker run --rm -it -v "${PWD}":/workdir --entrypoint sh mikefarah/yq 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: It can be useful to have a bash function to avoid typing the whole docker command:
```bash ```bash
@ -126,17 +138,27 @@ yq() {
} }
``` ```
```bash
yq() {
podman run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@"
}
```
#### Running as root: #### 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 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 FROM mikefarah/yq