diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..0dc3acb --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,47 @@ +name: Build and push Docker images to Docker Hub + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + build_docker_image: + # This workflow is only of value to Owner and would always be skipped in forks + if: github.repository_owner == 'agriyakhetarpal' + name: Build image + runs-on: buildjet-2vcpu-ubuntu-2204-arm + + 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 Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image to Docker Hub + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + tags: agriyakhetarpal/hugo:latest # To be updated with exact Docker Hub username and image name + push: false + platforms: linux/amd64, linux/arm64 + + - name: Run tests inside the built Docker image + run: | + docker run --rm agriyakhetarpal/hugo:latest hugo version + docker run --rm agriyakhetarpal/hugo:latest hugo env + + - name: List built image(s) + run: docker images diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4f85fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM python:3.11.9-slim + +ENV ZIG_VERSION=0.11.0 + +WORKDIR / + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc \ + g++ \ + clang \ + git \ + wget \ + dos2unix \ + xz-utils \ + musl-tools \ + && rm -rf /var/lib/apt/lists/* + +ARG TARGETARCH=x86_64 + +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + wget "https://ziglang.org/builds/zig-linux-aarch64-${ZIG_VERSION}.tar.xz" && \ + tar -C /usr/local -xf "zig-linux-aarch64-${ZIG_VERSION}.tar.xz" && \ + rm "zig-linux-aarch64-${ZIG_VERSION}.tar.xz"; \ + else \ + wget "https://ziglang.org/builds/zig-linux-x86_64-${ZIG_VERSION}.tar.xz" && \ + tar -C /usr/local -xf "zig-linux-x86_64-${ZIG_VERSION}.tar.xz" && \ + rm "zig-linux-x86_64-${ZIG_VERSION}.tar.xz"; \ + fi + +ENV PATH="${PATH}:/usr/local/zig-linux-${TARGETARCH}-${ZIG_VERSION}" + +RUN git clone https://github.com/agriyakhetarpal/hugo-python-distributions && \ + cd hugo-python-distributions && \ + pip install -e . && \ + pip install . + +WORKDIR /hugo-python-distributions + +CMD ["/bin/bash"] diff --git a/setup.py b/setup.py index f72e839..3933f19 100644 --- a/setup.py +++ b/setup.py @@ -196,11 +196,13 @@ def run(self): # Build a static binary on Windows to avoid missing DLLs from MinGW, # i.e., libgcc_s_seh-1.dll, libstdc++-6.dll, etc. - BUILDING_FOR_WINDOWS = ( - os.environ.get("GOOS") == "windows" or sys.platform == "win32" + BUILD_STATIC = ( + os.environ.get("GOOS") == "windows" + or sys.platform == "win32" + or "linux-musl" in os.environ.get("CC", "") + or "linux-musl" in os.environ.get("CXX", "") ) - - if BUILDING_FOR_WINDOWS: + if BUILD_STATIC: ldflags.append("-extldflags '-static'") if not (Path(HUGO_CACHE_DIR).resolve() / f"hugo-{HUGO_VERSION}").exists():