GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: set nginx port from Terraform result · getstackhead/stackhead@be6ee09

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
Filter options
  • ansible
    • __tests__
      • test-tf-generation.yml
    • roles
      • config_nginx
        • defaults
          • main.yml
        • tasks
          • main.yml
      • project_containerapp/tasks
        • main.yml
      • stackhead_project/tasks
        • setup-containerapp.yml
        • setup-nativeapp.yml
      • stackhead_setup/tasks
        • setup-terraform.yml
    • templates
      • nginx-vhost.reverse-proxy.j2
      • terraform
        • nginx_server_block.tf.j2
        • terraform-providers.tf.j2
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎ansible/__tests__/test-tf-generation.yml‎

Copy file name to clipboardExpand all lines: ansible/__tests__/test-tf-generation.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
stackhead__certificates_folder: ""
1313
nginx_vhost_content: "{{ lookup('template', nginx_vhost_template) }}"
1414
nginx_project_name: test
15+
containerapp__expose:
16+
service: test
1517
resource_name: "{{ nginx_project_name }}"
1618
app_config:
1719
domain: example.com
Collapse file

‎ansible/roles/config_nginx/defaults/main.yml‎

Copy file name to clipboard
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
---
22
nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.j2"
3-
nginx_basicauth_title: "Restricted area"
4-
nginx_project_name: "_default" # should be set when using this role!
3+
nginx_basicauth_title: "Restricted area"
Collapse file

‎ansible/roles/config_nginx/tasks/main.yml‎

Copy file name to clipboardExpand all lines: ansible/roles/config_nginx/tasks/main.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
- set_fact:
77
has_basic_auth: "{{ nginx_auth_basic is defined and nginx_auth_basic | length > 0 }}"
8-
htpasswd_path: "{{ nginx_htpasswd_path }}/.{{ nginx_project_name }}"
8+
htpasswd_path: "{{ nginx_htpasswd_path }}/.{{ project_name }}"
99

1010
- name: Generate htpasswd Terraform file
1111
template:
Collapse file

‎ansible/roles/project_containerapp/tasks/main.yml‎

Copy file name to clipboardExpand all lines: ansible/roles/project_containerapp/tasks/main.yml
-16Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,3 @@
44
src: "templates/terraform/docker.tf.j2"
55
dest: "{{ stackhead__tf_project_folder }}/docker.tf"
66
force: true
7-
8-
- import_tasks: "roles/config_terraform/tasks/update-project-symlinks.yml"
9-
- import_tasks: "roles/config_terraform/tasks/execute.yml"
10-
11-
# Always fetch port - required for Nginx config update when domain changed
12-
- block:
13-
- name: "StackHead::Container || Get current Docker port"
14-
shell: "docker port stackhead-{{ project_name }}-{{ item.name }} {{ containerapp__expose.port }}"
15-
when: containerapp__expose is defined and item.name == containerapp__expose.service
16-
with_items: "{{ containerapp__services }}"
17-
register: used_port
18-
19-
- set_fact:
20-
container_port: "{{ item.stdout | replace('0.0.0.0:','') }}"
21-
when: item.changed == true
22-
with_items: "{{ used_port.results }}"
Collapse file

‎ansible/roles/stackhead_project/tasks/setup-containerapp.yml‎

Copy file name to clipboardExpand all lines: ansible/roles/stackhead_project/tasks/setup-containerapp.yml
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@
1212
include_role:
1313
name: config_nginx
1414
vars:
15-
nginx_project_name: "{{ project_name }}"
1615
nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.reverse-proxy.j2"
1716
nginx_auth_basic: "{{ app_config.security.authentication|default([]) }}"
1817
nginx_vhost:
1918
server_name: "{{ app_config.domain }}"
2019
use_https: 1
21-
proxy_pass_port: "{{ container_port }}"
2220
state: present
2321
filename: "{{ app_config.domain }}.conf"
24-
when: container_port is defined
25-
# currently not checking if Docker steps succeeded as we cant "register" the result due to import_role
26-
# import_role is required because include_role does not pass the facts set in Docker role
Collapse file

‎ansible/roles/stackhead_project/tasks/setup-nativeapp.yml‎

Copy file name to clipboardExpand all lines: ansible/roles/stackhead_project/tasks/setup-nativeapp.yml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
include_role:
1111
name: config_nginx
1212
vars:
13-
nginx_project_name: "{{ project_name }}"
1413
nginx_vhost_template: "{{ playbook_dir }}/templates/nginx-vhost.native.j2"
1514
nginx_auth_basic: "{{ app_config.security.authentication|default([]) }}"
1615
nginx_use_php: "{{ native_php_enabled }}"
Collapse file

‎ansible/roles/stackhead_setup/tasks/setup-terraform.yml‎

Copy file name to clipboardExpand all lines: ansible/roles/stackhead_setup/tasks/setup-terraform.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
name: andrewrothstein.terraform
1616
- name: Download Nginx provider
1717
get_url:
18-
url: https://github.com/getstackhead/terraform-nginx/releases/download/v1.0.0/terraform-provider-nginx
18+
url: https://github.com/getstackhead/terraform-nginx/releases/download/v1.2.0/terraform-provider-nginx
1919
dest: "{{ terraform_plugin_directory }}/terraform-provider-nginx"
2020
mode: '0755'
2121
owner: stackhead
Collapse file

‎ansible/templates/nginx-vhost.reverse-proxy.j2‎

Copy file name to clipboardExpand all lines: ansible/templates/nginx-vhost.reverse-proxy.j2
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% block location %}
44
location / {
5-
proxy_pass http://localhost:{{ nginx_vhost.proxy_pass_port }};
5+
proxy_pass http://localhost:{~ docker_port ~};
66
proxy_redirect off;
77
proxy_set_header X-Scheme $scheme;
88
proxy_set_header Host $host;
Collapse file

‎ansible/templates/terraform/nginx_server_block.tf.j2‎

Copy file name to clipboardExpand all lines: ansible/templates/terraform/nginx_server_block.tf.j2
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
resource "nginx_server_block" "{{ resource_name }}" {
22
filename = "{{ resource_name }}.conf"
33
enable = true
4+
markers = {
5+
docker_port = docker_container.stackhead-{{ project_name }}-{{ containerapp__expose.service }}.ports[0].external
6+
}
47
content = <<EOF
58
{{ nginx_vhost_content }}
69
EOF
710

11+
{% if containerapp__expose is defined and containerapp__expose.service is defined %}
12+
depends_on = [
13+
docker_container.stackhead-{{ project_name }}-{{ containerapp__expose.service }}
14+
]
15+
{% endif %}
16+
817
provisioner "local-exec" {
918
command = "sudo systemctl reload nginx"
1019
}
Collapse file

‎ansible/templates/terraform/terraform-providers.tf.j2‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
provider "nginx" {
2+
}
3+
14
provider "acme" {
25
server_url = "{% if lookup('env','TEST') == '1' %}https://acme-staging-v02.api.letsencrypt.org/directory{% else %}https://acme-v02.api.letsencrypt.org/directory{% endif %}"
36
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.