From c7d0e065dc094e09c6e2c2fa6f6d59df6ce27fb5 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Thu, 13 Sep 2018 18:02:36 +0000 Subject: use system flag instead of using venv --- .gitlab-ci.yml | 14 +++++++++----- Pipfile | 7 +++++-- docker/Dockerfile | 16 ---------------- docker/Dockerfile.base | 27 --------------------------- docker/base.Dockerfile | 27 +++++++++++++++++++++++++++ docker/bot.Dockerfile | 14 ++++++++++++++ scripts/deploy.sh | 10 +++++----- 7 files changed, 60 insertions(+), 55 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/Dockerfile.base create mode 100644 docker/base.Dockerfile create mode 100644 docker/bot.Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3edfb2bf8..f7aee8165 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,12 +1,14 @@ image: pythondiscord/bot-ci:latest variables: - PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/pipenv-cache" + PIPENV_CACHE_DIR: "/root/.cache/pipenv" + PIP_CACHE_DIR: "/root/.cache/pip" cache: paths: - - "$CI_PROJECT_DIR/pipenv-cache" - - "$CI_PROJECT_DIR/.venv" + - "/root/.cache/pip/" + - "/root/.cache/pipenv/" + - "/usr/local/lib/python3.6/site-packages/" stages: - test @@ -19,8 +21,10 @@ test: stage: test script: - - pipenv install --dev --deploy - - pipenv run lint + - ls /root/.cache/ + - pipenv install --dev --deploy --system + - python -m flake8 + - ls /root/.cache/ build: tags: diff --git a/Pipfile b/Pipfile index b6f7aeb6f..d3d315e6e 100644 --- a/Pipfile +++ b/Pipfile @@ -40,9 +40,12 @@ python_version = "3.6" [scripts] start = "python -m bot" lint = "python -m flake8" -build = "docker build -t pythondiscord/bot:latest -f docker/Dockerfile ." + +build = "docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile ." push = "docker push pythondiscord/bot:latest" -buildbase = "docker build -t pythondiscord/bot-base:latest -f docker/Dockerfile.base ." + +buildbase = "docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile ." pushbase = "docker push pythondiscord/bot-base:latest" + buildci = "docker build -t pythondiscord/bot-ci:latest -f docker/ci.Dockerfile ." pushci = "docker push pythondiscord/bot-ci:latest" diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 2db1ee24a..000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM pythondiscord/bot-base:latest - -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -RUN pip install pipenv - -COPY . /bot -WORKDIR /bot - -RUN pipenv sync - -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["pipenv", "run", "start"] diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base deleted file mode 100644 index 2f6929e0d..000000000 --- a/docker/Dockerfile.base +++ /dev/null @@ -1,27 +0,0 @@ -FROM python:3.6-alpine3.7 - -RUN apk add --update tini -RUN apk add --update build-base -RUN apk add --update libffi-dev -RUN apk add --update zlib -RUN apk add --update jpeg-dev -RUN apk add --update libxml2 libxml2-dev libxslt-dev -RUN apk add --update zlib-dev -RUN apk add --update freetype-dev - -RUN pip install pipenv - -RUN mkdir /bot -COPY Pipfile /bot -COPY Pipfile.lock /bot -WORKDIR /bot - -ENV LIBRARY_PATH=/lib:/usr/lib -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -RUN pipenv install - -# usage: FROM pythondiscord/bot-base:latest diff --git a/docker/base.Dockerfile b/docker/base.Dockerfile new file mode 100644 index 000000000..de2c68c13 --- /dev/null +++ b/docker/base.Dockerfile @@ -0,0 +1,27 @@ +FROM python:3.6-alpine3.7 + +RUN apk add --update tini +RUN apk add --update build-base +RUN apk add --update libffi-dev +RUN apk add --update zlib +RUN apk add --update jpeg-dev +RUN apk add --update libxml2 libxml2-dev libxslt-dev +RUN apk add --update zlib-dev +RUN apk add --update freetype-dev + +RUN pip install pipenv + +RUN mkdir /bot +COPY Pipfile /bot +COPY Pipfile.lock /bot +WORKDIR /bot + +ENV LIBRARY_PATH=/lib:/usr/lib +ENV PIPENV_VENV_IN_PROJECT=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_HIDE_EMOJIS=1 + +RUN pipenv install --deploy --system + +# usage: FROM pythondiscord/bot-base:latest diff --git a/docker/bot.Dockerfile b/docker/bot.Dockerfile new file mode 100644 index 000000000..4713e1f0e --- /dev/null +++ b/docker/bot.Dockerfile @@ -0,0 +1,14 @@ +FROM pythondiscord/bot-base:latest + +ENV PIPENV_VENV_IN_PROJECT=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_HIDE_EMOJIS=1 + +COPY . /bot +WORKDIR /bot + +RUN pipenv install --deploy --system + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["python", "-m", "bot"] diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 50ec87f59..070d0ec26 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -5,22 +5,22 @@ if [[ $CI_COMMIT_REF_SLUG == 'master' ]]; then echo "Connecting to docker hub" echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - changed_lines=$(git diff HEAD~1 HEAD docker/Dockerfile.base | wc -l) + changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then - echo "Dockerfile.base was changed" + echo "base.Dockerfile was changed" echo "Building bot base" - docker build -t pythondiscord/bot-base:latest -f docker/Dockerfile.base . + docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile . echo "Pushing image to Docker Hub" docker push pythondiscord/bot-base:latest else - echo "Dockerfile.base was not changed, not building" + echo "base.Dockerfile was not changed, not building" fi echo "Building image" - docker build -t pythondiscord/bot:latest -f docker/Dockerfile . + docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile . echo "Pushing image" docker push pythondiscord/bot:latest -- cgit v1.2.3