Skip to content

Commit

Permalink
Merge pull request #264 from domino14/python3
Browse files Browse the repository at this point in the history
Upgrade app to Python 3
  • Loading branch information
domino14 authored Jan 22, 2018
2 parents 8da52b1 + 84b0e35 commit 9126fac
Show file tree
Hide file tree
Showing 89 changed files with 470 additions and 762 deletions.
163 changes: 163 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
version: 2
jobs:
build_python:
working_directory: /opt/webolith
environment:
PGSQL_DB_NAME: circle
PGSQL_USER: postgres
PGSQL_HOST: 127.0.0.1
PGSQL_PASSWORD:
# Debug for tests is False even if I set this to True.
DEBUG: false
DEBUG_JS: false
# Just some random secret key
INTERCOM_APP_SECRET_KEY: abcdefghijklmnopqrstuvwxyz
SECRET_KEY: csw*nc9gznwuz)(w9&u#h_b2dp1%hzf_w#)%yrzwas%+v8ck_q
WORD_DB_LOCATION: /opt/db
REDIS_HOST: localhost
docker:
- image: domino14/webolith-base-pkg:py3-latest
- image: redis:alpine
- image: postgres
steps:
- checkout # Into the webolith-base-pkg
- add_ssh_keys:
fingerprints:
- "ad:9e:01:fa:fa:e7:03:a4:49:74:98:91:52:a8:dc:3c"
- run:
name: Install git and ssh
command: apk update && apk upgrade && apk add git openssh
- run:
name: Install ssl
command: apk add --update ca-certificates openssl && update-ca-certificates
- run: if [ ! -n "$(grep "^bitbucket.org " ~/.ssh/known_hosts)" ]; then ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null; fi
- run:
name: Clone word dbs Webolith repo
command: git clone [email protected]:cesar_del_solar/webolith-word-dbs.git /opt/webolith-word-dbs
- run: mkdir $WORD_DB_LOCATION
- run: cd /opt/webolith-word-dbs && tar xzvf dbs.tar.gz
- run: mv /opt/webolith-word-dbs/*.db $WORD_DB_LOCATION
- run:
name: install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.6.0
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Wait for redis
command: dockerize -wait tcp://localhost:6379 -timeout 1m
- run:
name: Install Pylint
command: pip install pylint pylint-django
- run:
name: Pylint
command: pylint --errors-only --load-plugins=pylint_django djAerolith/
- run:
name: Django tests
command: cd djAerolith && ./manage.py test -v2

build_js:
working_directory: /opt/webolith
docker:
- image: node:alpine
steps:
- checkout
- run: npm install -g yarn
- run: yarn install
- run: yarn eslint && yarn jshint && yarn test && yarn prod:build
- run: apk add --update ca-certificates openssl && update-ca-certificates
- persist_to_workspace:
root: djAerolith/static
paths:
- dist

build_docker:
working_directory: /opt/webolith
environment:
REPO: /opt/webolith
SECRET_KEY: csw*nc9gznwuz)(w9&u#h_b2dp1%hzf_w#)%yrzwas%+v8ck_q
# For collecting static files to later copy into Nginx. This
# dir must be in the context of the build, so inside the kubernetes dir.
STATIC_ROOT: /opt/webolith/kubernetes/webolith_static/
docker:
- image: domino14/webolith-base-pkg:py3-latest
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: djAerolith/static
- run:
name: Install curl
command: apk --no-cache add curl
- run:
name: Install Docker client
command: |
set -x
VER="17.12.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/* /usr/bin
- run:
name: Collect static files
command: cd djAerolith && ./manage.py collectstatic --noinput
- run:
name: Compile messages
command: cd djAerolith && ./manage.py compilemessages
- run:
name: Build and push Docker images to Dockerhub
command: |
cd $REPO/kubernetes && \
docker build -t domino14/webolith-nginx:$CIRCLE_BUILD_NUM \
-f nginx-Dockerfile --build-arg static_root=./webolith_static/ .
# Delete the static files for the webapp container.
rm -rf $STATIC_ROOT
cd $REPO && \
docker build -t domino14/webolith:$CIRCLE_BUILD_NUM \
-t domino14/webolith:latest .
docker login --username domino14 --password $DOCKER_PASSWORD
docker push domino14/webolith-nginx:$CIRCLE_BUILD_NUM
docker push domino14/webolith:$CIRCLE_BUILD_NUM
docker push domino14/webolith:latest
deploy:
working_directory: /opt/webolith
environment:
# This will get created by the clone below.
KUBECONFIG: /opt/webolith-private/admin.conf
docker:
- image: domino14/aerolith-deployer
steps:
- checkout
# Clone the repo with the admin.conf file
- add_ssh_keys:
fingerprints:
- "ad:9e:01:fa:fa:e7:03:a4:49:74:98:91:52:a8:dc:3c"
- run: if [ ! -n "$(grep "^bitbucket.org " ~/.ssh/known_hosts)" ]; then ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null; fi
- run:
name: Clone private Webolith repo
command: git clone [email protected]:cesar_del_solar/webolith-private.git /opt/webolith-private
- run: fab create_k8s_configs:prod
- run: fab deploy:prod

workflows:
version: 2
build_app:
jobs:
- build_python
- build_js
- build_docker:
requires:
- build_python
- build_js
filters:
branches:
only: master
- deploy:
requires:
- build_docker
filters:
branches:
only: master
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ words/*
node/*
.git/*
**/*.pyc
**/__pycache__
config/*.env
node_modules/*
kubernetes/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ kubernetes/deploy-configs/prod-*.yaml
djAerolith/htmlcov
vars.sh
coverage
__pycache__
7 changes: 7 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[MASTER]
init-hook='base_dir="djAerolith"; import sys,os,re; _re=re.search(r".+\/" + base_dir, os.getcwd()); project_dir = _re.group() if _re else os.path.join(os.getcwd(), base_dir); sys.path.append(project_dir)'

[MESSAGES CONTROL]
# Find available symbolic names in:
# https://docs.pylint.org/features.html
disable=missing-docstring
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.linting.flake8Enabled": false,
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3",
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM domino14/webolith-base-pkg
FROM domino14/webolith-base-pkg:py3-latest
MAINTAINER Cesar Del Solar <[email protected]>

COPY . /opt/webolith/
WORKDIR /opt/webolith/djAerolith

EXPOSE 8000
# Run command in exec form because /bin/sh does not pass signals to its children.
CMD ["daphne", "-b", "0.0.0.0", "asgi:channel_layer"]
CMD ["daphne", "-b", "0.0.0.0", "djaerolith.asgi:channel_layer"]
4 changes: 2 additions & 2 deletions base_pkg.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base image that we can base the prod image on.

FROM python:2-alpine
FROM python:3-alpine
MAINTAINER Cesar Del Solar <[email protected]>

ENV PYTHONUNBUFFERED 1
Expand All @@ -11,4 +11,4 @@ COPY djAerolith/prod_requirements.txt /opt/prod_requirements.txt
RUN pip install --upgrade pip
RUN pip install -r /opt/prod_requirements.txt

# Prod image can import this image, and build on top of it.
# Prod image can import this image, and build on top of it.
8 changes: 0 additions & 8 deletions build-dockers.sh

This file was deleted.

72 changes: 0 additions & 72 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion djAerolith/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
import accounts.models
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import migrations, models

Expand Down
2 changes: 1 addition & 1 deletion djAerolith/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AerolithProfile(models.Model):
avatarUrl = models.CharField(null=True, blank=True, max_length=512)
additional_data = models.TextField(default='{}', blank=True)

def __unicode__(self):
def __str__(self):
return "Profile for " + self.user.username


Expand Down
Loading

0 comments on commit 9126fac

Please sign in to comment.