From 006c7f5e098d36a02320a404a4d2b02f5ed20689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Fri, 17 Mar 2023 12:05:10 +0100 Subject: [PATCH] add test CI --- .gitlab-ci.yml | 30 ++++++++++++++++++++++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++++ Dockerfile.nginx | 3 +++ nginx.conf | 23 +++++++++++++++++++++++ run.sh | 10 ++++++++++ 5 files changed, 96 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 Dockerfile.nginx create mode 100644 nginx.conf create mode 100644 run.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..cae401b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +stages: + - build + +image: docker:20.10.8 + +variables: + DOCKER_TLS_CERTDIR: "/certs" + IMAGE_TAG_APP: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + IMAGE_TAG_NGINX: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-nginx + +services: + - docker:20.10.8-dind + +before_script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + +build_app: + stage: build + script: + - docker pull $CI_REGISTRY_IMAGE:test || true + - docker build --cache-from $CI_REGISTRY_IMAGE:test -t $IMAGE_TAG_APP . + - docker push $IMAGE_TAG_APP + +build_nginx: + stage: build + when: manual + script: + - docker pull $CI_REGISTRY_IMAGE:test-nginx || true + - docker build --cache-from $CI_REGISTRY_IMAGE:test-nginx -t $IMAGE_TAG_NGINX . -f Dockerfile.nginx + - docker push $IMAGE_TAG_NGINX diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f94022 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.10 + +RUN mkdir /app +WORKDIR /app + +RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - +RUN apt-get install nodejs && rm -rf /var/lib/apt/lists/* + +COPY . . + +RUN pip install -r requirements/base.txt -r requirements/production.txt +RUN npm install +RUN npm run build + +# Placeholder values so the static files collect +RUN DATABASE_URL=postgres://x/x \ + SECRET_KEY=x \ + ALLOWED_HOSTS=x \ + python manage.py collectstatic --noinput --settings=registry.settings.production + +RUN bash -c "adduser --disabled-login --quiet --gecos app app && \ + chmod -R o+r /app/ && \ + chmod o+x /app/run.sh" +USER app + +ENV DJANGO_SETTINGS_MODULE "registry.settings.production" + +EXPOSE 8000 + +CMD ["bash", "run.sh"] diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 0000000..7f2e08a --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,3 @@ +FROM nginx:1.18 +EXPOSE 8080 +ADD nginx.conf /etc/nginx/conf.d/contract_registry.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..4725c76 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,23 @@ +upstream contract_registry { + ip_hash; + server app:8000; +} + +server { + server_name contract_registry; + listen 8080; + + client_max_body_size 10M; + + proxy_connect_timeout 60; + proxy_send_timeout 60; + proxy_read_timeout 60; + send_timeout 60; + + location / { + proxy_pass http://contract_registry/; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..416f8b5 --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# exit on error +set -e + +# migrate database +python manage.py migrate + +# start webserver +exec gunicorn -c gunicorn.conf.py registry.wsgi -- GitLab