summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsitkevij <1553398+sitkevij@users.noreply.github.com>2020-11-21 19:32:26 -0800
committersitkevij <1553398+sitkevij@users.noreply.github.com>2020-11-21 19:32:26 -0800
commitdf0281d525a3cd9e307ddf3a89ee4322b0d1725a (patch)
tree8e60d1cbc0427b50e3960c9bd2886bcf296270df
parent39589d50d0f564a6fc0e26e86dbdea693a8bf400 (diff)
#48 re-order colorize logic, update docker and add new gha
-rw-r--r--.github/workflows/ci.yml2
-rw-r--r--.github/workflows/docker.yml29
-rw-r--r--Dockerfile25
-rw-r--r--Dockerfile.alpine22
-rw-r--r--Makefile7
-rw-r--r--README.md14
-rw-r--r--src/lib.rs16
7 files changed, 64 insertions, 51 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 058100b..ed9a012 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,6 +13,7 @@ on:
env:
RUST_BACKTRACE: full
+ NO_COLOR: 1
jobs:
test:
@@ -41,7 +42,6 @@ jobs:
- run: cargo install hyperfine
- run: echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." | target/release/hx
- run: hyperfine -i --warmup 20 "echo 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | target/release/hx"
- # - run: cargo test --verbose --all -- --nocapture
# - run: cargo test --verbose --workspace --all-features
# - run: cargo test --verbose --workspace --no-default-features
# see https://github.com/actions/upload-release-asset
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644
index 0000000..e8a82a5
--- /dev/null
+++ b/.github/workflows/docker.yml
@@ -0,0 +1,29 @@
+name: docker
+
+on:
+ push:
+ branches:
+ - main
+ - master
+
+jobs:
+ main:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Set up QEMU
+ uses: docker/setup-qemu-action@v1
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
+ - name: Login to DockerHub
+ uses: docker/login-action@v1
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
+ - name: Build and push
+ id: docker_build
+ uses: docker/build-push-action@v2
+ with:
+ push: true
+ tags: sitkevij/hx:latest
+ - name: Image digest
+ run: echo ${{ steps.docker_build.outputs.digest }}
diff --git a/Dockerfile b/Dockerfile
index 653dcdb..072b68a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,19 +1,14 @@
-FROM debian:stretch-slim
+FROM rust:alpine
WORKDIR /root
+ENTRYPOINT ["target/release/hx"]
LABEL org.label-schema.name="hx" \
- org.label-schema.description="Futuristic take on hexdump, made in rust" \
- org.label-schema.url="https://hub.docker.com/r/sitkevij/hex/" \
- org.label-schema.usage="https://github.com/sitkevij/hex/blob/master/README.md" \
- org.label-schema.vcs-url="https://github.com/sitkevij/hex" \
- org.label-schema.vendor="sitkevij" \
- org.label-schema.version="0.2.1" \
- maintainer="https://github.com/sitkevij"
-RUN apt-get update && \
- apt-get install --no-install-recommends -y \
- ca-certificates curl build-essential
- # file autoconf automake autotools-dev libtool xutils-dev && \
- # rm -rf /var/lib/apt/lists/*
-RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
+ org.label-schema.description="Futuristic take on hexdump, made in rust" \
+ org.label-schema.url="https://hub.docker.com/r/sitkevij/hex/" \
+ org.label-schema.usage="https://github.com/sitkevij/hex/blob/master/README.md" \
+ org.label-schema.vcs-url="https://github.com/sitkevij/hex" \
+ org.label-schema.vendor="sitkevij" \
+ org.label-schema.version="latest" \
+ maintainer="https://github.com/sitkevij"
ENV PATH=/root/.cargo/bin:$PATH
COPY . .
-RUN cargo build \ No newline at end of file
+RUN cargo build --release \ No newline at end of file
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
deleted file mode 100644
index 81ea1d3..0000000
--- a/Dockerfile.alpine
+++ /dev/null
@@ -1,22 +0,0 @@
-FROM sitkevij/alpine-rust:rustup.rs
-ENTRYPOINT ["hx"]
-WORKDIR /tmp/hex
-LABEL org.label-schema.name="hx" \
- org.label-schema.description="Futuristic take on hexdump, made in rust" \
- org.label-schema.url="https://hub.docker.com/r/sitkevij/hex/" \
- org.label-schema.usage="https://github.com/sitkevij/hex/blob/master/README.md" \
- org.label-schema.vcs-url="https://github.com/sitkevij/hex" \
- org.label-schema.vendor="sitkevij" \
- org.label-schema.version="0.2.0" \
- maintainer="https://github.com/sitkevij"
-# RUN echo "export PATH=$PATH:~/.cargo/bin" >> ~/.profile && source ~/.profile
-COPY . .
-# RUN cat ~/.profile
-# RUN echo $PATH
-# RUN ls ~/.cargo/bin
-# https://blog.rust-lang.org/2016/05/13/rustup.html
-# rustup target add arm-linux-androideabi
-# rustup target add x86_64-unknown-linux-musl
-# rustup target add x86_64-unknown-linux-glibc
-RUN echo "export PATH=$PATH:~/.cargo/bin" >> ~/.profile && source ~/.profile && rustup self update && cargo build --target=x86_64-unknown-linux-musl
-
diff --git a/Makefile b/Makefile
index f719f78..a20d463 100644
--- a/Makefile
+++ b/Makefile
@@ -77,8 +77,11 @@ install-force: clean release debug test
clippy:
cargo clippy
-docker:
- docker build -t sitkevij/stretch-slim:$(BINARY)-0.2.0 .
+docker-build:
+ docker build -t sitkevij/hx:latest .
+
+docker-run:
+ cat README.md | docker run -i sitkevij/hx:latest
clean: ## Remove all artifacts
rm -rf $(DEBUG_DIR)
diff --git a/README.md b/README.md
index ac9e05e..954c9fe 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Futuristic take on hexdump.
-`hex` accepts a file path as input and outputs a hexadecimal colorized view to stdout.
+[hx](https://github.com/sitkevij/hex) accepts a file path as input and outputs a hexadecimal colorized view to stdout.
```sh
$ hx tests/files/alphanumeric.txt
@@ -16,7 +16,7 @@ $ hx tests/files/alphanumeric.txt
bytes: 68
```
-`hex` also accepts stdin as input.
+`hx` also accepts stdin as input.
```sh
cat "tests/files/alphanumeric.txt" | hx
@@ -91,10 +91,16 @@ Which will compile the release version, run tests and install release binary to
If `<USERDIR>/.cargo/bin` is part of the `PATH` environment variable, `hx` should be able to be executed anywhere in the shell.
-### debian
+### debian install
```sh
-curl -sLO https://github.com/sitkevij/hex/releases/download/v0.3.2/hx_0.3.2_amd64.deb && dpkg -i hx_0.3.2_amd64.deb
+curl -sLO https://github.com/sitkevij/hex/releases/download/v0.4.0/hx_0.4.0_amd64.deb && dpkg -i hx_0.4.0_amd64.deb
+```
+
+### docker run
+
+```sh
+cat README.md | docker run -i sitkevij/hx:latest
```
## features
diff --git a/src/lib.rs b/src/lib.rs
index cd57f25..4fbcc0a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -269,11 +269,19 @@ pub fn run(matches: ArgMatches) -> Result<(), Box<dyn Error>> {
}
}
- // check no_color here, allow override of via arg below
+ // check no_color here
+ // override via ARG_CLR below
if is_no_color() {
colorize = false;
}
+ // prevent term color codes being sent to stdout
+ // test: cat Cargo.toml | target/debug/hx | more
+ // override via ARG_CLR below
+ if !atty::is(Stream::Stdout) {
+ colorize = false;
+ }
+
if let Some(color) = matches.value_of(ARG_CLR) {
let color_v = color.parse::<u8>().unwrap();
if color_v == 1 {
@@ -283,12 +291,6 @@ pub fn run(matches: ArgMatches) -> Result<(), Box<dyn Error>> {
}
}
- // prevent term color codes being sent to stdout
- // test: cat Caqrgo.toml | target/debug/hx | more
- if !atty::is(Stream::Stdout) {
- colorize = false;
- }
-
// array output mode is mutually exclusive
if let Some(array) = matches.value_of(ARG_ARR) {
output_array(array, buf, truncate_len, column_width)?;