Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
fb300ba
fixed copy files
NeckerFree Jul 16, 2025
785f9f8
splitted send
NeckerFree Jul 16, 2025
437f33f
added copy SSH to jumbox and run setup-infra.yml playbook
NeckerFree Jul 16, 2025
87f89dc
fixed Failed to connect to the host via ssh from setup-infra
NeckerFree Jul 16, 2025
3f30b2b
created configure jumpbox script
NeckerFree Jul 16, 2025
abfed33
passed { secrets.VM_SSH_KEY }
NeckerFree Jul 16, 2025
800b584
Fixed SSH_KEY_CONTENT
NeckerFree Jul 16, 2025
581ac1f
Fixed The error was: 'ssh_home' is undefined
NeckerFree Jul 16, 2025
e49ac42
implemented changes to deploy api to jumpbox
NeckerFree Jul 16, 2025
f670cc6
Fixed conflicting action statements: run, working-directory
NeckerFree Jul 16, 2025
fc1973c
fixed script name
NeckerFree Jul 16, 2025
bf247a0
fixed remote username contains invalid characters
NeckerFree Jul 16, 2025
9229fb4
fixed protocol version mismatch
NeckerFree Jul 16, 2025
1df7fa2
fixed movie-api.service.j2 not found
NeckerFree Jul 16, 2025
74829c5
Fixed playbook_dir
NeckerFree Jul 16, 2025
b9cb17f
run db playbook
NeckerFree Jul 16, 2025
3fe721e
fixed the playbook: db-setup.yml could not be found
NeckerFree Jul 16, 2025
b27469c
fixed the playbook: db-setup.yml could not be found
NeckerFree Jul 16, 2025
2570dc4
fixed expanded paths
NeckerFree Jul 16, 2025
1dc1f10
repeat workflow
NeckerFree Jul 17, 2025
5e38c06
fixed Could not find or access '/home/adminuser/movie_db.sql'
NeckerFree Jul 17, 2025
0e6ad59
fixed script copy
NeckerFree Jul 17, 2025
b4db169
fixed db_host
NeckerFree Jul 17, 2025
148cf83
fixed DB_HOST 2
NeckerFree Jul 17, 2025
be725c0
fixed db_host
NeckerFree Jul 17, 2025
9904afb
echo db_host
NeckerFree Jul 17, 2025
01c9456
fixed playbook invocation
NeckerFree Jul 17, 2025
afe54df
fixed expansión
NeckerFree Jul 17, 2025
c84218c
fixed db vars
NeckerFree Jul 17, 2025
4b8f2cf
removed repeated block
NeckerFree Jul 17, 2025
388a63f
Forzar solo la línea con tail y grep
NeckerFree Jul 17, 2025
3da7855
db host
NeckerFree Jul 17, 2025
a4a9376
validate output
NeckerFree Jul 17, 2025
514bbe8
fixed extraction
NeckerFree Jul 17, 2025
8e6f5d0
validation 1
NeckerFree Jul 17, 2025
632bbd6
solution 2
NeckerFree Jul 17, 2025
96515fd
solution 3
NeckerFree Jul 17, 2025
50c0d2c
solution 4
NeckerFree Jul 17, 2025
6649412
solution 5
NeckerFree Jul 17, 2025
db81647
final solution
NeckerFree Jul 17, 2025
5ec3754
create db
NeckerFree Jul 17, 2025
ef05c59
fixed it might be an issue with
NeckerFree Jul 17, 2025
3139475
fixed quotation marks
NeckerFree Jul 17, 2025
483869b
removed space
NeckerFree Jul 17, 2025
dda0e53
fixed error in Create MySQL database
NeckerFree Jul 17, 2025
87a04c5
FixedAttempt to create database
NeckerFree Jul 17, 2025
3588cb9
Update terraform-destroy.yml
NeckerFree Jul 18, 2025
697f46e
Update terraform.yml
NeckerFree Jul 18, 2025
b07d7fe
Create webapp.yml
NeckerFree Jul 18, 2025
41246f1
Update terraform.yml
NeckerFree Jul 18, 2025
1922031
Update db-setup.yml
NeckerFree Jul 18, 2025
3d29a3e
Update db-setup.yml
NeckerFree Jul 19, 2025
5d67974
Update db-setup.yml
NeckerFree Jul 19, 2025
1d3dcc7
Reset nolog db-setup.yml
NeckerFree Jul 19, 2025
33bed0a
Update Db Pass deploy-db-from-local.sh
NeckerFree Jul 19, 2025
e1bea22
removed echo
NeckerFree Jul 19, 2025
1170312
execute terraform workflow
NeckerFree Jul 20, 2025
7a71dab
updated admin user
NeckerFree Jul 20, 2025
a9ede63
fixed quotation marks
NeckerFree Jul 20, 2025
a9e1126
fixed Synchronize API code
NeckerFree Jul 20, 2025
202f83a
fixed indentation
NeckerFree Jul 20, 2025
fcf3605
validated sintax
NeckerFree Jul 20, 2025
72d7c5e
cleaned shell
NeckerFree Jul 20, 2025
8420631
Cleaned up the remote shell
NeckerFree Jul 20, 2025
bcfe5b8
Fixed Synchronize API code
NeckerFree Jul 20, 2025
098a47a
added Copy API code
NeckerFree Jul 20, 2025
2d89027
Fixed node version
NeckerFree Jul 20, 2025
0231ceb
updated solution
NeckerFree Jul 20, 2025
f9052d7
fixed rsync error: protocol incompatibility
NeckerFree Jul 21, 2025
2c309e7
renamed deploy api script
NeckerFree Jul 21, 2025
eb4c49b
updated deploy api script
NeckerFree Jul 21, 2025
605ee25
fixed Uncaught Error: listen EADDRINUSE
NeckerFree Jul 21, 2025
eeebe88
sttoped service before run tests
NeckerFree Jul 21, 2025
d7c568b
added frontend playbook
NeckerFree Jul 21, 2025
e3a267f
Updated db connectivity test
NeckerFree Jul 21, 2025
76d2340
Removed azure_rm_webappconfiguration module (not needed)
NeckerFree Jul 21, 2025
3059d70
Fixed terraform vars extraction
NeckerFree Jul 21, 2025
4df751c
fix terraform vars extraction and used full GH workspace
NeckerFree Jul 21, 2025
5a0695e
fixed terraform vars extraction and passed workspace
NeckerFree Jul 21, 2025
ba73358
deploy without az collection
NeckerFree Jul 21, 2025
14be362
Fixed Azure API version
NeckerFree Jul 21, 2025
26b427c
updated azure_api_version
NeckerFree Jul 21, 2025
6b8bcc5
fixed api version
NeckerFree Jul 21, 2025
788bbc8
Fixed terraform vars
NeckerFree Jul 21, 2025
3c884f5
fixed char error
NeckerFree Jul 21, 2025
5bd9ac2
Fixed terraform vars extraction
NeckerFree Jul 21, 2025
5b4b190
fixed Terraform outputs aren't being properly captured
NeckerFree Jul 21, 2025
064ad50
removed duplicated lb
NeckerFree Jul 21, 2025
669a26d
fixed outputs aren't being properly captured and passed to Ansible
NeckerFree Jul 21, 2025
b0383e1
updated strict validation
NeckerFree Jul 21, 2025
4568d7c
Fixed extraction
NeckerFree Jul 21, 2025
ff52459
removed comments
NeckerFree Jul 21, 2025
6f28e9d
Fix error the terraform output -json command is being called incorrectly
NeckerFree Jul 21, 2025
2ef04cc
fixed terraform output -json command is being interpreted incorrectly
NeckerFree Jul 22, 2025
bb4635f
fixed extraction errors
NeckerFree Jul 22, 2025
d894a2f
Fixed Error: Terraform outputs contain command strings
NeckerFree Jul 22, 2025
70b38d3
fixed command outputs and terraform formats
NeckerFree Jul 22, 2025
67a9ad6
Fixed the Terraform CLI path isn't being properly referenced
NeckerFree Jul 22, 2025
ac556cc
guaranteed solution
NeckerFree Jul 22, 2025
7fec62d
final solution
NeckerFree Jul 22, 2025
a783f06
alternative solution
NeckerFree Jul 22, 2025
4ea077f
fixed backend environment var
NeckerFree Jul 22, 2025
6f7d811
Generated Terraform outputs
NeckerFree Jul 22, 2025
5e8357e
fixed terraform vars
NeckerFree Jul 22, 2025
437aa7b
print final url
NeckerFree Jul 22, 2025
8f50194
exported vars
NeckerFree Jul 22, 2025
043cca0
fixed Generate Terraform outputs
NeckerFree Jul 22, 2025
782efdc
fixed variable "ssh_public_key" is not set
NeckerFree Jul 22, 2025
34077d8
fixed output
NeckerFree Jul 22, 2025
63ee18a
npm run and build
NeckerFree Jul 22, 2025
70542f4
fixed Ansible local execution
NeckerFree Jul 22, 2025
88bf0a7
Final changes
NeckerFree Jul 22, 2025
07229a7
fixed load balancer error
NeckerFree Jul 22, 2025
22936b6
show tf outputs
NeckerFree Jul 22, 2025
dee8477
fixed lb url concatenation
NeckerFree Jul 22, 2025
98fd918
SSH error
NeckerFree Jul 22, 2025
79aa7f9
fixed node server in scripts
NeckerFree Jul 22, 2025
6dcf1cc
Setted custom startup
NeckerFree Jul 22, 2025
d916430
fix timeout error
NeckerFree Jul 22, 2025
e858a02
Fixed deployment error
NeckerFree Jul 22, 2025
9eace0f
removed localhost
NeckerFree Jul 22, 2025
aeed19c
supported a reliable Azure Web App deployment for EJS frontend
NeckerFree Jul 22, 2025
151632d
fixed error occurred during deployment
NeckerFree Jul 22, 2025
e36831b
updated from F1 to B1 due QuotaExceeded
NeckerFree Jul 22, 2025
3a187eb
deployed zip to Azure Web App using kudu zip push
NeckerFree Jul 22, 2025
cb9c70d
Leave Azure install dependencies
NeckerFree Jul 22, 2025
0f15f27
changed zip to copy
NeckerFree Jul 22, 2025
75c2cc6
implemented zip solution
NeckerFree Jul 22, 2025
bde857f
Set startup file command (npm start)
NeckerFree Jul 22, 2025
6129c03
fixed not executed npm install
NeckerFree Jul 22, 2025
2134979
Verify that frontend is accesible after deploy
NeckerFree Jul 22, 2025
7f04c36
Ok
NeckerFree Jul 22, 2025
565639e
Added readme file and npm install
NeckerFree Jul 22, 2025
e2b5fac
renamed readme and cleanup
NeckerFree Jul 22, 2025
d4f9c3e
created dns for lb
NeckerFree Jul 22, 2025
6b8a2e7
Merge branch 'master' into simplify
NeckerFree Jul 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions .github/workflows/main.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/terraform-destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Terraform Destroy

on:
workflow_dispatch:
inputs:
confirm_destroy:
description: "⚠️ Type 'YES' to confirm destroying the infrastructure"
required: true

permissions:
contents: read
id-token: write

env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}

jobs:
destroy:
name: Terraform Destroy
runs-on: ubuntu-latest

steps:
- name: 🛑 Validate confirmation input
if: ${{ github.event.inputs.confirm_destroy != 'YES' }}
run: |
echo "You must type YES to proceed with destroy."
exit 1

- name: 📦 Checkout code
uses: actions/checkout@v3

- name: ⚙️ Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.0

- name: 🔐 Azure Login with Service Principal
uses: azure/login@v1
with:
creds: >-
{
"clientId": "${{ secrets.ARM_CLIENT_ID }}",
"clientSecret": "${{ secrets.ARM_CLIENT_SECRET }}",
"subscriptionId": "${{ secrets.ARM_SUBSCRIPTION_ID }}",
"tenantId": "${{ secrets.ARM_TENANT_ID }}"
}

- name: 🧪 Verify Azure login
run: az account show

- name: 📥 Terraform Init
run: |
terraform -chdir=infra init \
-backend-config="resource_group_name=soft-tfstate-rg" \
-backend-config="storage_account_name=softsastate" \
-backend-config="container_name=tfstate" \
-backend-config="key=terraform.tfstate"

- name: ⚠️ Terraform Destroy
run: |
terraform -chdir=infra destroy -auto-approve -input=false \
-var="subscription_id=${{ secrets.ARM_SUBSCRIPTION_ID }}" \
-var="client_id=${{ secrets.ARM_CLIENT_ID }}" \
-var="client_secret=${{ secrets.ARM_CLIENT_SECRET }}" \
-var="tenant_id=${{ secrets.ARM_TENANT_ID }}" \
-var="allowed_ssh_ip=${{ secrets.MY_IP_ADDRESS }}" \
-var="mysql_user=${{ secrets.MYSQL_USER }}" \
-var="mysql_admin_password=${{ secrets.MYSQL_ADMIN_PASSWORD }}" \
-var="ssh_public_key=${{ secrets.VM_SSH_PUB_KEY }}"
140 changes: 111 additions & 29 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,51 +106,133 @@ jobs:
if: github.ref == 'refs/heads/master'
run: terraform -chdir=infra apply -auto-approve -input=false -var-file=terraform.tfvars

# - name: 📄 Generate Terraform outputs
# run: |
# terraform -chdir=infra output -json > infra/tf_outputs.json
# echo "✅ tf_outputs.json generated"

- name: 📄 Generate Terraform outputs
run: |
terraform -chdir=infra output -json > infra/tf_outputs.json

# cat infra/tf_outputs.json
# echo "Trying to extract IP:"
# jq -r '.control_node_public_ip' infra/tf_outputs.json
"$TERRAFORM_CLI_PATH/terraform-bin" -chdir=infra output -json > infra/tf_outputs.json

# - name: 🐛 Debug Terraform outputs
# run: |
# cat infra/tf_outputs.json

- name: 📦 Upload inventory.ini as artifact
uses: actions/upload-artifact@v4
with:
name: inventory
path: ansible/inventory.ini

- name: 🔑 Configure SSH for jumpbox
- name: 📤 Export Terraform outputs to GitHub ENV
run: |
mkdir -p ~/.ssh
echo "${{ secrets.VM_SSH_KEY }}" > ~/.ssh/vm_ssh_key
chmod 600 ~/.ssh/vm_ssh_key
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
echo "📥 Exporting variables to GitHub ENV..."
echo "APP_SERVICE_NAME=$(jq -r '.app_service_name.value' infra/tf_outputs.json)" >> $GITHUB_ENV
echo "RESOURCE_GROUP_NAME=$(jq -r '.resource_group_name.value' infra/tf_outputs.json)" >> $GITHUB_ENV
echo "LB_API_URL=$(jq -r '.lb_api_url.value' infra/tf_outputs.json)" >> $GITHUB_ENV
echo "LB_API_PORT=$(jq -r '.api_public_port.value' infra/tf_outputs.json)" >> $GITHUB_ENV

- name: 🚀 Upload Inventory to Jumpbox
- name: 🔧 Compose LB API URL
run: |
echo "LB_API_URL=${LB_API_URL}:${LB_API_PORT}" >> $GITHUB_ENV

- name: 🗃️ Run Script Configure Jumpbox
run: |
chmod +x ./ansible/configure-jumpbox.sh

# Get outputs from Terraform
JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip 2>/dev/null | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | tail -n1)
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user 2>/dev/null | grep -Eo '^[a-zA-Z0-9]+' | tail -n1)
JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | tail -n1)
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user | grep -Eo '^[a-zA-Z0-9]+' | tail -n1)

# Log and validate
echo "JUMP_HOST: $JUMP_HOST"
echo "JUMP_USER: $JUMP_USER"
SSH_KEY_CONTENT="${{ secrets.VM_SSH_KEY }}"
ANSIBLE_DIR=./ansible
REMOTE_DIR=/home/${JUMP_USER}/ansible-setup
./ansible/configure-jumpbox.sh "$JUMP_HOST" "$JUMP_USER" "$SSH_KEY_CONTENT" "$ANSIBLE_DIR" "$REMOTE_DIR"

if [[ -z "$JUMP_HOST" || -z "$JUMP_USER" ]]; then
echo "❌ Terraform outputs not found!"
- name: 🛢️ Run Script Deploy Database
run: |
chmod +x ./ansible/deploy-db-from-local.sh
# ✅ Ejecuta y guarda el resultado de terraform output
# Get clean DB_HOST - Ultimate reliable method
DB_HOST=$(terraform -chdir=infra output -raw mysql_fqdn 2>&1 | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
# echo "Extracted DB_HOST='$DB_HOST'"

# Fallback if raw output fails
if [ -z "$DB_HOST" ]; then
DB_HOST=$(terraform -chdir=infra output mysql_fqdn | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
# echo "Fallback extracted DB_HOST='$DB_HOST'"
fi

# Final validation
if [[ ! "$DB_HOST" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
echo "ERROR: Could not extract valid DB_HOST"
echo "Raw terraform output:"
terraform -chdir=infra output mysql_fqdn
exit 1
fi
DB_USER="${{ secrets.MYSQL_USER }}"
DB_PASS="${{ secrets.MYSQL_ADMIN_PASSWORD }}"
DB_NAME="movie_analyst"

JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | tail -n1)
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user | grep -Eo '^[a-zA-Z0-9]+' | tail -n1)

./ansible/deploy-db-from-local.sh "$DB_HOST" "$DB_USER" "$DB_PASS" "$DB_NAME" "$JUMP_HOST" "$JUMP_USER"

- name: 🧩 Run Script Deploy API from Jumpbox to VMs
run: |
chmod +x ./ansible/deploy-api-jumpbox-to-vms.sh

# Get clean DB_HOST - Ultimate reliable method
DB_HOST=$(terraform -chdir=infra output -raw mysql_fqdn 2>&1 | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
# echo "Extracted DB_HOST='$DB_HOST'"

# Fallback if raw output fails
if [ -z "$DB_HOST" ]; then
DB_HOST=$(terraform -chdir=infra output mysql_fqdn | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
# echo "Fallback extracted DB_HOST='$DB_HOST'"
fi

# Final validation
if [[ ! "$DB_HOST" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
echo "ERROR: Could not extract valid DB_HOST"
echo "Raw terraform output:"
terraform -chdir=infra output mysql_fqdn
exit 1
fi

# Create remote directory
ssh -i ~/.ssh/vm_ssh_key -o StrictHostKeyChecking=no ${JUMP_USER}@${JUMP_HOST} \
"mkdir -p /home/${JUMP_USER}/ansible-setup"
JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | tail -n1)
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user | grep -Eo '^[a-zA-Z0-9]+' | tail -n1)


DB_USER="${{ secrets.MYSQL_USER }}"
DB_PASS="${{ secrets.MYSQL_ADMIN_PASSWORD }}"
DB_NAME="movie_analyst"

# Upload inventory
scp -i ~/.ssh/vm_ssh_key -o StrictHostKeyChecking=no \
./ansible/inventory.ini \
${JUMP_USER}@${JUMP_HOST}:/home/${JUMP_USER}/ansible-setup/inventory.ini
# echo "=== Final Variables ==="
# echo "DB_HOST: $DB_HOST"
# echo "JUMP_HOST: $JUMP_HOST"
# echo "JUMP_USER: $JUMP_USER"

# Verify upload
ssh -i ~/.ssh/vm_ssh_key -o StrictHostKeyChecking=no ${JUMP_USER}@${JUMP_HOST} \
"ls -la /home/${JUMP_USER}/ansible-setup/"
./ansible/deploy-api-jumpbox-to-vms.sh "$DB_HOST" "$DB_USER" "$DB_PASS" "$DB_NAME" "$JUMP_HOST" "$JUMP_USER"

- name: Deploy Frontend
run: |
chmod +x ./ansible/deploy-frontend.yml
echo "Using values:"
echo "APP_SERVICE_NAME=$APP_SERVICE_NAME"
echo "RESOURCE_GROUP_NAME=$RESOURCE_GROUP_NAME"
echo "LB_API_URL=$LB_API_URL"
ansible-playbook ansible/deploy-frontend.yml -i localhost,
env:
APP_SERVICE_NAME: ${{ env.APP_SERVICE_NAME }}
RESOURCE_GROUP_NAME: ${{ env.RESOURCE_GROUP_NAME }}
LB_API_URL: ${{ env.LB_API_URL }}

- name: 🌐 Show frontend URL
run: |
echo "✅ Your frontend is deployed and available at:"
echo "https://${APP_SERVICE_NAME}.azurewebsites.net"
env:
APP_SERVICE_NAME: ${{ env.APP_SERVICE_NAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ infra/.terraform.lock.hcl
*node_modules/*
docs/query.txt
infra/import-resources.bat
docs/tests.txt
Loading
Loading