Skip to content

Commit

Permalink
Drop docker compose, use layer cache instead
Browse files Browse the repository at this point in the history
This drops the bat-server setup with a docker-compose in favor of a not
so over-engineered dockerfile.

This leverages the docker layer cache on each image re-build, so there's
no need to run `bat cache --build` if the syntax didn't change.

The point of bat-server was being able to use it for both highlight_ and
theme_regression.sh. But we can do that with a plain old Docker image if
we overwrite the entrypoint (run_highlight_ vs run_theme_regression.sh).

This improves DX for two reasons:

1. no need to `docker compose down` at the end of a coding session. (I
always forget.)
2. doesn't `bat cache --build` when the syntax file didn't change, which
makes that case speedup 2-3x.
  • Loading branch information
victor-gp committed Jul 9, 2022
1 parent 662e37f commit 310d732
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 39 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# only used for bat-test.dockerfile

*
!/syntaxes/
!/tests/docker/*regression.sh
!/tests/source
15 changes: 0 additions & 15 deletions tests/docker/bat-server.compose.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions tests/docker/bat-server.dockerfile

This file was deleted.

18 changes: 18 additions & 0 deletions tests/docker/bat-test.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# usage: through highlight_regression.sh and theme_regression.sh

FROM curlimages/curl:latest AS fetch-pkg
LABEL keep=false
ARG BAT_VERSION=0.21.0
RUN curl -LJ \
https://github.com/sharkdp/bat/releases/download/v$BAT_VERSION/bat_${BAT_VERSION}_amd64.deb \
--output /tmp/bat.deb

FROM debian:bullseye-slim
COPY --from=fetch-pkg /tmp/bat.deb /tmp
RUN dpkg --install /tmp/bat.deb
ENV COLORTERM=truecolor
COPY ./tests/docker/*regression.sh /tests/
COPY ./tests/source /tests/source
COPY ./syntaxes/cmd-help.sublime-syntax /root/.config/bat/syntaxes/
RUN bat cache --build > /dev/null
ENTRYPOINT /tests/run_highlight_regression.sh
4 changes: 1 addition & 3 deletions tests/docker/run_highlight_regression.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

bat cache --build > /dev/null

for source_path in source/* ; do
# this dir is only for theme_regression.sh
# this dir is only for run_theme_regression.sh
[ "$source_path" = source/theme ] && continue

filename=$(basename "$source_path")
Expand Down
2 changes: 0 additions & 2 deletions tests/docker/run_theme_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

bat cache --build > /dev/null

readarray -t themes <<< "$(bat --list-themes --color=never)"
cmd_prefix="bat --no-config -fpl cmd-help source/theme/synthetic.txt"

Expand Down
5 changes: 3 additions & 2 deletions tests/highlight_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

docker compose -f docker/bat-server.compose.yaml up -d
docker build --quiet -f docker/bat-test.dockerfile -t bat-test ..

docker exec bat-server bash /tests/run_highlight_regression.sh
volume="$PWD"/highlighted:/tests/highlighted
docker run -v "$volume" bat-test

# have git tell the effective difference between the version of the syntax
# in staging/HEAD and the one in working dir, for all highlighted samples
Expand Down
7 changes: 5 additions & 2 deletions tests/theme_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

docker compose -f docker/bat-server.compose.yaml up -d
docker build --quiet -f docker/bat-test.dockerfile -t bat-test ..

docker exec bat-server bash /tests/run_theme_regression.sh
volume="$PWD"/theme:/tests/theme
docker run -v "$volume" \
--entrypoint /tests/run_theme_regression.sh \
bat-test

# effective difference between HEAD/staging and working dir
GIT_PAGER='LESS=R less' git diff -- theme/

0 comments on commit 310d732

Please sign in to comment.