Skip to content

Commit

Permalink
Dockerfile updates (#1937)
Browse files Browse the repository at this point in the history
* Add docker build workflow
* Update onadata-uwsgi DockerFile
* Add an intermediate container to download optional packages
* Update docker compose file
* Bump docker image version to Ubuntu 20.04
* Silence linting error
  • Loading branch information
DavisRayM authored Nov 11, 2020
1 parent 18cfb5b commit 3390a99
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 32 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/docker-image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Docker Build Image

on:
release:
types:
- "released"

jobs:
main:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./docker/onadata-uwsgi
file: ./Dockerfile
platforms: linux/amd64
build-args: |
release_version=${{ steps.get_version.outputs.VERSION }}
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
onaio/onadata:latest
onaio/onadata:${{ steps.get_version.outputs.VERSION }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
90 changes: 58 additions & 32 deletions docker/onadata-uwsgi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
FROM ubuntu:18.04
FROM python:3.6 as intermediate

ENV DEBIAN_FRONTEND noninteractive
ENV PYTHONUNBUFFERED 1

ARG optional_packages
# Optional Argument; Used in cases where the optional
# packages require some sort of authentication i.e Private repositories on github
ARG ssh_private_key

# Create SSH Key file
RUN mkdir /root/.ssh/
RUN echo "${ssh_private_key}" > /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa

# Add github to accepted domains
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com > /root/.ssh/known_hosts

# Install optional requirements
# hadolint ignore=DL3013
RUN if [ -n "$optional_packages" ]; then pip install ${optional_packages} ; fi

FROM ubuntu:20.04
COPY --from=intermediate /usr/local/lib/python3.6/site-packages/ /usr/local/lib/python3.6/dist-packages/

ARG release_version=v2.4.1

Expand All @@ -11,36 +34,36 @@ ENV DJANGO_SETTINGS_MODULE onadata.settings.docker

# Install service dependencies
RUN apt-get update -q &&\
apt-get install -y --no-install-recommends software-properties-common=0.96.24.32.14 \
binutils=2.30-21ubuntu1~18.04.4 \
libproj-dev=4.9.3-2 \
gdal-bin=2.2.3+dfsg-2 \
memcached=1.5.6-0ubuntu1.2 \
libmemcached-dev=1.0.18-4.2ubuntu0.18.04.1 \
build-essential=12.4ubuntu1 \
python3.6=3.6.9-1~18.04ubuntu1.1 \
python3.6-dev=3.6.9-1~18.04ubuntu1.1 \
python3-pip=9.0.1-2.3~ubuntu1.18.04.2 \
python3-setuptools=39.0.1-2 \
git=1:2.17.1-1ubuntu0.7 \
libssl-dev=1.1.1-1ubuntu2.1~18.04.6 \
libpq-dev=10.14-0ubuntu0.18.04.1 \
gfortran=4:7.4.0-1ubuntu2.3 \
libatlas-base-dev=3.10.3-5 \
libjpeg-dev=8c-2ubuntu8 \
libxml2-dev=2.9.4+dfsg1-6.1ubuntu1.3 \
libxslt1-dev=1.1.29-5ubuntu0.2 \
zlib1g-dev=1:1.2.11.dfsg-0ubuntu2 \
ghostscript=9.26~dfsg+0-0ubuntu0.18.04.13 \
python-celery=4.1.0-2ubuntu1 \
python-sphinx=1.6.7-1ubuntu1 \
pkg-config=0.29.1-0ubuntu2 \
gcc=4:7.4.0-1ubuntu2.3 \
automake=1:1.15.1-3ubuntu2 \
libtool=2.4.6-2 \
openjdk-11-jre-headless=11.0.8+10-0ubuntu1~18.04.1 \
uwsgi=2.0.15-10.2ubuntu2.1 \
locales=2.27-3ubuntu1.2 && \
apt-get install -y --no-install-recommends software-properties-common \
binutils \
libproj-dev \
gdal-bin \
memcached \
libmemcached-dev \
build-essential \
python3.8 \
python3.8-dev \
python3-pip \
python3-setuptools \
git \
libssl-dev \
libpq-dev \
gfortran \
libatlas-base-dev \
libjpeg-dev \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
ghostscript \
python3-celery \
python3-sphinx \
pkg-config \
gcc \
automake \
libtool \
openjdk-11-jre-headless \
uwsgi \
locales && \
rm -rf /var/lib/apt/lists/*

# Generate and set en_US.UTF-8 locale
Expand All @@ -59,7 +82,8 @@ RUN useradd -m onadata

# Install service requirements
WORKDIR /srv/onadata
RUN python3 -m pip install -U pip && \
# hadolint ignore=DL3013
RUN python3 -m pip install --no-cache-dir -U pip && \
python3 -m pip install --no-cache-dir -r requirements/base.pip

# Compile API Docs
Expand All @@ -68,3 +92,5 @@ RUN make -C docs html
EXPOSE 8000

CMD ["/usr/local/bin/uwsgi", "--ini", "/uwsgi.ini"]

USER onadata

0 comments on commit 3390a99

Please sign in to comment.