diff --git a/.dockerignore b/.dockerignore index 9414382..ae3f10f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,10 @@ +*.nix +.github/ +.tool-versions Dockerfile +cabal.project.* +dist-newstyle/ +example/ +fixtures/ +script/ +stack.yaml* diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index 67c397d..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Build and Test -on: - push: - branches: - - master - pull_request: - types: - - opened - - synchronize -jobs: - build-and-test: - strategy: - matrix: - ghc: ["8.6.5", "8.8.4", "8.10.4", "9.0.1"] - os: [ubuntu-latest] - include: - - os: macos-latest - ghc: "9.0.1" - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - name: Install Zsh - run: | - if [ "$RUNNER_OS" == "Linux" ]; then - sudo apt-get update - sudo apt-get install zsh - else - brew update - brew install zsh - fi - - uses: haskell/actions/setup@v1 - id: setup-haskell-cabal - with: - ghc-version: ${{ matrix.ghc }} - cabal-version: "3.4" - - run: cabal update - - run: cabal freeze --enable-tests - - uses: actions/cache@v2 - with: - path: | - ${{ steps.setup-haskell-cabal.outputs.cabal-store }} - dist-newstyle - key: dependencies-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} - restore-keys: | - dependencies-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} - dependencies-${{ runner.os }}-${{ matrix.ghc }}- - - name: Compile dependencies - run: cabal build --only-dependencies - - name: Compile project - run: cabal build --enable-tests - - run: cabal test --enable-tests - - name: Generate module documentation with Haddock - run: | - # Fixes issue with different haddock coverage with different ghc versions https://github.com/haskell/haddock/issues/123 - cabal haddock | grep "100%" | wc -l | grep -E "[4-9]|[1-9][0-9]+" || - (echo "Haddock failed with exit code 1. Have you checked that the minimum of 4 modules with 100% documentation is fulfilled?" && false) - - run: cabal sdist - - if: matrix.ghc == '8.8.4' - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - if: matrix.ghc == '8.8.4' - name: Dockerize - run: | - docker build . -t hapistrano - docker run --rm hapistrano --version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..56d19df --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,84 @@ +--- +# The present workflow was made based on the following references: +# - https://github.com/actions/cache/blob/main/examples.md#haskell---cabal +# - https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md +# - https://github.com/haskell/time/blob/master/.github/workflows/ci.yml +# - https://github.com/stackbuilders/stache/blob/master/.github/workflows/ci.yaml +name: CI + +on: push + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + ghc: + - "9.0.1" + - "8.10.4" + - "8.8.4" + - "8.6.5" + include: + - os: macos-latest + ghc: "9.0.1" + + steps: + - uses: actions/checkout@v3 + - uses: haskell/actions/setup@v1 + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: "3.4" + - run: | + if [ "$RUNNER_OS" == "Linux" ] + then + sudo apt-get update + sudo apt-get install zsh + else + brew update + brew install zsh + fi + - run: cabal update + - run: cabal configure --enable-tests + - run: cabal freeze + - uses: actions/cache@v3 + with: + key: v1-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: v1-${{ runner.os }}-${{ matrix.ghc }}- + path: | + ~/.cabal/packages + ~/.cabal/store + dist-newstyle + - run: cabal build --only-dependencies + - run: cabal build + - run: cabal test + - run: | + # Fixes issue with different haddock coverage with different ghc versions https://github.com/haskell/haddock/issues/123 + cabal haddock | grep "100%" | wc -l | grep -E "[4-9]|[1-9][0-9]+" || + (echo "Haddock failed with exit code 1. Have you checked that the minimum of 4 modules with 100% documentation is fulfilled?" && false) + + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: docker/setup-buildx-action@v1 + - uses: actions/cache@v3 + with: + key: v1-${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: v1-${{ runner.os }}-buildx- + path: /tmp/.buildx-cache + - uses: docker/build-push-action@v2 + with: + context: . + load: true + tags: hapistrano:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + - run: docker run hapistrano --version + - run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.gitignore b/.gitignore index b5118a3..6f12d56 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,12 @@ cabal-dev *.chs.h *.dyn_o *.dyn_hi +.cabal-sandbox/ .hpc .hsenv -.cabal-sandbox/ +.tool-versions +cabal.project.freeze +cabal.project.local cabal.sandbox.config *.prof *.aux diff --git a/Dockerfile b/Dockerfile index 4b86d6d..882a3c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,62 +1,33 @@ -# Build Hapistrano -FROM alpine:3.13 as build-env - -MAINTAINER Nicolas Vivar - -RUN apk update \ - && apk add \ - alpine-sdk \ - bash \ - ca-certificates \ - cabal \ - ghc-dev \ - ghc \ - git \ - gmp-dev \ - gnupg \ - libffi-dev \ - linux-headers \ - upx \ - zlib-dev - -WORKDIR /hapistrano - +FROM alpine:3.15 AS build +RUN apk update && \ + apk add \ + alpine-sdk \ + bash \ + ca-certificates \ + cabal \ + ghc \ + ghc-dev \ + git \ + gmp-dev \ + gnupg \ + libffi-dev \ + linux-headers \ + zlib-dev +WORKDIR /usr/src/app COPY hapistrano.cabal . -COPY src/ src/ -COPY app/ app/ -COPY script/ script/ -COPY LICENSE . -COPY Setup.hs . -# So Hapistrano is built with version information -COPY .git/ .git/ -# Cabal has changed behaviour and it requires all modules listed -COPY spec/ spec/ -COPY fixtures/ fixtures/ -COPY CHANGELOG.md . -COPY README.md . -RUN touch Dockerfile - -RUN cabal update -RUN cabal install --only-dependencies -RUN cabal configure -f static -RUN cabal build hap - -# Compress the resulting binary -RUN mkdir bin -RUN cp /hapistrano/dist-newstyle/build/x86_64-linux/ghc-8.8.4/hapistrano-0.4.3.1/x/hap/build/hap/hap bin/ -RUN upx /hapistrano/bin/hap - -# Copy Hapistrano to a basic Alpine with SSH -FROM alpine:3.13 - -RUN apk update \ - && apk add \ - openssh-client \ - ca-certificates \ - git +RUN cabal update && \ + cabal configure -f static && \ + cabal build --only-dependencies +COPY . . +RUN cabal install +FROM alpine:3.15 +MAINTAINER Nicolas Vivar +RUN apk update && \ + apk add \ + ca-certificates \ + git \ + openssh-client RUN mkdir ~/.ssh - -COPY --from=build-env /hapistrano/bin/hap /bin/hap - -ENTRYPOINT ["/bin/hap"] +COPY --from=build /root/.cabal/bin/hap /usr/local/bin/hap +ENTRYPOINT ["/usr/local/bin/hap"] diff --git a/README.md b/README.md index 0da1f29..c9a4c5a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build and Test](https://github.com/stackbuilders/hapistrano/actions/workflows/build-and-test.yml/badge.svg?branch=master)](https://github.com/stackbuilders/hapistrano/actions/workflows/build-and-test.yml) +[![CI](https://github.com/stackbuilders/hapistrano/actions/workflows/ci.yml/badge.svg)](https://github.com/stackbuilders/hapistrano/actions/workflows/ci.yml) [![Hackage version](https://img.shields.io/hackage/v/hapistrano.svg)](http://hackage.haskell.org/package/hapistrano) [![Docker Hub](https://img.shields.io/docker/build/stackbuilders/hapistrano.svg?style=flat)](https://hub.docker.com/r/stackbuilders/hapistrano) diff --git a/hapistrano.cabal b/hapistrano.cabal index 194c873..f9578b8 100644 --- a/hapistrano.cabal +++ b/hapistrano.cabal @@ -31,9 +31,6 @@ cabal-version: >=1.18 tested-with: GHC==8.6.5, GHC==8.8.4, GHC==8.10.4, GHC==9.0.1 extra-source-files: CHANGELOG.md , README.md - , Dockerfile -data-files: script/clean-build.sh - , fixtures/*.yaml flag dev description: Turn on development settings.