diff options
| -rw-r--r-- | .gitlab-ci.yml | 7 | ||||
| -rw-r--r-- | Dockerfile | 18 | ||||
| -rw-r--r-- | docker/Dockerfile.base | 25 | ||||
| -rw-r--r-- | docker/base.Dockerfile | 17 | ||||
| -rw-r--r-- | docker/ci.Dockerfile | 23 | ||||
| -rw-r--r-- | scripts/deploy-ci.sh | 23 | 
6 files changed, 47 insertions, 66 deletions
| diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93253cc5..7e026ce6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,13 @@  build: +    image: docker +    tags: docker +    only: +        - master      script: -        - docker build -t "gitlab_pysite_$CI_JOB_ID" +        - scripts/deploy-ci.sh  lint: +    image: pythondiscord/django-site-ci:latest      script:          - pipenv install --system --dev          - flake8 @@ -1,17 +1 @@ -FROM python:3.7-alpine - -RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev -RUN python3 -m pip install pipenv - -ENV PIPENV_HIDE_EMOJIS=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_MAX_SUBPROCESS=2 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_VENV_IN_PROJECT=1 - -COPY . /app -WORKDIR /app - -RUN pipenv install --deploy --system - -CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:4000", "pysite:wsgi"]
\ No newline at end of file +FROM pythondiscord/django-site-ci:latest diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base deleted file mode 100644 index 7119d770..00000000 --- a/docker/Dockerfile.base +++ /dev/null @@ -1,25 +0,0 @@ -FROM python:3.6-alpine3.7 - -RUN apk add --update tini -RUN apk add --update git -RUN apk add --update build-base -RUN apk add --update gcc -RUN apk add --update cmake -RUN apk add --update autoconf -RUN apk add --update automake -RUN apk add --update libtool - -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -RUN pip install pipenv - -RUN mkdir -p /site -COPY Pipfile /site -COPY Pipfile.lock /site -WORKDIR /site -ENV PYTHONPATH=/site - -RUN pipenv sync diff --git a/docker/base.Dockerfile b/docker/base.Dockerfile new file mode 100644 index 00000000..7252598d --- /dev/null +++ b/docker/base.Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.7-alpine + +RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev +RUN python3 -m pip install pipenv + +ENV PIPENV_HIDE_EMOJIS=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_MAX_SUBPROCESS=2 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_VENV_IN_PROJECT=1 + +COPY . /app +WORKDIR /app + +RUN pipenv install --deploy --system + +CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:4000", "pysite:wsgi"] diff --git a/docker/ci.Dockerfile b/docker/ci.Dockerfile deleted file mode 100644 index 0153696a..00000000 --- a/docker/ci.Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM python:3.6-alpine3.7 - -# Install base packages -RUN apk add --update autoconf automake \ -                     build-base \ -                     cmake curl \ -                     docker \ -                     gcc git \ -                     libtool \ -                     nodejs nodejs-npm \ -                     ruby ruby-dev ruby-irb ruby-rdoc \ -                     tini - -# Set up env vars -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -# Install toolchain -RUN pip install pipenv -RUN gem install scss_lint -RUN npm install -g eslint gulp-cli diff --git a/scripts/deploy-ci.sh b/scripts/deploy-ci.sh new file mode 100644 index 00000000..1bf8ce00 --- /dev/null +++ b/scripts/deploy-ci.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Build and deploy on master branch +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/base.Dockerfile | wc -l) + +    if [ $changed_lines != '0' ]; then +      echo "base.Dockerfile was changed" + +      echo "Building CI container" +      docker build -t pythondiscord/django-site-ci:latest -f docker/base.Dockerfile . + +      echo "Pushing image to Docker Hub" +      docker push pythondiscord/django-site-ci:latest +    else +      echo "base.Dockerfile was not changed, not building" +    fi +else +    echo "Skipping CI Docker build" +fi | 
