-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
32 lines (30 loc) · 1.23 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
ARG UPX_VERSION="3.96"
ARG TARGETOS TARGETARCH
RUN apk --update add --no-cache curl git; \
git clone --depth 1 https://github.com/pratikbalar/tarrer.git /src
WORKDIR /src
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /usr/local/bin/tarrer -trimpath -ldflags "-s -w"
RUN set -ex; \
version="${UPX_VERSION}"; \
if [[ ${TARGETARCH} == "386" ]]; then arch="i386"; \
elif [[ ${TARGETARCH} == "mips64le" ]]; then arch="mipsel"; \
elif [[ ${TARGETARCH} == "mips64" ]]; then arch="mips"; \
elif [[ ${TARGETARCH} == "ppc64le" ]]; then arch="powerpc64le"; \
else arch="${TARGETARCH}"; \
fi; \
tar="/upx-${version}-${arch}_${TARGETOS}.tar.xz\""; \
url="https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-${arch}_${TARGETOS}.tar.xz"; \
echo $url; \
echo $version; \
echo $tar; \
wget "$url" -O /tmp/upx.tar.xz; \
tarrer /tmp/upx.tar.xz /tmp/; \
cp "$(find /tmp/ -name 'upx' -type f)" /tmp/
FROM scratch
WORKDIR /app
COPY --from=builder /tmp/upx /usr/local/bin/upx
ENTRYPOINT ["/usr/local/bin/upx","-9"]
# remain linux/riscv64x,linux/s390x