Skip to content

Commit

Permalink
Solution0.97
Browse files Browse the repository at this point in the history
  • Loading branch information
Serveladik committed Sep 19, 2024
1 parent 9b9fce4 commit 5902706
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
42 changes: 19 additions & 23 deletions install-app.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
#!/bin/bash

# Update and install python3-pip
# Script to silently install and start the todo web app on the virtual machine.
# Note that all commands bellow are without sudo - that's because extention mechanism
# runs scripts under root user.

# install system updates and isntall python3-pip package using apt. '-yq' flags are
# used to suppress any interactive prompts - we won't be able to confirm operation
# when running the script as VM extention.
sudo apt-get update -yq
sudo apt-get install python3-pip -yq

# Create a directory for the app if it doesn't exist
if [ ! -d /home/azureuser/app ]; then
sudo mkdir /home/azureuser/app
fi
# Create a directory for the app and download the files.
sudo mkdir /home/azureuser/app

# Change ownership of directories
sudo chown -R azureuser:azureuser /home/azureuser/devops_todolist_terraform_task
sudo chown -R azureuser:azureuser /home/azureuser/app
# sudo chmod 644 /home/azureuser/app/start.sh

# Copy files to the app directory
if [ -d /home/azureuser/devops_todolist_terraform_task/app ]; then
sudo cp -r /home/azureuser/devops_todolist_terraform_task/app/* /home/azureuser/app
else
echo "Source directory /home/azureuser/devops_todolist_terraform_task/app does not exist."
exit 1
fi
# make sure to uncomment the line bellow and update the link with your GitHub username
# git clone https://github.com/<your-gh-username>/azure_task_12_deploy_app_with_vm_extention.git
cp -r /home/azureuser/devops_todolist_terraform_task/app/* /home/azureuser/app

# Move and enable the service
if [ -f /home/azureuser/app/todoapp.service ]; then
sudo mv /home/azureuser/app/todoapp.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start todoapp
sudo systemctl enable todoapp
else
echo "Service file /home/azureuser/app/todoapp.service does not exist."
exit 1
fi
# create a service for the app via systemctl and start the app
sudo mv /home/azureuser/app/todoapp.service /etc/systemd/system/
sudo chmod 644 /etc/systemd/system/todoapp.service
sudo systemctl daemon-reload
sudo systemctl start todoapp
sudo systemctl enable todoapp
15 changes: 11 additions & 4 deletions modules/compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ resource "azurerm_virtual_machine_extension" "custom_script" {
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.1"
settings = jsonencode({
fileUris = ["https://raw.githubusercontent.com/Serveladik/devops_todolist_terraform_task/main/install-app.sh"]
commandToExecute = "bash install-app.sh"
})

settings = <<SETTINGS
{
"fileUris": ["https://raw.githubusercontent.com/Serveladik/devops_todolist_terraform_task/main/install-app.sh"],
"commandToExecute": "bash install-app.sh"
}
SETTINGS

tags = {
environment = "Production"
}
}
Binary file modified tfplan
Binary file not shown.

0 comments on commit 5902706

Please sign in to comment.