diff --git a/.github/workflows/draft.yml b/.github/workflows/draft.yml index 8e4af321..8babb454 100644 --- a/.github/workflows/draft.yml +++ b/.github/workflows/draft.yml @@ -6,7 +6,7 @@ name: Draft on: - create: + push: tags: - v* @@ -23,14 +23,17 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v2 + - name: Cache Docker layers uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: ${{ runner.os }}-buildx- + - name: Build Docker image uses: docker/build-push-action@v2 with: @@ -39,6 +42,7 @@ jobs: tags: ${{ github.repository }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + - name: Copy static binary run: | docker run \ @@ -47,6 +51,17 @@ jobs: ${{ github.repository }} \ /usr/local/bin/hap \ /root/bin/hap-${{ github.ref_name }}-linux-x86_64-bin + + - name: Change owner before compression + run: sudo chown $USER:$USER bin/hap-${{ github.ref_name }}-linux-x86_64-bin + + - name: Compress binary + uses: svenstaro/upx-action@v2 + with: + file: bin/hap-${{ github.ref_name }}-linux-x86_64-bin + args: --best --lzma + strip: true + - name: Create draft release uses: softprops/action-gh-release@v1 with: @@ -54,6 +69,7 @@ jobs: bin/hap-* LICENSE draft: true + - name: Move cache run: | rm -rf /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index bea7e39c..e173e660 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,43 @@ +# Build FROM quay.io/benz0li/ghc-musl:9.6.6 AS build + WORKDIR /usr/src/app -COPY hapistrano.cabal . + +# Install upx +RUN apk update && apk add --no-cache upx + +# Copy only the necessary files for dependency installation +COPY hapistrano.cabal ./ + +# Install dependencies RUN cabal update && \ cabal build --only-dependencies --enable-static + +# Copy the rest of the files. COPY . . -RUN cabal build --enable-executable-static && \ - cp $(cabal exec which hap) hap +# Build the application and compress the binary +RUN cabal build --enable-executable-static && \ + cp $(cabal exec which hap) hap && \ + upx hap +# Final image FROM alpine:3.15 -MAINTAINER Cristhian Motoche + +LABEL maintainer="Cristhian Motoche " + +# Install runtime dependencies RUN apk update && \ - apk add \ + apk add --no-cache \ ca-certificates \ git \ openssh-client -RUN mkdir ~/.ssh + +# Create .ssh directory +RUN mkdir -p ~/.ssh + +# Copy the binary from the build stage COPY --from=build /usr/src/app/hap /usr/local/bin/hap + +# Set the entrypoint and default command ENTRYPOINT ["/usr/local/bin/hap"] CMD ["--help"]