From b03685fb5c430cf836abd7f9b184a2a094f29819 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 18 Sep 2019 04:03:18 +1000 Subject: Refine Dockerfiles --- docker-compose.yml | 2 +- docker/app/Dockerfile | 41 +++++++------------------------------ docker/app/Dockerfile.local | 49 --------------------------------------------- docker/app/local.Dockerfile | 23 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 84 deletions(-) delete mode 100644 docker/app/Dockerfile.local create mode 100644 docker/app/local.Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index d415340b..0a8e6bcd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,7 @@ services: web: build: context: . - dockerfile: docker/app/Dockerfile.local + dockerfile: docker/app/local.Dockerfile command: docker/app/scripts/migrate_and_serve.sh ports: - "127.0.0.1:8000:8000" diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 903e7dc6..8378ceb9 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -5,46 +5,19 @@ STOPSIGNAL SIGQUIT ARG EXTRAS=deploy # Create a user. -RUN adduser \ - --disabled-login \ - --no-create-home \ - --uid 1500 \ - pysite +RUN useradd --system --shell /bin/false --uid 1500 pysite # Install prerequisites needed to complete the dependency installation. -RUN apt-get update -y \ - && \ - apt-get install --no-install-recommends -y \ - gcc \ - libc-dev \ - libpq-dev \ - git \ - && \ - apt-get clean \ - && \ - rm -rf /var/lib/apt/lists/* +RUN install_packages git uwsgi -# Set up the working directory. +# Copy the project files into the working directory. WORKDIR /app -COPY Pipfile Pipfile.lock /app/ - -# Pip install the stuff we'll need. -RUN rm -r /opt/bitnami/python/lib/python3.*/site-packages/setuptools* && \ - pip install --no-cache-dir -U setuptools -RUN python3 -m pip install pipenv \ - && python3 -m pipenv install --system --deploy \ - && pip install uwsgi==2.0.18 - -# Copy everything into the docker environment. COPY . . -# RUN SECRET_KEY=placeholder DATABASE_URL=sqlite:// python3 manage.py collectstatic --no-input --clear --verbosity 0 - -# Remove the prerequisites, dependency installation is now complete. -RUN apt-get purge -y \ - gcc \ - libc-dev \ - libpq-dev +# Update setuptools by removing egg first, add other dependencies +RUN rm -r /opt/bitnami/python/lib/python3.*/site-packages/setuptools* && \ + pip install --no-cache-dir -U setuptools pipenv +RUN pipenv install --system --deploy # Migrate, collect and start the app. RUN chmod +x /app/docker/app/scripts/migrate.sh diff --git a/docker/app/Dockerfile.local b/docker/app/Dockerfile.local deleted file mode 100644 index c332c757..00000000 --- a/docker/app/Dockerfile.local +++ /dev/null @@ -1,49 +0,0 @@ -FROM bitnami/python:3.7-prod - -# I have no idea what this does. -STOPSIGNAL SIGQUIT -ARG EXTRAS=deploy - -# Create a user. -RUN adduser \ - --disabled-login \ - --no-create-home \ - --uid 1500 \ - pysite - -# Install prerequisites needed to complete the dependency installation. -RUN apt-get update -y \ - && \ - apt-get install --no-install-recommends -y \ - gcc \ - libc-dev \ - libpq-dev \ - git \ - && \ - apt-get clean \ - && \ - rm -rf /var/lib/apt/lists/* - -# Set up the working directory. -WORKDIR /app -COPY Pipfile Pipfile.lock /app/ - -# Pip install the stuff we'll need. -RUN rm -r /opt/bitnami/python/lib/python3.*/site-packages/setuptools* && \ - pip install --no-cache-dir -U setuptools -RUN python3 -m pip install pipenv \ - && python3 -m pipenv install --system --deploy \ - && pip install uwsgi==2.0.18 - -# Copy everything into the docker environment. -COPY . . - -RUN SECRET_KEY=placeholder DATABASE_URL=sqlite:// python3 manage.py collectstatic --no-input --clear --verbosity 0 - -# Remove the prerequisites, dependency installation is now complete. -RUN apt-get purge -y \ - gcc \ - libc-dev \ - libpq-dev - -CMD ["uwsgi", "--ini", "docker/app/uwsgi.ini"] diff --git a/docker/app/local.Dockerfile b/docker/app/local.Dockerfile new file mode 100644 index 00000000..2edf4794 --- /dev/null +++ b/docker/app/local.Dockerfile @@ -0,0 +1,23 @@ +FROM bitnami/python:3.7-prod + +STOPSIGNAL SIGQUIT +ARG EXTRAS=deploy + +# Create a user. +RUN useradd --system --shell /bin/false --uid 1500 pysite + +# Install prerequisites needed to complete the dependency installation. +RUN install_packages git uwsgi + +# Copy the project files into the working directory. +WORKDIR /app +COPY . . + +# Update setuptools by removing egg first, add other dependencies +RUN rm -r /opt/bitnami/python/lib/python3.*/site-packages/setuptools* && \ + pip install --no-cache-dir -U setuptools pipenv +RUN pipenv install --system --deploy + +RUN SECRET_KEY=placeholder DATABASE_URL=sqlite:// python3 manage.py collectstatic --no-input --clear --verbosity 0 + +CMD ["uwsgi", "--ini", "docker/app/uwsgi.ini"] -- cgit v1.2.3 From 9ce9b95df915b6820ea7bcd5a7986ef5ea6da9aa Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 18 Sep 2019 05:47:22 +1000 Subject: Add PIP and PIPENV Environmental Variables --- docker/app/local.Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/app/local.Dockerfile b/docker/app/local.Dockerfile index 2edf4794..1a088279 100644 --- a/docker/app/local.Dockerfile +++ b/docker/app/local.Dockerfile @@ -3,6 +3,10 @@ FROM bitnami/python:3.7-prod STOPSIGNAL SIGQUIT ARG EXTRAS=deploy +ENV PIP_NO_CACHE_DIR=false \ + PIPENV_HIDE_EMOJIS=1 \ + PIPENV_NOSPIN=1 + # Create a user. RUN useradd --system --shell /bin/false --uid 1500 pysite -- cgit v1.2.3 From 1a89e250f1969ee5b4534c59bd022161ebc2c90c Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 18 Sep 2019 06:01:53 +1000 Subject: Add PIP and PIPENV Environmental Variables to production Dockerfile --- docker/app/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 8378ceb9..a17e034c 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -4,6 +4,10 @@ FROM bitnami/python:3.7-prod STOPSIGNAL SIGQUIT ARG EXTRAS=deploy +ENV PIP_NO_CACHE_DIR=false \ + PIPENV_HIDE_EMOJIS=1 \ + PIPENV_NOSPIN=1 + # Create a user. RUN useradd --system --shell /bin/false --uid 1500 pysite -- cgit v1.2.3 From c73825da901c7b047a8be532fd489ac6a460bd07 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Wed, 18 Sep 2019 19:59:36 +0200 Subject: Nuke `pysite.dockerapp`. --- docker/pysite.dockerapp | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 docker/pysite.dockerapp diff --git a/docker/pysite.dockerapp b/docker/pysite.dockerapp deleted file mode 100644 index 4e90ff87..00000000 --- a/docker/pysite.dockerapp +++ /dev/null @@ -1,42 +0,0 @@ -version: 0.3.0 -name: pysite -description: | - Our community website, built on Django and PostgreSQL. -namespace: python-discord -maintainers: - - name: Johannes Christ - email: jc@jchri.st - ---- -version: "3.6" -services: - django: - build: - context: . - command: docker/app/scripts/migrate_and_serve.sh - ports: - - "127.0.0.1:4000:4000" - environment: - DATABASE_URL: "postgres://${pg_user}:${pg_passwd}@${pg_host}/${pg_db}" - DEBUG: 'false' - SECRET_KEY: "${secret_key}" - depends_on: - - postgres - - postgres: - image: postgres:11-alpine - ports: - - "127.0.0.1:5432:5432" - environment: - POSTGRES_DB: "${pg_db}" - POSTGRES_USER: "${pg_user}" - POSTGRES_PASSWORD: "${pg_passwd}" - ---- -pg_user: pysite -pg_db: pysite -pg_passwd: supersecretpassword -pg_host: postgres -secret_key: 'suitable-for-development-only' - -# vim: ft=yaml: -- cgit v1.2.3 From a1d6ba19e4b88ead216afe6fe71641489bf5bc63 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Fri, 20 Sep 2019 11:19:43 +1000 Subject: Remove EXTRAS ARG as pip extras isn't used anymore. --- docker/app/Dockerfile | 1 - docker/app/local.Dockerfile | 1 - 2 files changed, 2 deletions(-) diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index a17e034c..15b1f77b 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -2,7 +2,6 @@ FROM bitnami/python:3.7-prod # I have no idea what this does. STOPSIGNAL SIGQUIT -ARG EXTRAS=deploy ENV PIP_NO_CACHE_DIR=false \ PIPENV_HIDE_EMOJIS=1 \ diff --git a/docker/app/local.Dockerfile b/docker/app/local.Dockerfile index 1a088279..124dab95 100644 --- a/docker/app/local.Dockerfile +++ b/docker/app/local.Dockerfile @@ -1,7 +1,6 @@ FROM bitnami/python:3.7-prod STOPSIGNAL SIGQUIT -ARG EXTRAS=deploy ENV PIP_NO_CACHE_DIR=false \ PIPENV_HIDE_EMOJIS=1 \ -- cgit v1.2.3 From 8a2a25341c062a681e26ba7c682a6577af0d3704 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Fri, 20 Sep 2019 12:01:26 +1000 Subject: Use DockerV2 task. --- azure-pipelines.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index de6237d8..963f3020 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -75,23 +75,18 @@ jobs: testResultsFiles: "**/TEST-*.xml" testRunTitle: 'Site-Django Test Results' -- job: docker - displayName: 'Build & Push Job' +- job: build + displayName: 'Build & Push Container' dependsOn: coverage_test condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) - pool: - vmImage: ubuntu-16.04 steps: - - task: Docker@1 - displayName: Login to Docker Hub + - task: Docker@2 + displayName: 'Build & Push Container' inputs: - containerregistrytype: 'Container Registry' - dockerRegistryEndpoint: 'DockerHub' - command: 'login' - - - script: | - docker build -t pythondiscord/site:latest -f docker/app/Dockerfile . - docker push pythondiscord/site:latest - displayName: 'Build & Push Docker Image' + containerRegistry: 'DockerHubV2' + repository: 'pythondiscord/site' + command: 'buildAndPush' + Dockerfile: 'docker/app/Dockerfile' + tags: 'latest' -- cgit v1.2.3 From f2951fddfdebbee2d7a445b58b52d1cf8ced7ac8 Mon Sep 17 00:00:00 2001 From: Daniel Brown Date: Fri, 20 Sep 2019 16:16:53 -0500 Subject: Line Ending Fix Added .gitattributes to prevent Windows users from accidentally cloning the repo and getting incorrect line endings Also adjusting the shebang for the migrate_and_serve.sh to prevent another Windows related bug --- .gitattributes | 3 +++ docker/app/scripts/migrate_and_serve.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..a90a0a96 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# Declare files that will always have LF line endings on checkout +# This prevents git on Windows from automatically inserting CRLF line endings +* text=auto eol=lf \ No newline at end of file diff --git a/docker/app/scripts/migrate_and_serve.sh b/docker/app/scripts/migrate_and_serve.sh index 0b54a2e5..c30d7e04 100755 --- a/docker/app/scripts/migrate_and_serve.sh +++ b/docker/app/scripts/migrate_and_serve.sh @@ -1,4 +1,5 @@ -#!/bin/sh -eu +#!/bin/sh +set -eu ### NOTE # This file is intended to be used by local setups. -- cgit v1.2.3