Skip to content

Commit

Permalink
feat: updated installation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvanr committed Aug 22, 2024
1 parent fca4628 commit 122261d
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 209 deletions.
25 changes: 23 additions & 2 deletions direct_indexing/solr/update_solr_cores.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ if [ "$EUID" -ne 0 ]
exit
fi

# Function to prompt user for Y/n choice
ask_for_confirmation() {
read -rp "$1 (Y/n): " choice
case "$choice" in
""|y|Y )
return 0 # Default to Y if user presses Enter without typing anything
;;
n|N )
return 1
;;
* )
ask_for_confirmation "$1" # Ask again if input is not recognized
;;
esac
}

# Ask the user if they are sure they want to copy these schemas, if not exit
read -p "Are you sure you want to copy the schemas? (y/N) " -n 1 -r
echo # (optional) move to a new line
Expand Down Expand Up @@ -32,7 +48,12 @@ docker cp ./direct_indexing/solr/cores/transaction/managed-schema $solr_containe
docker cp ./direct_indexing/solr/cores/activity/xslt $solr_container_id:/bitnami/solr/server/solr/activity/conf/

# Ask the user if this is mounted locally, default to no. If it is, chown the files to 1001:root
read -p "Is this mounted locally? (y/N) " -n 1 -r

if ask_for_confirmation "Are the files locally mounted (f.ex. on extra mounted volume)?"; then
df -h
read -p "Enter your mounted directory: " mounted_dir
sudo chown -R 1001:root $mounted_dir/solr_data/
else
echo "Skipping mounted solr directory."
fi

echo "Done!"
20 changes: 0 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,6 @@ services:
ports:
- 5555:5555

nginx:
container_name: nginx
image: iaticloud/nginx
env_file:
- .env
build:
context: ./services/nginx
args:
- IC_DOMAIN=${IC_DOMAIN}
- SOLR_AUTH_ENCODED=${SOLR_AUTH_ENCODED}
volumes:
- ./:/app
- ./static:/static
ports:
- 80:80
depends_on:
- celeryflower
- iaticloud
- solr

volumes:
db_data:
rabbitmq_data:
Expand Down
3 changes: 3 additions & 0 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Please check out the [reference of .env under the local docs](./LOCAL.md#env). T
| nginx | nginx | 80 | ./services/nginx | Runs NGINX and enables the flower and datastore subdomains for a provided domain. For local development it also allows subdomains. Customize `SOLR_AUTH_ENCODED` and `IC_DOMAIN`. iati.cloud-redirect is available but not enabled by default. The docker image is more described [here](../services/nginx/NGINX.md). |

## Running
We recommend using the `./scripts/setup.sh` script to get everything set up for you, then running `sudo docker compose up -d` to start the required processes.

### Old installation steps
We use a git submodule to ensure the Django static is set up correctly. Run the following to prepare to use that submodule:
```
git submodule init
Expand Down
26 changes: 26 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Help
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Used to (re)build services running through docker. Optionally specify service names."
echo ""
echo "Usage: bash $0 [service name (optional) (up to 10 service names)]"
exit 0
fi

# Start
# Get additional arguments (service names)
I1="$1"
I2="$2"
I3="$3"
I4="$4"
I5="$5"
I6="$6"
I7="$7"
I8="$8"
I9="$9"
I10="$10"

sudo docker compose build $I1 $I2 $I3 $I4 $I5 $I6 $I7 $I8 $I9 $I10

echo "Build script is done. You can now start the services using the './scripts/start.sh $MODE' script."
80 changes: 80 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Help
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Used to set up the repository. Specify the environment type."
echo "Optionally initialises git submodules and their setups."
echo "Removes any .env file, and creates a copy of .env.example with the appropriate name, then symlinks it to .env."
echo "Optionally prepopulates DX with data"
echo ""
echo "Usage: . $0"
exit 0
fi

# Function to prompt user for Y/n choice
ask_for_confirmation() {
read -rp "$1 (Y/n): " choice
case "$choice" in
""|y|Y )
return 0 # Default to Y if user presses Enter without typing anything
;;
n|N )
return 1
;;
* )
ask_for_confirmation "$1" # Ask again if input is not recognized
;;
esac
}

echo ""
echo ""
if ask_for_confirmation "Do you want to install Docker?"; then
. ./scripts/setup/install_docker.sh
else
echo "Skipping Docker installation."
fi

echo ""
echo ""
if ask_for_confirmation "Do you want to install NodeJS v16, npm and yarn?"; then
. ./scripts/setup/install_node.sh
else
echo "Skipping NodeJS, npm and yarn installation."
fi

echo ""
echo ""
if ask_for_confirmation "Do you want to initialise the submodules?"; then
. ./scripts/setup/install_submodules.sh
else
echo "Skipping the submodules."
fi

echo ""
echo ""
if ask_for_confirmation "Do you want to set up the query builder?"; then
. ./scripts/setup/setup_iati_cloud_frontend.sh
else
echo "Skipping the Query Builder."
fi

echo ""
echo ""
if ask_for_confirmation "Do you want to install NGINX with SSL enabled?"; then
. ./scripts/setup/install_nginx.sh
else
echo "Skipping NGINX."
fi

echo ""
echo ""
if ask_for_confirmation "Do you want to set up Solr (must be done before stack can be activated)?"; then
. ./scripts/setup/setup_solr.sh
else
echo "Skipping NGINX."
fi

echo ""
echo ""
echo "Setup script is done, please set up your env, and run 'bash ./scripts/build.sh <MODE>' to build the project."
30 changes: 30 additions & 0 deletions scripts/setup/install_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

print_status() {
echo "
======================================================
Status Update
------------------------------------------------------
$1
======================================================
"
}

print_status "Installing Docker..."
# Copied from https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
print_status "Done installing Docker."
90 changes: 90 additions & 0 deletions scripts/setup/install_nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# Function to prompt user for Y/n choice
ask_for_confirmation() {
read -rp "$1 (Y/n): " choice
case "$choice" in
""|y|Y )
return 0 # Default to Y if user presses Enter without typing anything
;;
n|N )
return 1
;;
* )
ask_for_confirmation "$1" # Ask again if input is not recognized
;;
esac
}

print_status() {
echo "
======================================================
Status Update
------------------------------------------------------
$1
======================================================
"
}

if ask_for_confirmation "Do NGINX and Certbot need to be installed before setup?"; then
echo "Installing NGINX and Certbot..."
print_status "Installing NGINX..."
sudo apt update
sudo apt install nginx -y

print_status "Installing certbot..."
sudo apt install software-properties-common -y
sudo add-apt-repository universe -y
sudo apt-get update -y
sudo apt-get install certbot python3-certbot-nginx -y
else
echo "Skipping NGINX and Certbot installation."
fi

# Configure nginx

print_status "Setting up NGINX configuration..."
# Function to configure NGINX for a given environment

# datastore.iati.cloud
# Ask the user for the server name
read -rp "What is the iati.cloud server name as defined in the DNS records (for example, datastore.iati.cloud)?: " server_name
sudo cp ./scripts/setup/nginx_host_machine/iati.cloud "/etc/nginx/sites-available/iati-cloud"
sudo sed -i "s/REPL_SERVER_NAME/$server_name/g" "/etc/nginx/sites-available/iati-cloud"
read -p "Re-Enter your solr username: " username
read -sp "Re-Enter your solr password: " password
encoded_base64=$(echo -n "$username:$password" | base64)
sudo sed -i "s/REPL_AUTH/$encoded_base64/g" "/etc/nginx/sites-available/iati-cloud"
sudo ln -s "/etc/nginx/sites-available/iati-cloud" /etc/nginx/sites-enabled/

# flower
sudo cp ./scripts/setup/nginx_host_machine/flower "/etc/nginx/sites-available/flower"
sudo sed -i "s/REPL_SERVER_NAME/$server_name/g" "/etc/nginx/sites-available/flower"
sudo ln -s "/etc/nginx/sites-available/flower" /etc/nginx/sites-enabled/

if ask_for_confirmation "Do you want to set up the redirect for iati.cloud -> datastore.iati.cloud?: "; then
sudo cp ./scripts/setup/nginx_host_machine/iati.cloud-redirect "/etc/nginx/sites-available/iati-cloud-redirect"
sudo ln -s "/etc/nginx/sites-available/iati-cloud-redirect" /etc/nginx/sites-enabled/
fi

# Restart nginx
print_status "Restarting NGINX..."
sudo service nginx restart

print_status "Setting up SSL certificates..."
if ask_for_confirmation "Do you want to set up SSL certificates for your domains?"; then
# Set up the ssl certificate, this will require some user input.
echo "Setting up SSL certificates..."
sudo certbot --nginx

echo "Setting up cron job to renew SSL certificates..."
# update crontab with `0 5 1 * * sudo certbot renew --preferred-challenges http-01`
cron_command="0 5 1 * * sudo certbot renew --preferred-challenges http-01"
temp_cron_file=$(mktemp)
echo "$cron_command" > "$temp_cron_file"
crontab "$temp_cron_file"
rm "$temp_cron_file"
fi

print_status "Done installing NGINX."
Loading

0 comments on commit 122261d

Please sign in to comment.