Skip to content

Commit

Permalink
Merge pull request #17 from dannyqiu/deployment-updates
Browse files Browse the repository at this point in the history
Update ansible deployment
  • Loading branch information
hunruh authored Apr 21, 2019
2 parents 96992f8 + 468eb7c commit 27fd185
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ Let's deploy this AWS now!

First step is to launch an EC2 instance (on the Oregon Availability Zone)

This EC2 instance should be using `Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-7c22b41c` as an AMI.
This EC2 instance should be using `Ubuntu Server 18.04 LTS (HVM), SSD Volume Type` as an AMI.
This AMI will be the same type of OS that we used for our VM.

I would recommend that you choose the `t2.micro`, which is a small, free tier-eligible instance type.
Expand All @@ -870,7 +870,7 @@ Ensure, that your vagrant folder looks like this:

```bash
$ ls
Vagrantfile a4keypair.pem ansible.cfg cs.nginx.j2 hosts site.yml upstart.conf.j2
Vagrantfile a4keypair.pem ansible.cfg cs.nginx.j2 hosts site.yml start.sh.j2 systemd.service.j2
$ chmod 700 a4keypair.pem
```

Expand All @@ -879,7 +879,7 @@ and putting that into the hosts file. So the hosts file should look like this, w

```yml
[webservers]
<YOUR_PUBLIC_IP> ansible_ssh_user=ubuntu
<YOUR_PUBLIC_IP> ansible_ssh_user=ubuntu ansible_python_interpreter=/usr/bin/python3
```

Insure that you had the the private key by running `ssh-keygen`:
Expand Down
2 changes: 1 addition & 1 deletion vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Vagrant.configure("2") do |config|

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
config.vm.box = "ubuntu/bionic64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
Expand Down
9 changes: 7 additions & 2 deletions vagrant/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[inventory]
# avoid "did not meet _ requirements" warnings when using -v
# see https://github.com/ansible/ansible/issues/48859
enable_plugins = ini

[defaults]
inventory=hosts
remote_user=ubuntu
private_key_file='~/.ssh/id_rsa'
ansible_ssh_private_key_file='~/.ssh/id_rsa'

[ssh_connection]
pipelining = True
pipelining = True
6 changes: 6 additions & 0 deletions vagrant/cs.nginx.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
server {
listen 80;
client_max_body_size 4G;

location /static/ {
# path for static files
alias {{ repository_path }}/app/static/;
}

location / {
include proxy_params;
proxy_pass http://unix:/tmp/cs.sock;
Expand Down
2 changes: 1 addition & 1 deletion vagrant/hosts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[webservers]
34.208.181.241 ansible_ssh_user=ubuntu
34.208.181.241 ansible_ssh_user=ubuntu ansible_python_interpreter=/usr/bin/python3
37 changes: 20 additions & 17 deletions vagrant/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
remote_user: root
become: true
become_method: sudo
environment:
environment:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
Expand All @@ -17,22 +17,21 @@
dbpassword: password
tasks:
- name: Install necessary packages
apt: update_cache=yes name={{ item }} state=present
with_items:
- libatlas-base-dev
- gfortran
apt: update_cache=yes name={{ packages }} state=present
vars:
packages:
- libatlas-base-dev
- gfortran
- g++
- build-essential
- libssl-dev
- libffi-dev
- python-dev
- libssl-dev
- libffi-dev
- postgresql
- libpq-dev
- git
- python-pip
- python3-dev
- python3-pip
- nginx
- python-numpy
- python-scipy
- name: Run echo
command: echo $APP_SETTINGS; echo $DATABASE_URL
- name: Check if directory exists
Expand All @@ -45,11 +44,13 @@
git: repo='{{ repository_url }}' dest='{{ repository_path }}'
when: cloned.stat.exists == false
- name: Install appdev
command: pip install git+https://github.com/cuappdev/appdev.py.git --upgrade
pip: executable=pip3 name=git+https://github.com/cuappdev/appdev.py.git state=forcereinstall
- name: Install pip requirements
pip: requirements='{{ repository_path }}/requirements.txt'
- name: Copy Upstart configuration
template: src=upstart.conf.j2 dest=/etc/init/upstart.conf
pip: executable=pip3 requirements='{{ repository_path }}/requirements.txt'
- name: Copy systemd start script
template: src=start.sh.j2 dest='{{ repository_path }}/start.sh' mode=a+x
- name: Copy systemd configuration
template: src=systemd.service.j2 dest=/etc/systemd/system/flask-project.service
- name: ensure database is created
become_user: postgres
become: yes
Expand All @@ -67,7 +68,7 @@
become: yes
postgresql_privs: db={{dbname}} role=PUBLIC type=database priv=ALL state=absent login_user=postgres
- name: Make sure our server is running
service: name=upstart state=started
systemd: name=flask-project enabled=yes state=started
- name: Copy Nginx site values
template: src=cs.nginx.j2 dest=/etc/nginx/sites-enabled/cs
notify:
Expand All @@ -80,4 +81,6 @@
service: name=nginx state=started
handlers:
- name: restart nginx
service: name=nginx state=restarted
service: name=nginx state=restarted
- name: restart application
systemd: name=flask-project state=restarted
12 changes: 12 additions & 0 deletions vagrant/start.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

cd "{{ repository_path }}"

exec gunicorn app:app \
--bind=unix:/tmp/cs.sock \
--workers 3 \
--user=root \
--log-level=info \
--access-logfile '-' \
-e DATABASE_URL=postgresql://localhost/my_app_db \
-e APP_SETTINGS=config.ProductionConfig
16 changes: 16 additions & 0 deletions vagrant/systemd.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=flask-project
After=network.target
After=systemd-user-sessions.service
After=network-online.target

[Service]
User=root
Group=nogroup
RemainAfterExit=no
Restart=on-failure
RestartSec=5s
ExecStart={{ repository_path }}/start.sh

[Install]
WantedBy=multi-user.target
12 changes: 0 additions & 12 deletions vagrant/upstart.conf.j2

This file was deleted.

0 comments on commit 27fd185

Please sign in to comment.