Skip to content

Instantly share code, notes, and snippets.

@Mastermind-U
Created August 1, 2019 18:11
Show Gist options
  • Save Mastermind-U/dad7dae08ef40e4915d8494a8f3d3796 to your computer and use it in GitHub Desktop.
Save Mastermind-U/dad7dae08ef40e4915d8494a8f3d3796 to your computer and use it in GitHub Desktop.
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- deploy
before_script:
- apk add --no-cache py-pip
- pip install docker-compose==1.9.0
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
build:
stage: build
script:
- docker-compose build
- docker-compose push
test:
stage: test
script:
- docker-compose pull test
- docker-compose run test
deploy:
stage: deploy
only:
- master
before_script:
# - apk add openssh
- 'which ssh-agent || ( apk add --no-cache openssh-client bash )'
- mkdir -p ~/.ssh
- ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$DEPLOY_KEY")'
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
# copy docker-compose yml to server
- scp docker-compose.yml web@$DEPLOY_ADDR:/home/web/hazeprice/docker-compose.yml
- ssh web@$DEPLOY_ADDR docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
# then we cd to folder with docker-compose, run docker-compose pull to update images, and run services with `docker-compose up -d`
- ssh web@$DEPLOY_ADDR "cd /home/web/hazeprice/ && docker-compose -f docker-compose.yml pull && HOME=/home/web docker-compose -f docker-compose.yml up -d"
version: '2.0'
volumes:
static:
networks:
nginx:
driver: bridge
services:
hazeprice:
image: registry.gitlab.com/hazeprice/hazeprice-api
build: .
environment:
- SECRET_KEY
command: gunicorn hazeprice.wsgi:application --bind 0.0.0.0:8000
volumes:
- static:/usr/src/app/static/
expose:
- "8000"
networks:
- nginx
restart: unless-stopped
test:
image: registry.gitlab.com/hazeprice/hazeprice-api
command: python manage.py test
restart: "no"
nginx:
image: nginx:mainline
ports:
- "80:80"
- "443:443"
volumes:
- ./deploy/nginx/:/etc/nginx/conf.d
- static/:/usr/src/app/static
networks:
- nginx
depends_on:
- hazeprice
restart: unless-stopped
FROM python:3.6-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn
COPY . /usr/src/app
RUN SECRET_KEY=build python manage.py collectstatic --noinput
RUN apk update
RUN apk add --update sshpass \
&& rm -rf /tmp/* /var/cache/apk/*
RUN sshpass
upstream django {
server hazeprice:8000;
}
server {
listen 80;
server_name ...; # тут мой ip
location / {
proxy_pass http://django/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /usr/src/app/static/;
}
}
@Mastermind-U
Copy link
Author

Структура:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment