Skip to content

Commit

Permalink
Add upgrade.sh and refactor roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Aug 14, 2023
1 parent e0d99ba commit 82d4ce6
Show file tree
Hide file tree
Showing 33 changed files with 307 additions and 221 deletions.
3 changes: 3 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
env: "prod"
data_url: "{% if env == 'prod' %}data.isimip.org{% else %}{{ env }}.isimip.org{% endif %}"
files_url: "files.isimip.org"
7 changes: 5 additions & 2 deletions hosts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
data.isimip.org
files.isimip.org
[data]
isimip-data proxy=193.174.19.232

[files]
isimip-files
File renamed without changes.
29 changes: 19 additions & 10 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
become_user: root
roles:
- role: config
tags: ['config']
tags: config
- role: packages
tags: ['packages']
tags: packages
- role: nginx
tags: ['nginx']
tags: nginx
- role: redis
tags: ['redis']
tags: redis

- name: data.isimip.org
hosts: data
become: yes
become_user: root
roles:
- role: isimip-data
tags: ['isimip-data']
when: ansible_host == "data.isimip.org"
tags: isimip-data

- name: files.isimip.org
hosts: files
become: yes
become_user: root
roles:
- role: isimip-files-api
tags: ['isimip-files-api']
when: ansible_host == "files.isimip.org"
tags: isimip-files-api
- role: isimip-publisher
tags: ['isimip-publisher']
when: ansible_host == "files.isimip.org"
tags: isimip-publisher
12 changes: 6 additions & 6 deletions roles/config/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
---

- name: /root/.bash_aliases
- name: Copy /root/.bash_aliases
copy:
src: bash_aliases
dest: /root/.bash_aliases

- name: /etc/skel/.bash_aliases
- name: Copy/etc/skel/.bash_aliases
copy:
src: bash_aliases
dest: /etc/skel/.bash_aliases

- name: include .bash_aliases in /root/.bashrc
- name: Include .bash_aliases in /root/.bashrc
lineinfile:
dest: /root/.bashrc
line: "source /root/.bash_aliases"
create: yes

- name: include .bash_aliases in /etc/skel/.bashrc
- name: Include .bash_aliases in /etc/skel/.bashrc
lineinfile:
dest: /etc/skel/.bashrc
line: "source ~/.bash_aliases"
create: yes

- name: /root/.emacs
- name: Copy /root/.emacs
copy:
src: emacs
dest: /root/.emacs

- name: /etc/skel/.emacs
- name: Copy /etc/skel/.emacs
copy:
src: emacs
dest: /etc/skel/.emacs
3 changes: 0 additions & 3 deletions roles/isimip-data/files/dev.conf

This file was deleted.

3 changes: 0 additions & 3 deletions roles/isimip-data/files/prod.conf

This file was deleted.

25 changes: 0 additions & 25 deletions roles/isimip-data/files/prod.service

This file was deleted.

12 changes: 12 additions & 0 deletions roles/isimip-data/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Restart gunicorn
systemd:
name: "{{ env }}"
state: restarted
enabled: yes

- name: Run npm run build:prod
become: yes
become_user: isimip
shell:
cmd: /bin/bash -c "source ~/.nvm/nvm.sh && nvm install && npm install && npm run build:prod"
chdir: /srv/www/{{ env }}
67 changes: 35 additions & 32 deletions roles/isimip-data/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,58 @@
gid: 2000
state: present

- name: Add the isimip-data user
- name: Add the isimip user
user:
name: isimip-data
comment: isimip-data user
name: isimip
comment: isimip user
uid: 2000
group: isimip
shell: /bin/bash

- name: Install PostgreSQL 10
- name: Install PostgreSQL 15
zypper:
name:
- postgresql10
- postgresql10-server
- postgresql10-devel
- postgresql15
- postgresql15-server
- postgresql15-devel
state: present

- name: Create /srv/www/prod and /srv/www/dev for isimip-data
- name: Create /srv/www/prod or /srv/www/dev for isimip-data
file:
path: /srv/www/{{ item }}
path: /srv/www/{{ env }}
state: directory
owner: isimip-data
owner: isimip
group: isimip
with_items:
- prod
- dev

- name: Clone the isimip-data repo
become: yes
become_user: isimip
git:
repo: 'https://github.com/ISI-MIP/isimip-data'
dest: /srv/www/{{ item }}
dest: /srv/www/{{ env }}
update: no
notify:
- Run npm run build:prod
- Restart gunicorn

- name: Upgrade the isimip-data repo
become: yes
become_user: isimip-data
with_items:
- prod
- dev
become_user: isimip
git:
repo: 'https://github.com/ISI-MIP/isimip-data'
dest: /srv/www/{{ env }}
update: yes
force: yes
notify:
- Run npm run build:prod
- Restart gunicorn
tags:
- upgrade
- never

- name: Copy systemd service files
copy:
src: "{{ item }}.service"
dest: "/etc/systemd/system/{{ item }}.service"
with_items:
- prod
- dev

- name: Copy tmpfiles.d files
copy:
src: "{{ item }}.conf"
dest: "/etc/tmpfiles.d/{{ item }}.conf"
with_items:
- prod
- dev
template:
src: "data.service"
dest: "/etc/systemd/system/{{ env }}.service"
notify:
- Restart gunicorn
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[Unit]
Description=dev.isimip.org gunicorn daemon
Description={{ data_url }} gunicorn daemon
After=network.target

[Service]
User=isimip-data
User=isimip
Group=isimip

WorkingDirectory=/srv/www/dev
EnvironmentFile=/srv/www/dev/.env
WorkingDirectory=/srv/www/{{ env }}
EnvironmentFile=/srv/www/{{ env }}/.env

LogsDirectory=django/{{ env }} gunicorn/{{ env }}
RuntimeDirectory=gunicorn/{{ env }}

ExecStart=/bin/sh -c '${GUNICORN_BIN} \
--workers ${GUNICORN_WORKER} \
Expand Down
5 changes: 2 additions & 3 deletions roles/isimip-files-api/files/api-app.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Unit]
Description=isimip-files-api gunicorn daemon
PartOf=api.service
After=api.service
After=network.target

[Service]
User=isimip-files-api
Expand All @@ -24,4 +23,4 @@ ExecReload=/bin/sh -c '/usr/bin/pkill -HUP -F ${GUNICORN_PID_FILE}'
ExecStop=/bin/sh -c '/usr/bin/pkill -TERM -F ${GUNICORN_PID_FILE}'

[Install]
WantedBy=api.target
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Unit]
Description=RQ worker for isimip-files-api
PartOf=api.service
After=api.service
Description=RQ worker for isimip-files-api (#%i)
After=network.target

[Service]
Type=simple
Expand All @@ -12,11 +11,12 @@ WorkingDirectory=/srv/www/api
Environment=LANG=en_US.UTF-8
Environment=LC_ALL=en_US.UTF-8
Environment=LC_LANG=en_US.UTF-8
ExecStart=/srv/www/api/env/bin/rq worker >> /var/log/rq/api/worker.log
ExecStart=/srv/www/api/env/bin/rq worker -w 'isimip_files_api.worker.LogWorker'
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=always
RestartSec=5

[Install]
WantedBy=api.target
WantedBy=multi-user.target
4 changes: 0 additions & 4 deletions roles/isimip-files-api/files/api.conf

This file was deleted.

10 changes: 0 additions & 10 deletions roles/isimip-files-api/files/api.service

This file was deleted.

16 changes: 16 additions & 0 deletions roles/isimip-files-api/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Restart app
systemd:
name: "api-app"
state: restarted
enabled: yes

- name: Restart workers
systemd:
name: "{{ item }}"
state: restarted
enabled: yes
with_items:
- api-worker@1
- api-worker@2
- api-worker@3
- api-worker@4
18 changes: 8 additions & 10 deletions roles/isimip-files-api/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@
dest: /srv/www/api
update: no
become_user: isimip-files-api
notify:
- Restart app
- Restart workers

- name: systemd services are present
- name: Copy systemd service files
copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
when: ansible_host == "files.isimip.org"
with_items:
- api.service
- api-app.service
- api-worker.service

- name: tmpfiles.d conf is present
copy:
src: "api.conf"
dest: "/etc/tmpfiles.d/api.conf"
when: ansible_host == "files.isimip.org"
- [email protected]
notify:
- Restart app
- Restart workers

- name: /data/api/public is present on files.isimip.org
file:
Expand Down
1 change: 0 additions & 1 deletion roles/isimip-publisher/files/publisher.conf

This file was deleted.

15 changes: 10 additions & 5 deletions roles/isimip-publisher/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
group: isimip
shell: /bin/bash

- name: Install dependencies
zypper:
name:
- gcc
- gcc-c++
- python3-devel
- libproj-devel
- geos-devel
state: present

- name: Clone the isimip-publisher repo
git:
repo: 'https://github.com/ISI-MIP/isimip-publisher'
Expand All @@ -30,8 +40,3 @@
- /data
- /data/public
- /data/archive

- name: tmpfiles.d conf is present
copy:
src: "publisher.conf"
dest: "/etc/tmpfiles.d/publisher.conf"
4 changes: 4 additions & 0 deletions roles/nginx/files/502.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div style="margin: 100px auto; text-align: center; font-family: sans;">
<img src="https://www.isimip.org/static/images/logo-white.png" alt="isimip logo"/>
<p style="margin-top: 2em;">Sorry, the site is currently down for maintainance, please try again later.</p>
</div>
Loading

0 comments on commit 82d4ce6

Please sign in to comment.