Skip to content

Commit

Permalink
[CI] Publish Docker image (WIP) (#217)
Browse files Browse the repository at this point in the history
* [CI] Publish Docker image
  • Loading branch information
iamazeem authored Oct 10, 2024
1 parent 3d67fc3 commit ec19a9e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 16 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
!/app
/app/cli_internal.*.in
!/include
!/scripts
!/src
!configure
!AUTHORS
!Makefile
!LICENSE
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
5 changes: 4 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,17 @@ 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}

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 $@
44 changes: 29 additions & 15 deletions scripts/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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] ---"

0 comments on commit ec19a9e

Please sign in to comment.