Skip to content

Commit

Permalink
Add Redirect Page
Browse files Browse the repository at this point in the history
  • Loading branch information
rooftopcellist committed Oct 29, 2024
1 parent 75fc0fc commit a5e90ca
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
include:
- SCENARIO: default # tests headless scenario too
- SCENARIO: externaldb
# - SCENARIO: ingress # TODO: This scenario currently fails because ui and event_stream ingress cannot have the same host and path in minikube nginx ingress controller
- SCENARIO: ingress
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down Expand Up @@ -71,14 +71,14 @@ jobs:
- name: Test EDA API via API k8s service
run: |
kubectl port-forward service/eda-demo-api 8081:8000 &
sleep 1
sleep 2
curl -s http://localhost:8081/api/eda/v1/status/
if: ${{ matrix.SCENARIO == 'default' }}

- name: Test EDA API via UI k8s service
run: |
kubectl port-forward service/eda-demo-ui 8080:80 &
sleep 1
sleep 2
curl -s http://localhost:8080/api/eda/v1/status/
if: ${{ matrix.SCENARIO != 'default' }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ jobs:
- name: Test EDA API via API k8s service
run: |
kubectl port-forward service/eda-demo-api 8081:8000 &
sleep 1
sleep 2
curl -s http://localhost:8081/api/eda/v1/status/
if: ${{ matrix.SCENARIO == 'default' }}

- name: Test EDA API via UI k8s service
run: |
kubectl port-forward service/eda-demo-ui 8080:80 &
sleep 1
sleep 2
curl -s http://localhost:8080/api/eda/v1/status/
if: ${{ matrix.SCENARIO != 'default' }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ spec:
path: public_base_url
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:text
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:hidden
- displayName: Automation Server URL
path: automation_server_url
x-descriptors:
Expand Down
7 changes: 7 additions & 0 deletions roles/eda/tasks/deploy_eda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
definition: "{{ lookup('template', 'eda.configmap.yaml.j2') }}"
wait: yes

- name: Apply Redirect Page Configmap
k8s:
apply: yes
definition: "{{ lookup('template', 'redirect-page.configmap.html.j2') }}"
wait: yes
when: public_base_url is defined

- name: Apply Backend deployment resources
k8s:
apply: yes
Expand Down
7 changes: 2 additions & 5 deletions roles/eda/templates/eda-api.configmap.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ data:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://gunicorn; # Forward requests to Django app
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
root {{ static_path }};
try_files /index.html =404;
access_log /var/log/nginx/proxy_access.log;
error_log /var/log/nginx/proxy_error.log;
}
Expand Down
36 changes: 31 additions & 5 deletions roles/eda/templates/eda-api.deployment.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ spec:
app.kubernetes.io/component: '{{ deployment_type }}-api'
annotations:
kubectl.kubernetes.io/default-container: 'eda-api'
{% for template in [
"redirect-page.configmap",
] %}
checksum-{{ template | replace('/', '-') }}: "{{ lookup('template', template + '.html.j2') | sha1 }}"
{% endfor %}
{% for template in [
"eda.configmap",
] %}
Expand Down Expand Up @@ -117,10 +122,7 @@ spec:
- name: eda-initial-data
image: {{ _image }}
imagePullPolicy: '{{ image_pull_policy }}'
command:
- /bin/bash
- -c
- aap-eda-manage create_initial_data && aap-eda-manage collectstatic --noinput
command: ["/bin/bash", "-c", "aap-eda-manage create_initial_data{% if not ui_disabled %} && aap-eda-manage collectstatic --noinput{% endif %}"]
envFrom:
- configMapRef:
name: '{{ ansible_operator_meta.name }}-{{ deployment_type }}-env-properties'
Expand Down Expand Up @@ -160,9 +162,11 @@ spec:
{% if combined_api.resource_requirements is defined %}
resources: {{ combined_api.resource_requirements }}
{% endif %}
{% if not ui_disabled %}
volumeMounts:
- name: static-files
mountPath: {{ static_path }}
{% endif %}
{% if bundle_ca_crt %}
- name: configure-bundle-ca-cert
image: {{ _image }}
Expand Down Expand Up @@ -282,9 +286,11 @@ spec:
{% if combined_api.resource_requirements is defined %}
resources: {{ combined_api.resource_requirements }}
{% endif %}
{% if not ui_disabled %}
volumeMounts:
- name: static-files
mountPath: {{ static_path }}
{% endif %}
- name: daphne
image: {{ _image }}
imagePullPolicy: '{{ image_pull_policy }}'
Expand Down Expand Up @@ -375,8 +381,16 @@ spec:
ports:
- containerPort: {{ api_nginx_port }}
volumeMounts:
{% if not ui_disabled %}
- name: static-files
mountPath: {{ static_path }}
mountPath: '{{ static_path }}'
{% else %}
{% if public_base_url is defined %}
- name: redirect-page
mountPath: '{{ static_path }}/index.html'
subPath: redirect-page.html
{% endif %}
{% endif %}
- name: '{{ ansible_operator_meta.name }}-nginx-api-conf'
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
Expand All @@ -386,9 +400,21 @@ spec:
- name: nginx-run
mountPath: /var/run
restartPolicy: Always

volumes:
{% if not ui_disabled %}
- name: static-files
emptyDir: {}
{% else %}
{% if public_base_url is defined %}
- name: redirect-page
configMap:
name: '{{ ansible_operator_meta.name }}-redirect-page'
items:
- key: redirect-page.html
path: redirect-page.html
{% endif %}
{% endif %}
- name: '{{ ansible_operator_meta.name }}-nginx-api-conf'
configMap:
name: '{{ ansible_operator_meta.name }}-nginx-api-configmap'
Expand Down
77 changes: 77 additions & 0 deletions roles/eda/templates/redirect-page.configmap.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ ansible_operator_meta.name }}-redirect-page
namespace: {{ ansible_operator_meta.namespace }}
data:
redirect-page.html: |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="15; url={{ public_base_url }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting to Ansible Automation Platform</title>

<!-- Favicon links -->
<link rel="icon" type="image/x-icon" href="static/rest_framework/docs/img/favicon.ico">

<!-- Link to DRF's CSS -->
<link rel="stylesheet" type="text/css" href="static/rest_framework/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="static/rest_framework/css/bootstrap-theme.min.css">

<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding-top: 0px;
/* background-color: rgb(34, 34, 34); */
}
.banner {
background-color: #151414;
color: rgb(255, 255, 255);
padding: 20px;
margin-bottom: 20px;
min-height: 70px; /* Ensure the banner is tall enough to fit the logo */
}
.logo {
width: 150px;
margin-bottom: 20px;
float: left;
}
a {
color: #007BFF;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.doc-note {
font-size: 0.7em; /* Makes the text smaller */
color: #555; /* Optional: Change text color to a lighter shade */
background-color: #f9f9f9; /* Optional: Light background color */
padding: 10px; /* Optional: Add some padding */
margin: 10px 0; /* Optional: Add some margin */
float: left;
}
</style>
</head>
<body>
<!-- Banner Section with Brand Logo -->
<div class="banner">
<img class="logo" src="/static/logo/aap-logo.svg" alt="Brand Logo">
</div>

<h2>Redirecting to Ansible Automation Platform...</h2>
<p>If you are not redirected automatically, <a href="{{ public_base_url }}">click here</a> to go to AAP.</p>
<p class="doc-note">
The API endpoints for this platform service will temporarily remain available at the URL for this service.
Please use the Ansible Automation Platform API endpoints corresponding to this component in the future.
These can be found at <a href="{{ public_base_url }}/api/eda/" target="_blank">{{ public_base_url }}/api/eda</a>.
</p>

<!-- Include any additional scripts if needed -->
<script src="static/rest_framework/js/jquery-3.5.1.min.js"></script>
<script src="static/rest_framework/js/bootstrap.min.js"></script>
</body>
</html>

0 comments on commit a5e90ca

Please sign in to comment.