This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | --- |
2 | 2 | nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.j2" |
| 3 | +nginx_basicauth_title: "Restricted area" |
Collapse file
Copy file name to clipboardExpand all lines: ansible/roles/config_nginx/tasks/main.yml +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | include_vars: "{{ ansible_os_family }}.yml" |
4 | 4 | ignore_errors: yes |
5 | 5 |
|
| 6 | +- set_fact: |
| 7 | + has_basic_auth: "{{ nginx_auth_basic is defined and nginx_auth_basic | length > 0 }}" |
| 8 | + htpasswd_path: "{{ nginx_htpasswd_path }}/.{{ nginx_project_name }}" |
| 9 | + |
| 10 | +- name: Write BasicAuth data |
| 11 | + htpasswd: |
| 12 | + path: "{{ htpasswd_path }}" |
| 13 | + name: "{{ item.username }}" |
| 14 | + password: "{{ item.password }}" |
| 15 | + state: present |
| 16 | + when: item.type == 'basic' |
| 17 | + with_items: "{{ nginx_auth_basic }}" |
| 18 | + |
| 19 | +- name: Remove BasicAuth file |
| 20 | + file: |
| 21 | + path: "{{ htpasswd_path }}" |
| 22 | + state: absent |
| 23 | + when: not has_basic_auth |
| 24 | + |
6 | 25 | - name: Add managed vhost config files. |
7 | 26 | template: |
8 | 27 | src: "{{ nginx_vhost_template }}" |
|
Collapse file
Copy file name to clipboardExpand all lines: ansible/roles/config_nginx/vars/main.yml +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
2 | 2 | # OS-specific variables see other yml files in this directory |
3 | 3 | root_group: root |
4 | 4 | nginx_vhost_path: /etc/nginx/sites-enabled |
| 5 | +nginx_htpasswd_path: /etc/nginx/passwd |
Collapse file
Copy file name to clipboardExpand all lines: ansible/roles/stackhead_project/tasks/setup-containerapp.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
14 | 14 | include_role: |
15 | 15 | name: config_nginx |
16 | 16 | vars: |
| 17 | + nginx_project_name: "{{ project_name }}" |
17 | 18 | nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.reverse-proxy.j2" |
| 19 | + nginx_auth_basic: "{{ app_config.security.authentication|default([]) }}" |
18 | 20 | nginx_vhosts: |
19 | 21 | - server_name: "{{ app_config.domain }}" |
20 | 22 | use_https: 1 |
|
Collapse file
Copy file name to clipboardExpand all lines: ansible/roles/stackhead_project/tasks/setup-nativeapp.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
10 | 10 | include_role: |
11 | 11 | name: config_nginx |
12 | 12 | vars: |
| 13 | + nginx_project_name: "{{ project_name }}" |
13 | 14 | nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.native.j2" |
| 15 | + nginx_auth_basic: "{{ app_config.security.authentication|default([]) }}" |
14 | 16 | nginx_use_php: "{{ native_php_enabled }}" |
15 | 17 | nginx_vhosts: |
16 | 18 | - server_name: "{{ app_config.domain }}" |
|
Collapse file
Copy file name to clipboardExpand all lines: ansible/roles/stackhead_setup/tasks/main.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
11 | 11 |
|
12 | 12 | - import_tasks: "roles/stackhead_setup/tasks/setup-user.yml" |
13 | 13 |
|
| 14 | +- import_tasks: "roles/stackhead_setup/tasks/setup-auth.yml" |
| 15 | + |
14 | 16 | - import_tasks: "roles/stackhead_setup/tasks/setup-nginx.yml" |
15 | 17 |
|
16 | 18 | - import_tasks: "roles/stackhead_setup/tasks/setup-docker.yml" |
|
Collapse file
Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +--- |
| 2 | +- name: Install passlib dependency for htpasswd generation |
| 3 | + pip: |
| 4 | + name: passlib |
| 5 | + state: present |
Collapse file
Copy file name to clipboardExpand all lines: ansible/templates/nginx-vhost.j2 +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,5 +35,12 @@ server { |
35 | 35 | client_max_body_size 10G; |
36 | 36 | {% endif %} |
37 | 37 |
|
| 38 | +{% if nginx_auth_basic is defined and nginx_auth_basic | length > 0 %} |
| 39 | + location / { |
| 40 | + auth_basic "{{ nginx_basicauth_title }}"; |
| 41 | + auth_basic_user_file "{{ nginx_htpasswd_path }}/.{{ nginx_project_name }}"; |
| 42 | + } |
| 43 | +{% endif %} |
| 44 | + |
38 | 45 | {% block location %}{% endblock %} |
39 | 46 | } |
Collapse file
Copy file name to clipboard +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +--- |
| 2 | +domain: mydomain.com |
| 3 | +security: |
| 4 | + authentication: |
| 5 | + - type: basic |
| 6 | + username: user |
| 7 | + password: pass |
| 8 | +deployment: |
| 9 | + type: container |
| 10 | + settings: |
| 11 | + expose: |
| 12 | + service: app |
| 13 | + port: 8080 |
| 14 | + registries: |
| 15 | + - username: dockerhubuser |
| 16 | + password: dockerhubpassword |
| 17 | + - username: privateuser |
| 18 | + password: privatepassword |
| 19 | + url: https://myprivateregistry.tld |
| 20 | + services: |
| 21 | + - name: app |
| 22 | + image: getstackhead/project-demo-php |
| 23 | + user: "1000:1000" |
| 24 | + volumes: |
| 25 | + - type: global |
| 26 | + src: assets |
| 27 | + dest: /var/www/public/assets |
| 28 | + - type: local |
| 29 | + src: log |
| 30 | + dest: /var/www/public/log |
| 31 | + - type: custom |
| 32 | + src: /etc/secrets.txt |
| 33 | + dest: /var/www/secrets.txt |
| 34 | + mode: ro |
| 35 | + links: |
| 36 | + - db |
| 37 | + - name: db |
| 38 | + image: mariadb:10.5 |
| 39 | + environment: |
| 40 | + MYSQL_ROOT_PASSWORD: example |
Collapse file
Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +--- |
| 2 | +domain: mydomain.com |
| 3 | +security: |
| 4 | + authentication: |
| 5 | + - type: basic |
| 6 | + username: user |
| 7 | + password: pass |
| 8 | +deployment: |
| 9 | + type: native |
| 10 | + settings: |
| 11 | + public_path: public |
| 12 | + capabilities: |
| 13 | + php: |
| 14 | + version: 7.3 |