Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
Complete changelog:
* Added Push notifications
* Added RSS-based post sources
* Added new fields to posts
* Revamped the administration interface and its features
* Added Sentry for error reporting
* Added new deployment system; see README
  • Loading branch information
Spyridon Pagkalos committed Sep 16, 2019
1 parent 7dcb84b commit 53dadc2
Show file tree
Hide file tree
Showing 539 changed files with 15,266 additions and 877 deletions.
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
unichallenge_client/node_modules
/app
/venv
/unichannel
/.env
/.gitignore
/fabfile.py
30 changes: 13 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# Editor stuff
.idea
.vscode
.env
node_modules
*.iml

# Python configs
site_config.py
/database.py
/venv

# Django stuff:
/unichallenge_server/db.sqlite3
# Development assets
*.sqlite3
firebase.json
unichannel
app/static

# Environments
/unichallenge_server/venv/
# Inline configuration
site_config.py

# For b4s
/unichallenge_server/djuc/__pycache__/
/unichallenge_server/djuc/*.py[cod]
/unichallenge_server/djuc/migrations/__pycache__/
# Node dependencies
node_modules

# For project_site
/unichallenge_server/unichallenge/__pycache__/
/unichallenge_server/unichallenge/*.py[cod]
# Python stuff
venv
__pycache__
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM node
FROM python

RUN mkdir /angular
WORKDIR /angular
COPY unichallenge_client/package.json /angular
COPY unichallenge_client/package-lock.json /angular
RUN npm install
COPY unichallenge_client /angular
RUN npm run prod
WORKDIR /app
COPY server/requirements.txt .

FROM nginx
RUN pip install -r requirements.txt
RUN pip install uwsgi

COPY --from=0 /angular/dist/uknow /files/angular
COPY unichallenge_server/static /files/static
COPY server .
COPY server/unichallenge/site_config.production.py unichallenge/site_config.py

CMD uwsgi --socket 0.0.0.0:8000 --protocol uwsgi --module unichallenge.wsgi
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

# UniChannel

## Development

To setup your development environment, after cloning, do:

```bash
cd app
# Setup the Angular application
npm install
cd ..

# Setup the Django app
cd server
virtualenv
source venv/bin/activate
pip install -r requirements.txt
```

You will also need to populate your `server/unichallenge/site_config.py` file with:

* The database connection information about your local MySQL installation.
* The Firebase configuration for your app.
* the `DEBUG = True` flag, to indicate this is a dev environment.

You should also most probably run all migrations and create a superuser:

```bash
cd server;
python manage.py migrate
python manage.py createsuperuser
```

After all this, you can simply run these commands (in seperate terminals):

```bash
cd server; source venv/bin/activate; python manage.py runserver
cd app; yarn run serve
```

And **voila!** The app is now running at [http://localhost:4200](http://localhost:4200)!

## Production

### Deploy the app

To deploy the app, run while in its directory:

```bash
fab -h deployer@<host> deploy
```

The script will take care of building the images, running any pending migrations and (re)starting the apps.

### Setup the app

Ensure **Docker**, **Docker Compose**, **Python >3.6** and **Fabric >2** are installed.

Using the `root` user, execute:

```bash
# Or substitute with your own directory
mkdir /usr/unichannel
# Create the unichannel user
useradd unichannel
# Create the deployer user
useradd deployer
# Make unichannel the owner
chown -R unichannel:unichannel /usr/unichannel
# Allow the deployer to run Docker commands and access the new directory
usermod -a -G docker deployer
usermod -a -G unichannel deployer
```

Now using the `unichannel` user:

```bash
# Initialize the repository
cd /usr/unichannel
git clone [email protected]:Unichallenge/unichannel.git

# Create the user SSH keys and allow other users to make deploys
cd
ssh-keygen
mkdir .ssh; chmod 700 .ssh
cat > .ssh/authorized_keys
```

The `.ssh/authorized_keys` file should have the following format:

```bash
command="cd /usr/unichannel; fab $SSH_ORIGINAL_COMMAND",no-pty ssh-rsa # ...
```

This will ensure people with deploy access can **only execute** `fabric` tasks.

Next up, create the `/usr/unichannel/unichannel` directory and place the `firebase.json` private key file you
generated from Firebase. More about how to create it [here](https://firebase.google.com/docs/admin/setup#initialize_the_sdk).

You must also create the `/usr/unichannel/.env` file containing all the environment variables
necessary for your application to run. This should contain the following:

* `UID` = The UID of the `unichallenge` user.
* `GID` = The GID of the `unichallenge` user.
* `MARIA_PASS` = A unique password for your MariaDB installation.
* `SENTRY_DSN` = The Sentry DSN for error logging.

Compose will automatically take these into consideration when setting up its environment.

You can now try and deploy the app itself!
2 changes: 2 additions & 0 deletions app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
e2e
20 changes: 11 additions & 9 deletions nginx.conf → app/.nginx.server.conf
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
server {
server_name channel.unichallenge.gr;
listen 80;

location /api {
uwsgi_pass server:8000;
uwsgi_pass uwsgi:8000;
include /etc/nginx/uwsgi.conf;
}

location /admin {
uwsgi_pass server:8000;
uwsgi_pass uwsgi:8000;
client_max_body_size 20M;
include /etc/nginx/uwsgi.conf;
}

location /media {
root /files;
location /static/ {
root /static/;
try_files $uri $uri/ =403;
}

location /static {
root /files;
location /media/ {
root /static/;
try_files $uri $uri/ =403;
}

location / {
root /files/angular;
root /static/;
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
}
13 changes: 13 additions & 0 deletions app/.uwsgi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
22 changes: 22 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node

WORKDIR /app
COPY package.json .
COPY package-lock.json .

RUN npm install

COPY src .
COPY angular.json .
COPY proxy.conf.json .
COPY tsconfig.json .
COPY tslint.json .

RUN npm run prod

FROM nginx

COPY --from=0 /app/dist /static/
COPY static /static/static
COPY .nginx.server.conf /etc/nginx/conf.d/default.conf
COPY .uwsgi.conf /etc/nginx/uwsgi.conf
8 changes: 5 additions & 3 deletions unichallenge_client/angular.json → app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/uknow",
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
"src/assets",
"src/firebase-messaging-sw.js"
],
"styles": [
"src/styles.css"
Expand Down Expand Up @@ -57,8 +58,9 @@
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"host": "0.0.0.0",
"browserTarget": "uknow:build",
"proxyConfig": "proxy.conf.json"
"proxyConfig": "proxy.conf.json"
},
"configurations": {
"production": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 53dadc2

Please sign in to comment.