Skip to content
Snippets Groups Projects
Commit 047735d6 authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Completely refactored CI and Dockerfiles

- the forntend will now be part of the main image since its static
anyway
- The frontend has a testing stage
- reorganized .gitignore files
- docker-compose works as expected
 - serving api on 8000
 - serving frontend on 8080
parent ce3ccdf0
No related branches found
No related tags found
1 merge request!15Refactor
Pipeline #
.dockerignore # Common
*/.git
Dockerfile Dockerfile
db.sqlite3
__pycache__ # Django
*/db.sqlite3
*/__pycache__*
*.pyc *.pyc
*.pyo *.pyo
*.pyd *.pyd
.Python */env*
env
pip-log.txt pip-log.txt
pip-delete-this-directory.txt pip-delete-this-directory.txt
.tox .tox
...@@ -16,4 +19,8 @@ pip-delete-this-directory.txt ...@@ -16,4 +19,8 @@ pip-delete-this-directory.txt
coverage.xml coverage.xml
*,cover *,cover
*.log *.log
.git
# node
*/node_modules
*/npm-debug.log
# If you need to exclude files such as those generated by an IDE, use
# $GIT_DIR/info/exclude or the core.excludesFile configuration variable as
# described in https://git-scm.com/docs/gitignore
# python specific
*.egg-info
*.pot
*.py[co]
.tox/
__pycache__
MANIFEST
.coverage
cache/
# Django specific
dist/
docs/_build/
docs/locale/
tests/coverage_html/
tests/.coverage
build/
static/
tests/report/
*.sqlite3
env/
static/
# project specific
env-grady/
env/
scripts/
*.csv
.importer*
# operation system # operation system
.DS_Store .DS_Store
# ide specific # ide specific
*.sublime-* *.sublime-*
.idea/ .idea/
# Node specific
node_modules/
\ No newline at end of file
...@@ -6,41 +6,58 @@ stages: ...@@ -6,41 +6,58 @@ stages:
variables: variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
build: # ============================= Building section ============================= #
build_backend:
image: docker:latest image: docker:latest
stage: build stage: build
script: script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $IMAGE_TAG backend/ - docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG - docker push $IMAGE_TAG
# ============================== Testing section ============================= #
.test_template: &test_definition # ----------------------------- Backend subsection --------------------------- #
.test_template_backend: &test_definition_backend
stage: test stage: test
image: $IMAGE_TAG image: $IMAGE_TAG
before_script:
- cd backend/
test_coverage: test_coverage:
<<: *test_definition <<: *test_definition_backend
services: services:
- postgres:9.5 - postgres:9.5
script: script:
- cd backend/
- coverage run manage.py test --noinput - coverage run manage.py test --noinput
- coverage report --skip-covered - coverage report --skip-covered
artifacts:
paths:
- .coverage/
test_pylint: test_pylint:
<<: *test_definition <<: *test_definition_backend
script: script:
- cd backend/
- pylint core || exit 0 - pylint core || exit 0
test_prospector: test_prospector:
<<: *test_definition <<: *test_definition_backend
script: script:
- cd backend/
- prospector --uses django || exit 0 - prospector --uses django || exit 0
# ----------------------------- Frontend subsection -------------------------- #
.test_template_frontend: &test_definition_frontend
image: node:carbon-alpine
stage: test
before_script:
- cd frontend/
test_frontend:
<<: *test_definition_frontend
script:
- yarn install
- yarn test --single-run
# ============================== Staging section ============================= #
.staging_template: &staging_definition .staging_template: &staging_definition
stage: staging stage: staging
image: docker:latest image: docker:latest
......
# Build Python files # Build Python files
FROM python:3.6 as python FROM python:3.6 as python
COPY requirements.txt . COPY backend/requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
RUN curl https://gitlab.gwdg.de/snippets/51/raw --output words RUN curl https://gitlab.gwdg.de/snippets/51/raw --output words
# Retrieve noes files FROM node:carbon as node
FROM node:latest as node
COPY package.json . WORKDIR /app/
RUN yarn COPY frontend/ .
RUN npm install
RUN npm run build
# Now fetch other files and build on small image # Now fetch other files and build on small image
FROM python:3.6-alpine FROM python:3.6-alpine
...@@ -22,14 +25,11 @@ RUN apk update \ ...@@ -22,14 +25,11 @@ RUN apk update \
&& apk del build-deps && apk del build-deps
RUN mkdir -p /usr/share/dict RUN mkdir -p /usr/share/dict
RUN mkdir /code WORKDIR /code/backend
WORKDIR /code
COPY . /code COPY . /code
COPY --from=python /root/.cache /root/.cache COPY --from=python /root/.cache /root/.cache
COPY --from=python /words /usr/share/dict/words COPY --from=python /words /usr/share/dict/words
# TODO this won't be necessarry anymore once merged with development COPY --from=node /app/dist /code/backend/static
# since the node_modules are served form the Project Root there
COPY --from=node /node_modules core/static/node_modules
RUN pip install -r requirements.txt && rm -rf /root/.cache RUN pip install -r requirements.txt && rm -rf /root/.cache
# python specific
*.egg-info
*.pot
*.py[co]
.tox/
__pycache__
MANIFEST
.coverage
cache/
# Django specific
dist/
docs/_build/
docs/locale/
tests/coverage_html/
tests/.coverage
build/
tests/report/
*.sqlite3
static/
# project specific
env-grady/
env/
scripts/
*.csv
.importer*
{
"name": "grady",
"version": "0.4.2",
"description": "A new way to correct programming exams",
"main": "index.js",
"repository": "https://gitlab.gwdg.de/j.michal/grady.git",
"author": "Jan Maximilian Michal",
"license": "MIT",
"dependencies": {
"ace-editor-builds": "^1.2.4",
"bootstrap": "4.0.0-beta.2",
"datatables.net": "^1.10.15",
"datatables.net-bs4": "^1.10.15",
"popper.js": "^1.12.3"
}
}
...@@ -9,16 +9,11 @@ services: ...@@ -9,16 +9,11 @@ services:
- /bin/sh - /bin/sh
- -c - -c
- | - |
python manage.py collectstatic --ignore node_modules --noinput --clear
python manage.py compress --force
python manage.py migrate --noinput python manage.py migrate --noinput
python manage.py loaddata core/fixtures/testdata-groups.json gunicorn --bind 0.0.0.0:8000 grady.wsgi:application &
python manage.py loaddata core/fixtures/testdata-user.json cd static/ && python -m http.server 8080
python manage.py loaddata core/fixtures/testdata-core.json
gunicorn --bind 0.0.0.0:8000 grady.wsgi:application
ports: ports:
- "8000:8000" - "8000:8000"
volumes: - "8080:8080"
- /var/www/static:/code/static
depends_on: depends_on:
- postgres - postgres
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment