Skip to content

Commit

Permalink
Refactor GitHub Actions draft workflow and Dockerfile to use upx to c…
Browse files Browse the repository at this point in the history
…ompress binary (#247)

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

* Update missing logic to move file to gh actions runner
  • Loading branch information
FranzGB authored Oct 18, 2024
1 parent 8161615 commit 159e7a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
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 <cmotoche@stackbuilders.com>

LABEL maintainer="Cristhian Motoche <cmotoche@stackbuilders.com>"

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

0 comments on commit 159e7a1

Please sign in to comment.