浏览代码

Convert Dockefile to Multi-Stage

Decrease Dockefile image from 1.46GB to 325MB. Speed up the build by leveraging Docker Multi-Stage technique and using python:3.7-slim-stretch as final image.
pull/192/head
Jason Kaltsikis 4 年前
父节点
当前提交
3d3b7e73fe
共有 1 个文件被更改,包括 37 次插入22 次删除
  1. +37
    -22
      Dockerfile.autobuild

+ 37
- 22
Dockerfile.autobuild 查看文件

@@ -5,13 +5,34 @@
# all of it's assets, there are more optimal ways to do this but this is the
# most friendly and has everything contained in a single instance.
#
# Authors: Isaac Bythewood
# Updated: Mar 29th, 2016
# Authors: Isaac Bythewood, Jason Kaltsikis
# Updated: May 2nd, 2020
# Require: Docker (http://www.docker.io/)
# -----------------------------------------------------------------------------

# Base system is the LTS version of Ubuntu.
FROM python:3.7-stretch
# Build static yarn file
FROM node:10.20.1-alpine3.11 as yarn-build

WORKDIR pinry-spa
COPY pinry-spa/package.json .
RUN yarn install
COPY pinry-spa .
RUN yarn build


# Required for other database options
FROM python:3.7-slim-stretch as base

RUN apt-get update \
&& apt-get -y install gcc default-libmysqlclient-dev
RUN pip --no-cache-dir install --user mysqlclient cx-Oracle


# Final image
FROM python:3.7-slim-stretch

WORKDIR pinry
RUN mkdir /data && chown -R www-data:www-data /data

RUN groupadd -g 2300 tmpgroup \
&& usermod -g tmpgroup www-data \
@@ -21,30 +42,24 @@ RUN groupadd -g 2300 tmpgroup \
&& usermod -u 1000 www-data \
&& groupdel tmpgroup

RUN mkdir /data
RUN chown -R www-data:www-data /data

# Install nginx
RUN apt-get update \
&& apt-get -y install nginx nginx-extras pwgen \
&& apt-get -y install nginx \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get autoclean

# required for other database options
RUN pip --no-cache-dir install pipenv gunicorn mysqlclient psycopg2 cx-Oracle

# COPY and start installation
COPY . /pinry

RUN cd /pinry \
&& pipenv install --three --system --clear
# Install Pipfile requirements
COPY Pipfile* ./
RUN pip install rcssmin --install-option="--without-c-extensions" \
&& pip install pipenv \
&& pipenv install --three --system --clear

# config nodejs
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n || exit
RUN bash n 10
RUN npm -g install yarn
# Copy from previous stages
COPY --from=yarn-build pinry-spa/dist /pinry/pinry-spa/dist
COPY --from=base /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH

# build frontend
RUN cd /pinry/pinry-spa/ && yarn install && yarn build
COPY . .

# Load in all of our config files.
ADD docker/nginx/nginx.conf /etc/nginx/nginx.conf


正在加载...
取消
保存