Skip to content

Commit

Permalink
Dockerfile and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
korneevm committed Aug 29, 2020
1 parent b0a3f17 commit 4b7a668
Show file tree
Hide file tree
Showing 11 changed files with 9,222 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
@@ -0,0 +1,11 @@
env/
.git/
__pycache__/
.vscode/
.idea
.envrc
.editorconfig
src/
build/
node_modules/
*.dump
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,30 @@
name: Duild and deploy Docker container
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build the tagged Docker image
run: docker build . --file Dockerfile --tag korneevm/moscowpython
- name: Push the tagged Docker image
run: docker push korneevm/moscowpython
- name: login to server and pull container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script_stop: true
script: |
cd /opt/servers
docker-compose pull moscowpython
docker-compose up -d
docker exec -i servers_moscowpython_1 python3 manage.py migrate --noinput
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -18,6 +18,9 @@ moscowdjango.db
env
node_modules
.venv
src/
.envrc
Pipfile

# Installer logs
pip-log.txt
Expand All @@ -31,3 +34,6 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

# Postgres dump
*.dump
22 changes: 22 additions & 0 deletions Dockerfile
@@ -0,0 +1,22 @@
FROM python:3.7-slim-buster

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install git nodejs npm -y --no-install-recommends

RUN pip install gunicorn==20.0.4

ADD requirements.txt /opt/requirements.txt
RUN pip3 install -r /opt/requirements.txt

COPY . /opt/app

WORKDIR /opt/app

RUN npm install
RUN npx gulp compile

RUN mkdir -p /opt/staticfiles
RUN python3 manage.py collectstatic --noinput

CMD ["gunicorn", "-b 0.0.0.0:8000", "moscowdjango.wsgi:application"]
2 changes: 1 addition & 1 deletion moscowdjango/settings.py
Expand Up @@ -135,7 +135,7 @@
#if DEBUG:
# INSTALLED_APPS += ('debug_toolbar',)

ALLOWED_HOSTS = ['.moscowdjango.ru', 'moscowdjango-staging.herokuapp.com', 'localhost', '.moscowpython.ru']
ALLOWED_HOSTS = ['.moscowdjango.ru', 'moscowdjango-staging.herokuapp.com', 'localhost', '.moscowpython.ru', '127.0.0.1']

LOGGING = {
'version': 1,
Expand Down
2 changes: 1 addition & 1 deletion moscowdjango/settings_production.py
Expand Up @@ -9,7 +9,7 @@
# Amazon credentials
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = 'moscowdjango'
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_QUERYSTRING_AUTH = False
AWS_CALLING_FORMAT = 2 # SUBDOMAIN
AWS_S3_SECURE_URLS = True
Expand Down
4 changes: 2 additions & 2 deletions moscowdjango/settings_staging.py
@@ -1,15 +1,15 @@
# Django settings for moscowdjango project.
from .settings import *

DEBUG = os.environ.get('DEBUG', False)
DEBUG = bool(os.environ.get('DEBUG', False))

EMBEDLY_KEY = os.environ.get('EMBEDLY_KEY')
SECRET_KEY = os.environ.get('SECRET_KEY')

# Amazon credentials
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = 'moscowdjango-staging'
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_QUERYSTRING_AUTH = False
AWS_CALLING_FORMAT = 2 # SUBDOMAIN
AWS_S3_SECURE_URLS = True
Expand Down
2 changes: 1 addition & 1 deletion moscowdjango/wsgi.py
Expand Up @@ -20,4 +20,4 @@ def wrapped(environ, start_response):

application = get_wsgi_application()
application = DjangoWhiteNoise(application)
application = force_domain(application)
#application = force_domain(application)

0 comments on commit 4b7a668

Please sign in to comment.