-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor Dockerfile making images more size efficient (#236)
- Loading branch information
Showing
1 changed file
with
29 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,43 @@ | ||
FROM alpine:3.16.0 | ||
LABEL maintainer="Miraculous Owonubi <[email protected]>" \ | ||
name="freyrcli" \ | ||
version="latest" \ | ||
tag="alpine" | ||
FROM node:alpine as installer | ||
|
||
RUN printf '#!/usr/bin/env sh\necho "Python 3.0.0"\n' > /usr/bin/python && chmod +x /usr/bin/python | ||
# ^-- Workaround to bypass youtube-dl-exec's postinstall check for a supported python installation | ||
COPY . /freyr | ||
WORKDIR /freyr | ||
RUN npm ci --only=production | ||
|
||
FROM golang:alpine as prep | ||
|
||
# Install dependencies and clean cache | ||
# hadolint ignore=DL3018 | ||
RUN apk add \ | ||
--no-cache \ | ||
git \ | ||
libstdc++ \ | ||
npm \ | ||
nodejs \ | ||
python3 \ | ||
ffmpeg \ | ||
bash \ | ||
which \ | ||
cmake \ | ||
gcc \ | ||
g++ \ | ||
make \ | ||
linux-headers \ | ||
&& ln /usr/bin/python3 /usr/bin/python \ | ||
&& find /usr/lib/python3* -type d -name __pycache__ -exec rm -r {} \+ | ||
RUN apk add --no-cache git g++ make cmake linux-headers | ||
COPY --from=installer /freyr/node_modules /freyr/node_modules | ||
RUN go install github.com/tj/node-prune@1159d4c \ | ||
&& node-prune /freyr/node_modules \ | ||
&& git clone --branch 20210715.151551.e7ad03a --depth 1 https://github.com/wez/atomicparsley /atomicparsley \ | ||
&& cmake -S /atomicparsley -B /atomicparsley \ | ||
&& cmake --build /atomicparsley --config Release | ||
|
||
# install atomicparsley | ||
RUN mkdir /bins \ | ||
&& git clone --branch 20210715.151551.e7ad03a --depth 1 https://github.com/wez/atomicparsley \ | ||
&& cmake -S atomicparsley -B atomicparsley \ | ||
&& cmake --build atomicparsley --config Release \ | ||
&& mv atomicparsley/AtomicParsley /bins \ | ||
&& rm -r atomicparsley | ||
ENV PATH "/bins:$PATH" | ||
FROM alpine:3.16.0 as base | ||
|
||
# hadolint ignore=DL3018 | ||
RUN apk add --no-cache nodejs ffmpeg python3 libstdc++ | ||
COPY --from=installer /freyr /freyr | ||
RUN rm -rf /freyr/node_modules | ||
COPY --from=prep /freyr/node_modules /freyr/node_modules | ||
COPY --from=prep /atomicparsley/AtomicParsley /bin/AtomicParsley | ||
|
||
# Create freyr user and group | ||
# hadolint ignore=DL4006 | ||
RUN addgroup -g 1000 freyr \ | ||
RUN addgroup -g 1001 freyr \ | ||
&& adduser -DG freyr freyr \ | ||
&& echo freyr:freyr | chpasswd | ||
|
||
# Stage and install freyr | ||
COPY . /freyr | ||
WORKDIR /freyr | ||
RUN npm ci \ | ||
&& npm link \ | ||
&& npm cache clean --force \ | ||
&& echo freyr:freyr | chpasswd \ | ||
&& ln -s /freyr/cli.js /bin/freyr \ | ||
&& mkdir /data \ | ||
&& chown -R freyr:freyr /freyr /data | ||
|
||
# Set and mount workdir | ||
WORKDIR /freyr | ||
USER freyr | ||
|
||
WORKDIR /data | ||
VOLUME /data | ||
|
||
# Set entrypoint and default cmd | ||
ENTRYPOINT ["freyr"] | ||
CMD ["--help"] | ||
|
||
# BUILD | ||
# > git clone https://github.com/miraclx/freyr-js freyr | ||
# > docker build -t freyr:alpine freyr | ||
|
||
# LAUNCH (freyr) | ||
# > docker run --rm -v $PWD:/data freyr:alpine | ||
# LAUNCH (bash) | ||
# > docker run -itv $PWD:/data --entrypoint bash freyr:alpine |