Skip to content

Commit 3d6b4d0

Browse files
committed
New Dockerfile and github action for deploy
1 parent dcacacb commit 3d6b4d0

13 files changed

Lines changed: 291 additions & 252 deletions

File tree

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build and deploy Docker container
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Login to DockerHub Registry
13+
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
14+
- name: Build the tagged Docker image
15+
run: docker build . --file Dockerfile --tag korneevm/pythonru
16+
- name: Push the tagged Docker image
17+
run: docker push korneevm/pythonru
18+
- name: login to server and pull container
19+
uses: appleboy/ssh-action@master
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
key: ${{ secrets.KEY }}
24+
port: ${{ secrets.PORT }}
25+
script_stop: true
26+
script: |
27+
cd /opt/servers
28+
docker-compose pull pythonru
29+
docker-compose up -d
30+
docker exec -i servers_pythonru_1 python3 manage.py migrate --noinput
31+
docker exec -i servers_pythonru_1 python3 manage.py collectstatic --noinput

Dockerfile

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
1-
FROM ubuntu:16.04
2-
3-
ARG version=dev
4-
5-
RUN export DEBIAN_FRONTEND=noninteractive && \
6-
sed -i 's,http://archive.ubuntu.com/ubuntu/,mirror://mirrors.ubuntu.com/mirrors.txt,' /etc/apt/sources.list && \
7-
apt-get update -qq && apt-get upgrade -qq && \
8-
apt-get install -y --no-install-recommends \
9-
python3 \
10-
python3-setuptools \
11-
python3-pip \
12-
python3-psycopg2 \
13-
nginx \
14-
supervisor && \
15-
BUILD_DEPS='build-essential python3-dev libxml2-dev libxslt-dev libssl-dev libffi-dev python-lxml zlib1g-dev git' && \
16-
apt-get install -y --no-install-recommends ${BUILD_DEPS} && \
17-
pip3 install -U setuptools wheel && \
18-
pip3 install -U uwsgi
19-
20-
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
21-
COPY etc/ /etc/
22-
23-
ADD requirements.txt /opt/requirements.txt
24-
RUN pip3 install -r /opt/requirements.txt
1+
FROM python:3.8-slim-buster as base
2+
3+
ENV PYTHONUNBUFFERED 1
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
FROM base AS builder
7+
8+
RUN set -xe; \
9+
apt-get update && apt-get install -y \
10+
-o APT::Install-Recommends=false \
11+
-o APT::Install-Suggests=false \
12+
build-essential\
13+
gcc\
14+
g++ \
15+
libc-dev \
16+
libffi-dev \
17+
libxml2-dev \
18+
libxslt-dev \
19+
libpq-dev \
20+
git \
21+
zlib1g-dev \
22+
libjpeg-dev \
23+
libmagic-dev \
24+
curl \
25+
wget \
26+
ca-certificates
27+
28+
ADD requirements.txt /requirements.txt
29+
RUN pip install --prefix=/install -r /requirements.txt
30+
31+
32+
FROM base
33+
34+
RUN groupadd -g 800 -r unprivileged && useradd -r -g 800 -u 800 -m unprivileged
35+
36+
RUN set -xe; \
37+
apt-get update && apt-get install -y \
38+
-o APT::Install-Recommends=false \
39+
-o APT::Install-Suggests=false \
40+
locales gosu procps libjpeg62; \
41+
gosu nobody true;
42+
43+
COPY --from=builder /install /usr/local
44+
45+
RUN pip install gunicorn==20.0.4
46+
47+
RUN echo "LC_ALL=ru_RU.UTF-8" >> /etc/environment && echo "ru_RU.UTF-8 UTF-8" >> /etc/locale.gen && \
48+
echo "LANG=ru_RU.UTF-8" > /etc/locale.conf && locale-gen ru_RU.UTF-8
2549

2650
COPY . /opt/app
2751

52+
RUN chmod +x /opt/app/entrypoint.sh
53+
RUN chmod +x /opt/app/wait-for-it.sh
54+
2855
WORKDIR /opt/app
29-
RUN mkdir -p /opt/staticfiles
30-
RUN python3 manage.py collectstatic --noinput
56+
RUN mkdir -p /opt/app/static && mkdir -p /opt/staticfiles
57+
58+
RUN chown -R unprivileged:unprivileged /opt/app
59+
60+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
3161

32-
RUN apt-get autoremove -y ${BUILD_DEPS} \
33-
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
62+
EXPOSE 8000
3463

35-
EXPOSE 80
36-
CMD ["supervisord", "-n"]
64+
ENTRYPOINT ["/opt/app/entrypoint.sh"]
65+
CMD ["runserver"]

entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
DO_CONNECTION_CHECK=${DO_CONNECTION_CHECK:-true}
6+
7+
if [ "${DO_CONNECTION_CHECK}" = true ]; then
8+
for link in $(env | grep _LINK= | cut -d = -f 2 | sort | uniq)
9+
do
10+
/opt/app/wait-for-it.sh ${link} -t 0
11+
done
12+
fi
13+
14+
LOG_LEVEL='INFO'
15+
16+
if [ "$1" == 'runworker' ]; then
17+
cd /opt/app
18+
exec gosu unprivileged celery -A python_ru worker -l info
19+
fi
20+
21+
if [ "$1" == 'runserver' ]; then
22+
cd /opt/app
23+
exec gosu unprivileged gunicorn \
24+
-t 180 \
25+
--worker-tmp-dir /dev/shm \
26+
--access-logfile - \
27+
--error-logfile - \
28+
--log-level info \
29+
--workers 4 \
30+
--bind 0.0.0.0:8000 \
31+
python_ru.wsgi:application
32+
fi
33+
34+
exec "$@"

etc/nginx/sites-available/default

Lines changed: 0 additions & 25 deletions
This file was deleted.

etc/nginx/uwsgi_params

Lines changed: 0 additions & 15 deletions
This file was deleted.

etc/supervisor/conf.d/supervisord.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.

etc/uwsgi.ini

Lines changed: 0 additions & 16 deletions
This file was deleted.

fabfile.py

Lines changed: 0 additions & 152 deletions
This file was deleted.

python_ru/templates/blocks/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
{% endfor %}
1111
</ul>
1212
<!-- copyright -->
13-
<p class="copyright">&copy; 2016 <a href="https://python.ru">Python.ru</a></p>
13+
<p class="copyright">&copy; 2016-2020 <a href="https://python.ru">Python.ru</a></p>
1414
</div>
1515
</footer>

requirements-deploy.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)