Skip to content

Instantly share code, notes, and snippets.

@samsulmaarif
Last active July 14, 2020 07:55
Show Gist options
  • Save samsulmaarif/71e3282609ce261f5460222ec3dba5c3 to your computer and use it in GitHub Desktop.
Save samsulmaarif/71e3282609ce261f5460222ec3dba5c3 to your computer and use it in GitHub Desktop.
FROM node:12-alpine as build
# create app Directory
RUN mkdir /app
WORKDIR /app
ENV NUXT_TELEMETRY_DISABLED 1
ENV NODE_OPTIONS "--max_old_space_size=4096"
COPY . /app
COPY .env.staging /app/.env
RUN apk add --no-cache curl git && cd /tmp && \
curl -#L https://github.com/tj/node-prune/releases/download/v1.0.1/node-prune_1.0.1_linux_amd64.tar.gz | tar -xvzf- && \
mv -v node-prune /usr/local/bin && rm -rvf *
RUN npm install && \
npm run build && \
node-prune
FROM node:12-alpine
COPY --from=build /app /app
WORKDIR /app
VOLUME /app
RUN apk add --no-cache nginx supervisor && \
addgroup -S www && \
adduser -S -D -H -h /app -s /bin/sh -G www -g www www && \
mkdir -p /var/run/nginx/ && \
mkdir -p /var/log/nginx/ && \
mkdir -p /app/log/ && \
touch /var/run/nginx/nginx.pid && \
wget https://gist.githubusercontent.com/samsulmaarif/d67851065a05fd2f37c147a732488716/raw/nginx-docker.conf -O /etc/nginx/nginx.conf && \
chown -Rf www:www /var/run/nginx && \
chown -Rf www:www /var/lib/nginx && \
chown -Rf www:www /var/log/nginx && \
chown -Rf www:www /etc/nginx && \
chown -Rf www:www /app && \
cp /app/deploy/supervisord.conf /etc/supervisord.conf
ENV NODE_ENV production
ENV NUXT_HOST 0.0.0.0
ENV NUXT_PORT 4000
EXPOSE 4000
EXPOSE 80
ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf
FROM webdevops/toolbox AS baselayout
RUN mkdir -p \
/baselayout/sbin \
/baselayout/usr/local/bin \
# Baselayout scripts
&& wget -O /tmp/baselayout-install.sh https://raw.githubusercontent.com/webdevops/Docker-Image-Baselayout/master/install.sh \
&& sh /tmp/baselayout-install.sh /baselayout \
## Install go-replace
&& wget -O "/baselayout/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-64-linux" \
&& chmod +x "/baselayout/usr/local/bin/go-replace" \
&& "/baselayout/usr/local/bin/go-replace" --version \
# Install gosu
&& wget -O "/baselayout/sbin/gosu" "https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64" \
&& wget -O "/tmp/gosu.asc" "https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /tmp/gosu.asc "/baselayout/sbin/gosu" \
&& rm -rf "$GNUPGHOME" /tmp/gosu.asc \
&& chmod +x "/baselayout/sbin/gosu" \
&& "/baselayout/sbin/gosu" nobody true
FROM php:7.4-fpm-alpine
ENV TERM="xterm" \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8"
# Baselayout copy (from staged image)
COPY --from=baselayout /baselayout /
#COPY conf/ /opt/docker/
RUN set -x \
# Init bootstrap
# Add community
&& echo https://dl-4.alpinelinux.org/alpine/v3.11/community/ >> /etc/apk/repositories \
# System update
&& /usr/local/bin/apk-upgrade \
# Install base stuff
&& apk-install \
bash \
ca-certificates \
openssl \
&& update-ca-certificates \
&& /usr/local/bin/generate-dockerimage-info \
## Fix su execution (eg for tests)
&& mkdir -p /etc/pam.d/ \
&& echo 'auth sufficient pam_rootok.so' >> /etc/pam.d/su \
&& docker-run-bootstrap \
&& docker-image-cleanup
RUN set -x \
# Install services
#&& chmod +x /opt/docker/bin/* \
&& apk-install \
supervisor \
wget \
curl \
vim \
sed \
tzdata \
busybox-suid \
apache2 \
apache2-ctl \
apache2-utils \
apache2-proxy \
apache2-ssl \
bash \
ca-certificates \
openssl \
zip \
unzip \
bzip2 \
drill \
ldns \
openssh-client \
rsync \
patch \
git \
shadow \
imagemagick \
graphicsmagick \
ghostscript \
jpegoptim \
pngcrush \
optipng \
pngquant \
vips \
rabbitmq-c \
c-client \
# Libraries
libldap \
icu-libs \
libintl \
libpq \
libxslt \
libzip \
libmemcached \
yaml \
&& chmod +s /sbin/gosu \
&& update-ca-certificates \
&& /usr/local/bin/generate-dockerimage-info \
## Fix su execution (eg for tests)
&& mkdir -p /etc/pam.d/ \
&& echo 'auth sufficient pam_rootok.so' >> /etc/pam.d/su \
# Fix issue with module loading order of lbmethod_* (see https://serverfault.com/questions/922573/apache2-fails-to-start-after-recent-update-to-2-4-34-no-clue-why)
&& sed -i '2,5{H;d}; ${p;x;s/^\n//}' /etc/apache2/conf.d/proxy.conf \
&& sed -ri ' \
s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
' /etc/apache2/httpd.conf \
&& chmod +s /sbin/gosu \
# Build dependencies
&& apk add --virtual .build-deps \
autoconf \
g++ \
make \
libtool \
pcre-dev \
gettext-dev \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
vips-dev \
krb5-dev \
openssl-dev \
imap-dev \
imagemagick-dev \
rabbitmq-c-dev \
openldap-dev \
icu-dev \
postgresql-dev \
libxml2-dev \
ldb-dev \
pcre-dev \
libxslt-dev \
libzip-dev \
libmemcached-dev \
yaml-dev \
# Install guetzli
&& wget https://github.com/google/guetzli/archive/master.zip \
&& unzip master.zip \
&& make -C guetzli-master \
&& cp guetzli-master/bin/Release/guetzli /usr/local/bin/ \
&& rm -rf master.zip guetzli-master \
# https://github.com/docker-library/php/issues/240
&& apk add gnu-libiconv --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ --allow-untrusted \
# Install new version of ICU
&& curl -sS -o /tmp/icu.tar.gz -L https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.tgz \
&& tar -zxf /tmp/icu.tar.gz -C /tmp && cd /tmp/icu/source && ./configure --prefix=/usr/local && make && make install && cd / && rm -rf /tmp/icu* \
# Install extensions
&& PKG_CONFIG_PATH=/usr/local docker-php-ext-configure intl \
&& docker-php-ext-configure gd --with-jpeg --with-freetype --with-webp \
&& docker-php-ext-configure ldap \
&& PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install \
bcmath \
bz2 \
calendar \
exif \
ffi \
intl \
gettext \
ldap \
mysqli \
imap \
pcntl \
pdo_mysql \
pdo_pgsql \
pgsql \
soap \
sockets \
tokenizer \
sysvmsg \
sysvsem \
sysvshm \
shmop \
xmlrpc \
xsl \
zip \
gd \
gettext \
opcache \
# Install extensions for PHP 7.x
&& pecl install apcu \
# Memcached for 7.3 can currently only be built from master
&& MEMCACHED="`mktemp -d`" \
&& curl -skL https://github.com/php-memcached-dev/php-memcached/archive/master.tar.gz | tar zxf - --strip-components 1 -C $MEMCACHED \
&& docker-php-ext-configure $MEMCACHED \
&& docker-php-ext-install $MEMCACHED \
&& rm -rf $MEMCACHED \
# Install vips (only works with PHP >= 7.0)
&& printf "\n" | pecl install vips \
&& pecl install redis \
&& pecl install mongodb \
&& pecl install imagick \
&& pecl install amqp \
&& pecl install yaml \
&& docker-php-ext-enable \
apcu \
redis \
imagick \
mongodb \
amqp \
vips \
yaml \
# Uninstall dev and header packages
&& apk del -f --purge .build-deps \
#&& rm -f /usr/local/etc/php-fpm.d/zz-docker.conf \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \
&& docker-run-bootstrap \
&& docker-image-cleanup
EXPOSE 80 9000
CMD ["supervisord"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment