diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3b1eb6cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +/** +!/app +/app/cli_internal.*.in +!/include +!/scripts +!/src +!configure +!AUTHORS +!Makefile +!LICENSE diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a875130..e32dd2d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -495,3 +495,37 @@ jobs: TRIPLET: ${{ env.AMD64_MACOSX_GCC }} run: | ./scripts/ci-update-homebrew-tap.sh + + docker: + needs: [tag, ci] + runs-on: ubuntu-latest + + env: + TAG: ${{ needs.tag.outputs.TAG }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + push: false + tags: | + zsv:${{ env.TAG }} + zsv:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f490f07d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:latest AS build + +LABEL maintainer="Liquidaty" +LABEL description="zsv: tabular data swiss-army knife CLI + world's fastest (simd) CSV parser" +LABEL url="https://github.com/liquidaty/zsv" + +RUN apk add --no-cache gcc make musl-dev perl + +WORKDIR /zsv +COPY . . + +RUN \ + PREFIX=amd64-linux-musl \ + CC=gcc \ + MAKE=make \ + ARTIFACT_DIR=artifacts \ + RUN_TESTS=false \ + STATIC_BUILD=1 \ + SKIP_ZIP_ARCHIVE=true \ + SKIP_TAR_ARCHIVE=true \ + ./scripts/ci-build.sh + +FROM scratch + +WORKDIR /zsv +COPY --from=build /zsv/amd64-linux-musl/bin/zsv . +COPY --from=build /zsv/AUTHORS /zsv/LICENSE ./ + +ENTRYPOINT [ "./zsv" ] diff --git a/app/Makefile b/app/Makefile index d69200dc..07622d18 100644 --- a/app/Makefile +++ b/app/Makefile @@ -484,7 +484,7 @@ clean-util-lib: clean-lib: @rm -rf ${BUILD_DIR}-external -clean: clean-obj +clean: clean-obj clean-internal rm -rf ${BUILD_DIR} ${MAKE} -C test clean CONFIGFILE=${CONFIGFILEPATH} DEBUG=${DEBUG} @@ -492,6 +492,9 @@ clean-obj: rm -rf ${BUILD_DIR}/bin ${INIH_OBJECT} ${JSONWRITER_OBJECT} ${UTF8PROC_OBJECT} rm -rf external/utf8proc-2.6.1 +clean-internal: + $(RM) cli_internal.c.in cli_internal.h.in + ${UTF8PROC_SRC}/utf8proc.c ${UTF8PROC_SRC}/utf8proc.h: ${THIS_MAKEFILE_DIR}/external/utf8proc-2.6.1.tar.gz @cd external && tar xf $< && chown -R `whoami` utf8proc-2.6.1 @touch $@ diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh index c4e70205..937ffb86 100755 --- a/scripts/ci-build.sh +++ b/scripts/ci-build.sh @@ -19,6 +19,14 @@ if [ "$RUN_TESTS" != true ]; then RUN_TESTS=false fi +if [ "$SKIP_ZIP_ARCHIVE" != true ]; then + SKIP_ZIP_ARCHIVE=false +fi + +if [ "$SKIP_TAR_ARCHIVE" != true ]; then + SKIP_TAR_ARCHIVE=false +fi + #JQ_DIR="$PWD/jq" #JQ_PREFIX="$JQ_DIR/build" #JQ_INCLUDE_DIR="$JQ_PREFIX/include" @@ -33,6 +41,8 @@ echo "[INF] LDFLAGS: $LDFLAGS" echo "[INF] MAKE: $MAKE" echo "[INF] RUN_TESTS: $RUN_TESTS" echo "[INF] ARTIFACT_DIR: $ARTIFACT_DIR" +echo "[INF] SKIP_ZIP_ARCHIVE: $SKIP_ZIP_ARCHIVE" +echo "[INF] SKIP_TAR_ARCHIVE: $SKIP_TAR_ARCHIVE" #echo "[INF] JQ_DIR: $JQ_DIR" #echo "[INF] JQ_PREFIX: $JQ_PREFIX" #echo "[INF] JQ_INCLUDE_DIR: $JQ_INCLUDE_DIR" @@ -74,20 +84,24 @@ echo "[INF] Built successfully!" mkdir -p "$ARTIFACT_DIR" -ZIP="$PREFIX.zip" -echo "[INF] Compressing [$ZIP]" -cd "$PREFIX" -zip -r "$ZIP" . -ls -Gghl "$ZIP" -cd .. -mv "$PREFIX/$ZIP" "$ARTIFACT_DIR" -echo "[INF] Compressed! [$ZIP]" - -TAR="$PREFIX.tar.gz" -echo "[INF] Compressing [$TAR]" -tar -czvf "$TAR" "$PREFIX" -ls -Gghl "$TAR" -mv "$TAR" "$ARTIFACT_DIR" -echo "[INF] Compressed! [$TAR]" +if [ "$SKIP_ZIP_ARCHIVE" = false ]; then + ZIP="$PREFIX.zip" + echo "[INF] Compressing [$ZIP]" + cd "$PREFIX" + zip -r "$ZIP" . + ls -Gghl "$ZIP" + cd .. + mv "$PREFIX/$ZIP" "$ARTIFACT_DIR" + echo "[INF] Compressed! [$ZIP]" +fi + +if [ "$SKIP_TAR_ARCHIVE" = false ]; then + TAR="$PREFIX.tar.gz" + echo "[INF] Compressing [$TAR]" + tar -czvf "$TAR" "$PREFIX" + ls -Gghl "$TAR" + mv "$TAR" "$ARTIFACT_DIR" + echo "[INF] Compressed! [$TAR]" +fi echo "[INF] --- [DONE] ---"