Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor GitHub Actions draft workflow and Dockerfile to use upx to compress binary #247

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: Draft

on:
create:
push:
tags:
- v*

Expand All @@ -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:
Expand All @@ -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 \
Expand All @@ -47,13 +51,25 @@ 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:
files: |
bin/hap-*
LICENSE
draft: true

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
Expand Down
35 changes: 29 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

LABEL maintainer="Cristhian Motoche <[email protected]>"

# 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"]
Loading