diff --git a/.dockerignore b/.dockerignore index e09277c..88ad04d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,3 @@ README.md .git .gitlab docker-compose.* -deploy diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eaddc9e..15943f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,22 +5,37 @@ variables: DEPLOY_KUBER_NAMESPACE: spatial stages: - - build + - build_django + - build_static # - lint - deploy -build-docker: - stage: build +build-django: + stage: build_django tags: - shell script: - > docker build --build-arg YC_CONTAINER_REGISTRY=${YC_CONTAINER_REGISTRY} + -f ./deploy/dockerfiles/Dockerfile -t ${DOCKER_IMAGE_TAG} . - docker push ${DOCKER_IMAGE_TAG} -deploy_dev_kuber: +build-static-image: + stage: build_static + tags: + - shell + script: + - > + docker build + --build-arg YC_CONTAINER_REGISTRY=${YC_CONTAINER_REGISTRY} + --build-arg DJANGO_DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} + -f ./deploy/dockerfiles/Dockerfile-nginx + -t ${DOCKER_IMAGE_TAG}-static . + - docker push ${DOCKER_IMAGE_TAG}-static + +deploy-dev-kuber: extends: .deploy_base_kuber variables: INGRESS_HOST: "postnet.dev.selftech.ru" @@ -40,17 +55,21 @@ deploy_dev_kuber: script: - sed -i "s|DEPLOY_IMAGE_TAG|${DOCKER_IMAGE_TAG}|g" ./deploy/django.yml - sed -i "s|ADDRESS_INGRESS_HOST|${INGRESS_HOST}|g" ./deploy/django.yml + - sed -i "s|ADDRESS_INGRESS_HOST|${INGRESS_HOST}|g" ./deploy/django-static.yml - sed -i "s|DEPLOY_IMAGE_TAG|${DOCKER_IMAGE_TAG}|g" ./deploy/worker.yml - sed -i "s|DEPLOY_IMAGE_TAG|${DOCKER_IMAGE_TAG}|g" ./deploy/beat.yml + - sed -i "s|DEPLOY_IMAGE_TAG|${DOCKER_IMAGE_TAG}-static|g" ./deploy/django-static.yml - kubectl apply -f ./deploy/django.yml - kubectl apply -f ./deploy/worker.yml - kubectl apply -f ./deploy/beat.yml + - kubectl apply -f ./deploy/django-static.yml dependencies: [] artifacts: paths: - ./deploy/django.yml - ./deploy/worker.yml - ./deploy/beat.yml + - ./deploy/django-static.yml expire_in: 1 week when: manual diff --git a/deploy/django-static.yml b/deploy/django-static.yml new file mode 100644 index 0000000..0a54c6d --- /dev/null +++ b/deploy/django-static.yml @@ -0,0 +1,73 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: django-static + namespace: spatial + labels: + app.kubernetes.io/name: django-static +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: django-static + template: + metadata: + labels: + app.kubernetes.io/name: django-static + spec: + containers: + - name: django + image: DEPLOY_IMAGE_TAG + ports: + - containerPort: 80 + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "64Mi" + cpu: "50m" + readinessProbe: + httpGet: + path: /nginx-health + port: 8888 + initialDelaySeconds: 3 + periodSeconds: 3 + livenessProbe: + httpGet: + path: /nginx-health + port: 8888 + initialDelaySeconds: 3 + periodSeconds: 3 +--- +apiVersion: v1 +kind: Service +metadata: + name: django-static +spec: + selector: + app.kubernetes.io/name: django-static + ports: + - protocol: TCP + port: 80 + targetPort: 80 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: django-static + namespace: spatial +spec: + ingressClassName: nginx-internal + rules: + - host: ADDRESS_INGRESS_HOST + http: + paths: + - backend: + service: + name: django-static + port: + number: 80 + path: /django_static/ + pathType: ImplementationSpecific diff --git a/deploy/django.yml b/deploy/django.yml index 0a3b605..a4b312e 100644 --- a/deploy/django.yml +++ b/deploy/django.yml @@ -19,7 +19,7 @@ spec: containers: - name: django image: DEPLOY_IMAGE_TAG - command: ["sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput && python manage.py runserver 0.0.0.0:${DJANGO_PORT}"] + command: ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:${DJANGO_PORT}"] ports: - containerPort: 8000 envFrom: @@ -89,10 +89,3 @@ spec: number: 8000 path: /accounts/ pathType: ImplementationSpecific - - backend: - service: - name: postamates-django - port: - number: 8000 - path: /django_static/ - pathType: ImplementationSpecific diff --git a/Dockerfile b/deploy/dockerfiles/Dockerfile similarity index 77% rename from Dockerfile rename to deploy/dockerfiles/Dockerfile index 93c761b..95d5f00 100644 --- a/Dockerfile +++ b/deploy/dockerfiles/Dockerfile @@ -12,7 +12,4 @@ COPY requirements.txt /code/ RUN pip install -r /code/requirements.txt -# RUN apt purge binutils libproj-dev gdal-bin -y && \ -# apt autoremove -y - COPY . /code/ diff --git a/deploy/dockerfiles/Dockerfile-nginx b/deploy/dockerfiles/Dockerfile-nginx new file mode 100644 index 0000000..75999ea --- /dev/null +++ b/deploy/dockerfiles/Dockerfile-nginx @@ -0,0 +1,8 @@ +ARG DJANGO_DOCKER_IMAGE_TAG +ARG YC_CONTAINER_REGISTRY +FROM ${DJANGO_DOCKER_IMAGE_TAG} as builder +RUN python manage.py collectstatic --noinput + +FROM ${YC_CONTAINER_REGISTRY}/public/nginx:1.23-alpine +COPY ./deploy/nginx_conf/default.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /code/django_static /usr/share/nginx/html/django_static diff --git a/deploy/nginx_conf/default.conf b/deploy/nginx_conf/default.conf new file mode 100644 index 0000000..7d45bb7 --- /dev/null +++ b/deploy/nginx_conf/default.conf @@ -0,0 +1,18 @@ +server { + listen 80; + server_name _; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } +} + +server { + listen 8888; + server_name _; + location /nginx-health { + return 200 "healthy\n"; + access_log off; + } +}