Skip to content

Commit d205b6c

Browse files
authored
Ansible Nginx Modification (#210)
* Ansible Nginx Modification * https support * same env variable
1 parent a2dcea4 commit d205b6c

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

devops/services/nginx/setup_nginx_service.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
image_tag: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:image_tag') }}"
88
replicas: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:replicas') }}"
99
domain_name: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:domain_name') }}"
10-
fullchain: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:fullchain') }}"
11-
privkey: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:privkey') }}"
10+
use_https: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:use_https') }}"
1211
destination_directory: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:destination_directory') }}"
1312
tasks:
1413
- name: Copy file from host to machine
@@ -34,18 +33,26 @@
3433
state: directory
3534
mode: "0755"
3635

36+
- name: Pull Certificates
37+
set_fact:
38+
fullchain: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:fullchain') }}"
39+
privkey: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=secret/data/prod/nginx:privkey') }}"
40+
when: use_https == "true"
41+
3742
- name: Create fullchain.pem
3843
copy:
3944
dest: /nginx/certificates/{{ domain_name }}/fullchain.pem
4045
content: |
4146
{{ fullchain }}
47+
when: use_https == "true"
4248

4349
- name: Create privkey.pem
4450
copy:
4551
dest: /nginx/certificates/{{ domain_name }}/privkey.pem
4652
content: |
4753
{{ privkey }}
48-
54+
when: use_https == "true"
55+
4956
- name: Retrieve environment file from Vault
5057
set_fact:
5158
env_file: "{{ lookup('hashi_vault', 'secret=secret/data/generate') }}"

generate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,26 @@ for ((i=0; i<$count; i++)); do
4949
done
5050

5151
printf " }\n" >> "${DOMAIN_NAME}.conf"
52+
53+
if [ "${USE_HTTPS}" = "true" ]; then
54+
printf "\nserver { listen 443; \n listen [::]:443; \n server_name ${DOMAIN_NAME};\n" >> "${DOMAIN_NAME}.conf"
55+
56+
printf " ssl_certificate /etc/nginx/certificates/${DOMAIN_NAME}/fullchain.pem;\n" >> "${DOMAIN_NAME}.conf"
57+
printf " ssl_certificate_key /etc/nginx/certificates/${DOMAIN_NAME}/privkey.pem;\n" >> "${DOMAIN_NAME}.conf"
58+
printf " ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n" >> "${DOMAIN_NAME}.conf"
59+
printf " ssl_ciphers HIGH:!aNULL:!MD5;\n" >> "${DOMAIN_NAME}.conf"
60+
61+
# Loop through each model
62+
for ((i=0; i<$count; i++)); do
63+
# Get model details from config.json
64+
apiBasePath=$(jq -r ".models[$i].apiBasePath" config.json)
65+
66+
# Calculate the exposed port for the model
67+
exposedPort=$((8000 + i))
68+
69+
# Add location block to Nginx configuration
70+
printf " location ${apiBasePath}/ {\n proxy_pass http://localhost:${exposedPort}/;\n }\n" >> "${DOMAIN_NAME}.conf"
71+
done
72+
73+
printf " }\n" >> "${DOMAIN_NAME}.conf"
74+
fi

sample.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ AUTH_HEADER=
33
AUTH_HEADER_KEY=Authorization
44
DOMAIN_NAME=
55
DOCKER_REGISTRY_URL=ghcr.io
6-
GITHUB_REPOSITORY=aitools
6+
GITHUB_REPOSITORY=
7+
USE_HTTPS=false

0 commit comments

Comments
 (0)