-
Open a Command Prompt / Terminal / Shell, either:
- On your local computer / localhost
- Or, if you develop on a remote server then SSH into the remote machine.
-
Execute the following commands:
- (Optional) For Production or Remote Servers Only
sudo useradd usernamehere -s /bin/bash && passwd usernamehere
sudo mkdir /home/usernamehere/public_html && chown -Rf usernamehere:groupnamehere /home/usernamehere/public_html
- (Optional) Install Git on your operating system, assuming you don't already have it installed:
- RedHat / CentOS / Fedora:
sudo update yum
&&sudo yum install git
- Ubuntu / Debian:
sudo apt-get update
&&sudo apt-get install git
- Mac:
sudo brew install git
- RedHat / CentOS / Fedora:
cd
to change the directory to where you want the git repository / application to be downloaded- Clone the GitHub repository
- Using the SSH protocol:
git clone [email protected]:codeforgreenville/upstate_tech_cal_service.git
- Or, using the HTTPS protcol:
git clone https://github.com/codeforgreenville/upstate_tech_cal_service.git
- Using the SSH protocol:
cd upstate_tech_cal_service
- Install Docker and Docker Compose on your operating system: https://docs.docker.com/compose/install/
- Alternatively, install Docker Desktop: https://docs.docker.com/desktop/
- (Optional) For Production or Remote Servers Only
-
Create a local config.ini file, if one does not exist. 3.
cp config.ini.example-docker config.ini && nano config.ini
4. Fill in the placeholder values in yourconfig.ini
with the real values for the following,nano config.ini
1. Register your own Eventbrite token 2. Flask secret can be any long random string 3. (No longer needed) Version 3 of the Meetup.com API requires an Oauth Key. However, as of Oct 2019, we're using only public GET API endpoints that require not authentication. It's not necessary to register a Meetup.com API key unless/until the app needs access to an authenticated endpoint, at which point the key could be added to the config file -
Create a local logging_config.ini file
cp logging_config.ini.example logging_config.ini
mkdir logs
-
Test with gunicorn WSGI Server on a localhost port
- Run the following to generate / update the
all_meetings.json
file in your application directory. docker-compose up --build
ordocker-compose up -d --build
to run the container in detatched mode- View logs with
docker-compose logs
or follow logs withdocker-compose logs -f
- Visit the localhost application in your web browser, and see if it works:
http://127.0.0.1:8000/api/gtc?tags=1
- Run the following to generate / update the
-
(Optional) On Remote or Production Servers - Setup a cronjob to generate the all_meetings.json, for example, at :35 after every hour
crontab -e -u usernamehere
35 * * * * source $HOME/.bashrc; cd ~/upstate_tech_cal_service && docker-compose restart
-
(Optional) Configure hosting via a real Web Server, like Apache or Nginx
- Configure an Nginx or Apache to "talk" to the container via the respective "proxy" directive(s)
- Apache Example
<VirtualHost *:443> UseCanonicalName On ServerName events.openupstate.org DocumentRoot /home/eventapi/public_html DirectoryIndex index.html ErrorLog /var/log/httpd/events.openupstate.org_error_log CustomLog /var/log/httpd/events.openupstate.org_access_log combined ProxyPass /api/ http://127.0.0.1:8000|http://events.openupstate.org/api/ <Directory /home/eventapi/public_html> Options -Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI allow from all AllowOverride None Include /home/eventapi/public_html/.htaccess </Directory> # HSTS to force browsers to always ask for https Header always set Strict-Transport-Security "max-age=31536000;" SSLCertificateFile /etc/letsencrypt/live/events.openupstate.org/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/events.openupstate.org/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost>
- Nginx Virtual Host Example - modified from Boban, and not tested
server { server_tokens off; listen 443 ssl; server_name events.openupstate.org; ssl_certificate /etc/letsencrypt/live/events.openupstate.org/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/events.openupstate.org/privkey.pem; access_log /var/log/nginx/access.myserver.log; error_log /var/log/nginx/error.myserver.log; location /api { include proxy_params; proxy_pass http://127.0.0.1:8000; } }
- If hosting Nginx or Apache through a Docker container on the same Docker network, you can replace
127.0.0.1
with the container name, and remove the127.0.0.1:8000
port mapping indocker-compose.yml
.
- Configure an Nginx or Apache to "talk" to the container via the respective "proxy" directive(s)
Kudos To
- https://djangodeployment.com/2016/11/30/how-to-setup-apache-with-gunicorn/
- predis/predis#277
- https://axilleas.me/en/blog/2013/selinux-policy-for-nginx-and-gitlab-unix-socket-in-fedora-19/
- https://stackoverflow.com/q/36527427
- http://vicch.github.io/pkb/programming/book/servers_for_hackers.html
- http://dev.prodigi.us/post/python-gunicorn-apache-simple-and-performant-method-deploy-your-django-projects/
- https://www.vioan.eu/blog/2016/10/10/deploy-your-flask-python-app-on-ubuntu-with-apache-gunicorn-and-systemd/
- https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-centos-7
- https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04