From 0e198682e58be9978f93f9926978d6f22c535481 Mon Sep 17 00:00:00 2001 From: janmax <j.michal@stud.uni-goettingen.de> Date: Fri, 18 May 2018 19:01:19 +0200 Subject: [PATCH] Updated Dockerfile to support caching --- .dockerignore | 6 ++++-- .gitlab-ci.yml | 24 +++++++++++------------- Dockerfile | 25 +++++++++++++++---------- docker-compose.yml | 5 +++-- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5ea37856..41a3cce3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ # Common -*/.git +.git Dockerfile # Django @@ -9,7 +9,8 @@ Dockerfile *.pyo *.pyd */env* -*/.venv* +.venv +.ipynb_checkpoints pip-log.txt pip-delete-this-directory.txt .tox @@ -26,3 +27,4 @@ public/ # node */node_modules */npm-debug.log +*/dist diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b2f040f..465c8782 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,8 @@ stages: - build - test - - pages - build_image + - pages - staging variables: @@ -74,6 +74,16 @@ test_frontend: paths: - frontend/node_modules/ +# =========================== Build Image section ============================ # +build_backend: + image: docker:latest + stage: build_image + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker build -t $IMAGE_TAG . + - docker tag $IMAGE_TAG $IMAGE_TAG-$CI_COMMIT_SHA + - docker push $IMAGE_TAG + # =========================== Gitlab pages section =========================== # pages: <<: *test_definition_virtualenv @@ -90,18 +100,6 @@ pages: only: - master -# =========================== Build Image section ============================ # -build_backend: - image: docker:latest - stage: build_image - script: - - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker build -t $IMAGE_TAG . - - docker tag $IMAGE_TAG $IMAGE_TAG-$CI_COMMIT_SHA - - docker push $IMAGE_TAG - only: - - master - # ============================== Staging section ============================= # .staging_template: &staging_definition stage: staging diff --git a/Dockerfile b/Dockerfile index 2a790dbb..d9947f19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,34 @@ -# Build Vue files FROM node:carbon as node WORKDIR /app/ -COPY frontend/ . +COPY frontend/package.json . +COPY frontend/yarn.lock . +RUN yarn -RUN npm install -RUN npm run build +# CACHED +COPY frontend/ . +RUN yarn build -# Now fetch other files and build on small image FROM python:3.6-alpine -ENV PYTHONUNBUFFERED 1 +WORKDIR /code -# This set is need otherwise the postgres driver wont work +# This set is needed otherwise the postgres driver wont work RUN apk update \ && apk add --virtual build-deps gcc python3-dev musl-dev curl \ && apk add --no-cache postgresql-dev -WORKDIR /code +COPY requirements.txt . +RUN pip install -r requirements.txt && rm -rf /root/.cache -COPY . /code +# CACHED +COPY . . COPY --from=node /app/dist /code/frontend/dist COPY --from=node /app/dist/index.html /code/core/templates/index.html -RUN pip install -r requirements.txt && rm -rf /root/.cache +ENV PYTHONUNBUFFERED 1 RUN python util/format_index.py RUN python manage.py collectstatic --noinput RUN apk del build-deps + +CMD ["./deploy.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 9f46f31d..94f997ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,9 @@ services: grady: image: docker.gitlab.gwdg.de/j.michal/grady:master - command: - - ./deploy.sh + command: > + bash -c "./manage.py maketestdata && + ./deploy.sh" depends_on: - postgres restart: always -- GitLab