From 48f0e2df73a0273c2a0485534910a455807448c6 Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Thu, 17 Sep 2020 14:48:49 +0200 Subject: [PATCH] build slim image --- .travis.yml | 102 ++++++++++++++++++++++++++++------------- Dockerfile | 13 +++++- scripts/docker_push.sh | 2 +- 3 files changed, 83 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5e3b142..49bbbc21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,79 @@ language: shell - -env: - - IMAGE_NAME="${DOCKER_ORG}/geospaas" - services: - docker -if: type != pull_request +# Environment variables defined as part of the Travis CI repository configuration are: +# - DOCKER_ORG: the docker hub organization (or user) to which the image will be pushed +# - DOCKER_USER: the docker hub user used to log in to the docker hub +# - DOCKER_PASS: the password of this user +# - PYPI_TOKEN: the token associated to the pypi account for deployment. More information can be found here: https://pypi.org/help/#apitoken +# - COVERALLS_REPO_TOKEN: authentication token for coveralls.io -install: - - docker pull $IMAGE_NAME || true - - docker build --cache-from $IMAGE_NAME . -t $IMAGE_NAME +env: + global: + - IMAGE_NAME="${DOCKER_ORG}/geospaas" -script: - - > - docker run --rm - -e COVERALLS_REPO_TOKEN - -e "TRAVIS=true" - -e TRAVIS_JOB_ID - -e TRAVIS_BRANCH - -e TRAVIS_PULL_REQUEST - -v "$(pwd):/src" - $IMAGE_NAME - bash -c "source /opt/conda/bin/activate && coverage run --omit=geospaas/nansat_ingestor/tests/*,geospaas/catalog/tests/*,geospaas/vocabularies/tests/* runtests.py && coveralls" +jobs: + include: + - stage: 'Unit tests' + if: type = push + env: + - TEST_IMAGE="${IMAGE_NAME}:latest" + install: + - docker pull "${TEST_IMAGE}" || true + script: + - > + docker run --rm + -e COVERALLS_REPO_TOKEN + -e "TRAVIS=true" + -e TRAVIS_JOB_ID + -e TRAVIS_BRANCH + -e TRAVIS_PULL_REQUEST + -v "$(pwd):/src" + ${TEST_IMAGE} + bash -c "source /opt/conda/bin/activate && coverage run --omit=geospaas/nansat_ingestor/tests/*,geospaas/catalog/tests/*,geospaas/vocabularies/tests/* runtests.py && coveralls" + deploy: + - provider: pypi + user: "__token__" + password: "${PYPI_TOKEN}" + on: + tags: true -before_deploy: - - docker login -u $DOCKER_USER -p $DOCKER_PASS + - stage: 'Build Docker images' + name: 'Build standard image' + if: type = push + env: + - TAG='latest' + install: + - docker pull "${IMAGE_NAME}:${TAG}" || true + - > + docker build . + --cache-from "${IMAGE_NAME}:${TAG}" + --build-arg BASE_IMAGE="nansencenter/nansat:${TAG}" + -t "${IMAGE_NAME}:tmp" + before_deploy: + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" + deploy: + - provider: script + on: + tags: true + script: /bin/bash scripts/docker_push.sh $TRAVIS_TAG latest -deploy: - - provider: script - on: - tags: true - script: /bin/bash scripts/docker_push.sh $TRAVIS_TAG latest - - provider: pypi - user: "__token__" - password: "${PYPI_TOKEN}" - on: - tags: true + - name: 'Build slim image' + if: type = push + env: + - TAG='latest-slim' + install: + - docker pull "${IMAGE_NAME}:${TAG}" || true + - > + docker build . + --cache-from "${IMAGE_NAME}:${TAG}" + --build-arg BASE_IMAGE="nansencenter/nansat:${TAG}" + -t "${IMAGE_NAME}:tmp" + before_deploy: + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" + deploy: + - provider: script + on: + tags: true + script: /bin/bash scripts/docker_push.sh "${TRAVIS_TAG}-slim" 'latest-slim' diff --git a/Dockerfile b/Dockerfile index 6e6a7650..813255b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,17 @@ # Initialize from docker image with Python, libraries and Nansat -FROM nansencenter/nansat:latest +ARG BASE_IMAGE='nansencenter/nansat:latest' +FROM ${BASE_IMAGE} LABEL purpose="Running and developing Django-Geo-SpaaS" ENV PYTHONUNBUFFERED=1 # Install Django -RUN pip install \ +RUN apt update \ +&& apt install -y \ + # psycopg2 dependencies + g++ \ + libpq5 \ + libpq-dev \ +&& pip install \ bs4 \ coverage \ django==3.0.6 \ @@ -12,6 +19,8 @@ RUN pip install \ django-leaflet==0.26.0 \ psycopg2==2.8.4 \ thredds_crawler==1.5.4 \ +&& apt remove -y g++ && apt autoremove -y \ +&& apt clean && rm -rf /var/lib/apt/lists/* \ && echo "alias ll='ls -lh'" >> /root/.bashrc # install Geo-SPaaS diff --git a/scripts/docker_push.sh b/scripts/docker_push.sh index 694b5e08..eba56fb8 100644 --- a/scripts/docker_push.sh +++ b/scripts/docker_push.sh @@ -1,4 +1,4 @@ for tag in $*;do - docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${tag}" + docker tag "${IMAGE_NAME}:tmp" "${IMAGE_NAME}:${tag}" docker push "${IMAGE_NAME}:${tag}" done