From 809f379c0d7566be25f00274b412530078d94b1e Mon Sep 17 00:00:00 2001
From: Bruce Flynn <brucef@ssec.wisc.edu>
Date: Wed, 20 Nov 2019 15:03:37 +0000
Subject: [PATCH] ci tweaks

---
 .dockerignore      |  7 +++++++
 .gitlab-ci.yml     |  6 ++++--
 tests/Dockerfile   | 29 +++++++++++++++++++++++++++++
 tests/run_ci.sh    |  3 ---
 tests/run_tests.sh | 21 +++++++++++++++++++++
 5 files changed, 61 insertions(+), 5 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 tests/Dockerfile
 delete mode 100755 tests/run_ci.sh
 create mode 100755 tests/run_tests.sh

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..bc71a10
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,7 @@
+build
+dist
+*.egg-info
+.eggs
+.pytest_cache
+./tests/fixtures/*
+./tests/__pycache__
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 84fb63b..235f682 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,13 +1,15 @@
 test-py2:
   stage: test
+  tags: ["docker", "shell"]
   script:
-    - ./tests/run_ci.sh 2
+    - ./tests/run_tests.sh 2
 
 
 test-py3:
   stage: test
+  tags: ["docker", "shell"]
   script:
-    - ./tests/run_ci.sh 3
+    - ./tests/run_tests.sh 3
 
 sdist:
   stage: deploy
diff --git a/tests/Dockerfile b/tests/Dockerfile
new file mode 100644
index 0000000..4b6b1d7
--- /dev/null
+++ b/tests/Dockerfile
@@ -0,0 +1,29 @@
+FROM debian:bullseye-slim
+
+ARG pytag="3"
+
+# Install basic system/python requirements
+RUN apt-get -qq update && apt-get -qq install \
+        gcc \
+        git \
+        python${pytag}-dev \
+        python${pytag}-minimal \
+        python${pytag}-pip \
+        python${pytag}-setuptools && \
+    apt-get clean -y && \
+    rm -rf /var/lib/apt/lists/*
+
+# Install basic system/python requirements
+RUN apt-get -qq update && apt-get -qq install \
+        postgresql-client && \
+    apt-get clean -y && \
+    rm -rf /var/lib/apt/lists/*
+
+ENV PIP_TRUSTED_HOST "iweb1.sips"
+ENV PIP_NO_CACHE_DIR "false"
+ENV LC_ALL C.UTF-8
+ENV LANG C.UTF-8
+
+WORKDIR /code
+COPY . .
+RUN pip${pytag} install -i https://iweb1.sips/eggs --trusted-host=iweb1.sips -e ".[testing]"
diff --git a/tests/run_ci.sh b/tests/run_ci.sh
deleted file mode 100755
index a9a4dad..0000000
--- a/tests/run_ci.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-ver=${1:-3}
-docker run --rm -v $PWD:/code -w /code python:${ver} /code/tests/run.sh
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..119b813
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+set -e
+ver=$1
+[[ ! "$ver" =~ (2|3) ]] && echo "Must provided 2 or 3 as python version" && exit 1
+
+tag=$ver
+if [[ $ver == 2 ]]; then
+    tag=""
+fi
+
+image=edosl0util${ver}
+
+docker build -t ${image} -f tests/Dockerfile --build-arg=pytag=${tag} .
+docker run \
+    -e PYTHONDONTWRITEBYTECODE=1 \
+    -e HOME=/code \
+    -v $PWD:/code \
+    -u $(id -u):$(id -g) \
+    -w /code \
+    ${image} \
+    py.test -xv
-- 
GitLab