Created
May 29, 2015 13:59
-
-
Save silenius/423aae95d056683a8e45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jcigar@dev:/usr/local/etc/salt/states/venvs/python/ > cat _template.sls | |
{% import 'venvs/macros.jinja' as macros %} | |
{% set args = salt['pillar.get']('venvs:python:{}'.format(venv)) %} | |
{% set venv_base = salt['pillar.get']('venvs:lookup:base') %} | |
{% set venv_full = '{}/{}'.format(venv_base, venv) %} | |
include: | |
- users.webapps.{{ args.user }} | |
- pkgs.python | |
- postgresql.client | |
{{ macros.venv_dir(venv_base, venv_full, user=args.user, group=args.user) }} | |
# Three steps approach: | |
# - Create the virtualenv | |
# - Upgrade pip to the last version | |
# - Install the requirements (requirements.txt) | |
{{ venv }}: | |
virtualenv.managed: | |
- name: {{ venv_full }} | |
{% if args.python_version == 3.4 %} | |
- venv_bin: /usr/local/bin/pyvenv-3.4 | |
{% elif args.python_version == 2.7 %} | |
- venv_bin: /usr/local/bin/virtualenv-2.7 | |
{% endif %} | |
- system_site_packages: False | |
- user: {{ args.user }} | |
- clear: True | |
- require: | |
- file: {{ venv_full }} | |
- user: {{ args.user }} | |
- pkg: {{ salt['pillar.get']('postgresql:lookup:pkg_client') }} | |
{% if args.python_version == 3.4 %} | |
- pkg: python34 | |
{% elif args.python_version == 2.7 %} | |
- pkg: python27 | |
- pkg: py27-virtualenv | |
{% endif %} | |
{{ venv }}_upgrade_pip: | |
cmd.run: | |
- name: {{ venv_full }}/bin/pip --no-cache-dir install -U pip | |
- user: {{ args.user }} | |
- group: {{ args.user }} | |
- require: | |
- virtualenv: {{ venv }} | |
{{ venv }}_requirements: | |
virtualenv.managed: | |
- name: {{ venv_full }} | |
- requirements: salt://venvs/python/{{ venv }}-requirements.txt | |
- user: {{ args.user }} | |
- env_vars: | |
PIP_CACHE_DIR: /tmp | |
- watch: | |
- cmd: {{ venv }}_upgrade_pip | |
jcigar@dev:/usr/local/etc/salt/states/venvs/python/ > cat alienalert.sls | |
{% extends "venvs/python/_template.sls" %} | |
{% set venv = "alienalert" %} | |
jcigar@dev:/usr/local/etc/salt/states/venvs/python/ > cat bbpf.sls | |
{% extends "venvs/python/_template.sls" %} | |
{% set venv = "bbpf" %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment