Skip to content

Commit

Permalink
Migrate to multistage build and alpine 3.8 image base
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeacom committed Nov 30, 2018
1 parent f8e9e52 commit d3fc745
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
57 changes: 32 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
FROM python:3.7-slim-stretch
FROM python:3.7-alpine3.8 as base
FROM base as builder

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONVERBOSE 1
ARG PACKAGES="postgresql-libs libxml2 libxslt freetype libffi jpeg libmaxminddb"
ARG BUILD_DEPS="gcc g++ postgresql-dev libxml2-dev libxslt-dev freetype-dev libffi-dev jpeg-dev linux-headers autoconf automake libtool make dos2unix"

RUN mkdir /install
WORKDIR /install

RUN mkdir /code && \
apt-get update -y && \
apt-get install build-essential -y && \
apt-get install -y --no-install-recommends apt-utils && \
apt-get install -y --no-install-recommends tk-dev python3-tk pgtop libsecp256k1-dev libsecp256k1-0 gettext graphviz libgraphviz-dev wget git dos2unix gcc libc6-dev libc-dev libssl-dev make automake libtool autoconf pkg-config libffi-dev libgdal-dev gdal-bin libgdal20 python3-gdal ffmpeg libav-tools x264 x265 && \
pip install --upgrade pip wheel setuptools && \
pip3 install dumb-init psutil && \
rm -rf /var/lib/apt/lists/*

RUN git clone --recursive https://github.com/maxmind/libmaxminddb.git && \
cd libmaxminddb && \
./bootstrap && \
./configure && \
make && \
make check && \
make install && \
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf && \
ldconfig
# Install general dependencies.
RUN apk add --no-cache --update $PACKAGES && \
apk add --no-cache --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ vips && \
apk add --no-cache --update --virtual .builder $BUILD_DEPS

# GeoIP2 Data Files
RUN mkdir -p /usr/share/GeoIP/ && \
Expand All @@ -28,16 +23,28 @@ RUN mkdir -p /usr/share/GeoIP/ && \
gunzip GeoLite2-Country.mmdb.gz && \
mv *.mmdb /usr/share/GeoIP/

WORKDIR /code
# Upgrade package essentials.
RUN pip3 install --upgrade --install-option="--prefix=/install" pip setuptools wheel dumb-init pipenv


COPY requirements/ /code/
COPY app/ /code/app/
RUN pip3 install --upgrade --install-option="--prefix=/install" -r test.txt

RUN pip install -r test.txt
COPY bin/docker-command.bash /bin/docker-command.bash
RUN dos2unix /bin/docker-command.bash && \
apt-get purge -y --auto-remove dos2unix wget gcc libc6-dev libc-dev libssl-dev make automake libtool autoconf pkg-config libffi-dev apt-utils
RUN dos2unix /bin/docker-command.bash

# Switch to the base image.
FROM base
WORKDIR /code

RUN apt-get update && apt-get install -y libvips libvips-dev libmagickwand-dev
RUN apk add --no-cache --update $PACKAGES bash git && \
apk add --no-cache --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ vips

RUN mkdir -p /usr/share/GeoIP/
COPY --from=builder /install /usr/local
COPY --from=builder /usr/share/GeoIP /usr/share/GeoIP
COPY --from=builder /bin/docker-command.bash /bin/docker-command.bash
COPY app/ /code/app/

ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
CMD ["bash", "/bin/docker-command.bash"]
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ autotranslate: ## Automatically translate all untranslated entries for all LOCAL

build: ## Build the Gitcoin Web image.
@docker build \
--stream \
--pull \
--build-arg BUILD_DATETIME=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg "SHA1=${SHA1}" \
${VERSION:+--build-arg "VERSION=$VERSION"} \
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ services:
- PYTHONPATH=/code/app
env_file:
- app/app/.env
build: .
build:
context: .
dockerfile: Dockerfile
image: gitcoinco/web:latest
volumes:
- .:/code
Expand Down
2 changes: 1 addition & 1 deletion ops/images/job/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-alpine
FROM python:3.7-alpine3.8
# Specify label-schema specific arguments and labels.
ARG BUILD_DATE
ARG VCS_REF
Expand Down
4 changes: 2 additions & 2 deletions ops/images/kubectl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Build Image
FROM alpine:3.8 as alpine
ARG VERSION=v1.12.2
ARG VERSION=v1.12.3
WORKDIR /
RUN apk add -U --no-cache curl ca-certificates && \
curl -L "https://storage.googleapis.com/kubernetes-release/release/$VERSION/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl && \
chmod +x /usr/local/bin/kubectl
# Release Image
FROM scratch
ARG VERSION=v1.12.2
ARG VERSION=v1.12.3
ARG VCS_REF
ARG BUILD_DATE
COPY --from=alpine /usr/local/bin/kubectl /bin/kubectl
Expand Down
10 changes: 5 additions & 5 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-r base.txt
pytest==3.8.0
pytest==4.0.1
pytest-cov==2.6.0
pytest-isort==0.2.1
pytest-django==3.4.2
pytest-sugar==0.9.1
coverage==4.5.1
pytest-django==3.4.4
pytest-sugar==0.9.2
coverage==4.5.2
isort==4.3.4
responses==0.9.0
responses==0.10.4
requests_mock==1.5.2
django-test-plus==1.1.1
git+https://github.com/google/yapf.git#egg=yapf

0 comments on commit d3fc745

Please sign in to comment.