Skip to content

Commit

Permalink
optimize dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Jan 5, 2025
1 parent f4d71bd commit 6d1402a
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
ARG ANONADDY_VERSION=1.3.0
ARG ALPINE_VERSION=3.21

FROM crazymax/yasu:latest AS yasu
FROM crazymax/alpine-s6:${ALPINE_VERSION}-2.2.0.3
FROM --platform=$BUILDPLATFORM scratch AS src
ARG ANONADDY_VERSION
ADD "https://github.com/anonaddy/anonaddy.git#v${ANONADDY_VERSION}" .

COPY --from=yasu / /
FROM crazymax/alpine-s6:${ALPINE_VERSION}-2.2.0.3 AS base
COPY --from=crazymax/yasu:latest / /
RUN apk --no-cache add \
bash \
ca-certificates \
Expand Down Expand Up @@ -70,45 +72,37 @@ RUN apk --no-cache add \
&& echo "extension=gnupg.so" > /etc/php83/conf.d/60_gnupg.ini \
&& pecl83 install mailparse \
&& echo "extension=mailparse.so" > /etc/php83/conf.d/60_mailparse.ini \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& apk del build-dependencies \
&& rm -rf /tmp/* /var/www/*

FROM base AS build
RUN apk --no-cache add nodejs npm
WORKDIR /var/www/anonaddy
COPY --from=src / .
ARG ANONADDY_VERSION
RUN <<EOT
set -ex
composer install --optimize-autoloader --no-dev --no-interaction --no-ansi --ignore-platform-req=php-64bit
npm ci --ignore-scripts
APP_URL=https://addy-sh.test npm run production
npm prune --production
rm -rf /var/www/anonaddy/node_modules
chown -R nobody:nogroup /var/www/anonaddy
EOT

FROM base
COPY --from=build /var/www/anonaddy /var/www/anonaddy
ARG ANONADDY_VERSION
ENV ANONADDY_VERSION=$ANONADDY_VERSION \
S6_BEHAVIOUR_IF_STAGE2_FAILS="2" \
SOCKLOG_TIMESTAMP_FORMAT="" \
TZ="UTC" \
PUID="1000" \
PGID="1000"

WORKDIR /var/www/anonaddy
RUN apk --no-cache add -t build-dependencies \
git \
nodejs \
npm \
&& node --version \
&& npm --version \
&& addgroup -g ${PGID} anonaddy \
RUN addgroup -g ${PGID} anonaddy \
&& adduser -D -h /var/www/anonaddy -u ${PUID} -G anonaddy -s /bin/sh -D anonaddy \
&& addgroup anonaddy mail \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& git config --global --add safe.directory /var/www/anonaddy \
&& git init . && git remote add origin "https://github.com/anonaddy/anonaddy.git" \
&& git fetch --depth 1 origin "v${ANONADDY_VERSION}" && git checkout -q FETCH_HEAD \
&& composer install --optimize-autoloader --no-dev --no-interaction --no-ansi --ignore-platform-req=php-64bit \
&& chown -R anonaddy:anonaddy /var/www/anonaddy \
&& npm ci --ignore-scripts \
&& APP_URL=https://addy-sh.test npm run production \
&& npm prune --production \
&& chown -R nobody:nogroup /var/www/anonaddy \
&& apk del build-dependencies \
&& rm -rf /root/.composer \
/root/.config \
/root/.npm \
/var/www/anonaddy/.git \
/var/www/anonaddy/node_modules \
/tmp/*

&& addgroup anonaddy mail
COPY rootfs /

EXPOSE 25 8000 11334
Expand Down

0 comments on commit 6d1402a

Please sign in to comment.