tj / node-prune

Remove unnecessary files from node_modules (.md, .ts, ...)
MIT License
4.41k stars 130 forks source link

Support alpine image via gobinaries.com #64

Open TasukuUno opened 4 years ago

TasukuUno commented 4 years ago

I would like to run on alpine image of Docker by installing via gobinaries.com, but I got error message below:

/bin/sh: node-prune: not found

I think installation is complete, but the executable is not suitable for alpine environment. Is it possible for you to support this using GoReleaser?

reproduction

tj commented 4 years ago

hmm I imagine it should be linux/amd64, I'll boot up an Alpine container and see what's up, must not be detecting the env correctly

tj commented 4 years ago

sounds like you have to compile with musl-gcc for Alpine, I'll open an issue in my gobinaries.com repo (still closed source ATM)

williamoliveira commented 4 years ago

any progress or easy alternative?

tj commented 4 years ago

@williamoliveira not yet, haven't had time to work on it

williamoliveira commented 4 years ago

ok, I found an alternative, the yarn autoclean command

PacoDu commented 4 years ago

Current workaround using goreleaser (tested on node:14-alpine):

FROM node:14-alpine as builder

# Add dependencies
RUN apk add curl bash --no-cache

# Install node-prune
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin

# Build app
RUN npm install && (...)

# Run cleanup necessary dependencies 
RUN npm prune --production && node-prune

Unfortunately it will install v1.0.1 not 1.2.0

Dugong42 commented 2 years ago

The proposed workaround for alpine does not work anymore, as install.goreleaser.com has been removed as of 2022-05-18 https://goreleaser.com/deprecations/#godownloader

This worked fine for me :

FROM node:14-alpine as builder

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# Install node-prune
RUN wget -qO- https://gobinaries.com/tj/node-prune | ash -s

# ...

FYI, setting /bin/ash -eo pipefail allows RUN to detect if a command fails in a pipe chain. Otherwise it only fails if the last piped command fails.

diegomdrs commented 1 year ago

This worked for me:

FROM node:19-alpine as builder

RUN mkdir /app
WORKDIR /app

# node-prune
RUN wget -qO- https://gobinaries.com/tj/node-prune | sh

ENV NODE_ENV production

COPY . .

RUN npm install

...