Dockerized version of FPMA
FPMA is containerized using Docker-compose, which allows it to be deployed on any UNIX-based machine.
Main components of the tool
- PostgreSQL DB: This component handles the database functionality.
- Django backend: The Django backend serves as the core of the FPMA tool.
- Angular frontend: The Angular frontend provides the user interface for the tool.
Docker services
| Docker Service | Description |
|---|---|
| Web Service | This service runs the Django backend using Gunicorn as the server |
| DB Service | The DB service runs the PostgreSQL DB, which is responsible for data storage |
| Redis Service | This service runs the Redis service, enabling caching functionality |
| Celery Services | The Celery services consist of the Celery worker and Celery beat, which handle periodic tasks |
| Frontend Service | This service runs the Angular frontend, facilitating the user interaction |
| Nginx Service | The Nginx service runs an Nginx host with the appropriate configurations to ensure smooth operation |
Initial Configurations
To initiate the Docker container, it is essential to ensure that Docker and GCloud SDK are correctly installed and operational.
Verify Docker Installation
Run the following commands to ensure Docker is installed correctly:
which docker
docker --version
which docker-compose
docker-compose --version
The versions tested and known to work correctly. are as follows
Docker version 20.10.x
docker-compose version 1.29.x
Google Cloud Permissions
Ensure that you have the necessary permissions to pull from Google Cloud Container Registry (GCR) and Cloud Storage. Log in using your Google account, and proceed with the following commands to link Docker with Google Cloud.
gcloud auth application-default login
gcloud auth configure-docker
Make sure you inform us at fpma@fao.org with the email address you intend to use so that we can grant you all neccessary permissions from our side.
Node.js and npm
Ensure you have the following installed on your system:
- Node.js (version 12 or higher). Tested version:
$ node --version
v18.18.0
- npm (Node Package Manager, usually comes with Node.js). Tested version:
$ npm --version
9.8.1
Startup Script
Copy the startup.sh script from below or from this link.
The startup.sh script is a self-updating script that will fetch its own code from our servers then execute it.
After it pulls the updates, it will create a directory called scripts in the same directory that the startup script is located.
The scripts directory contains a NodeJS app that will take care of all the process for you through an intuitive CLI interface.
#!/bin/bash
# Color Definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
SCRIPT_NAME='startup.sh'
FPMA_SCRIPT="./$SCRIPT_NAME"
CLOUD_BUCKET_PATH='gs://fao-fpma-docker-scripts'
# Check gsutil Installation
check_gsutil() {
if [[ $(which gsutil) && $(gsutil --version) ]]; then
printf "${GREEN}gsutil installation verified${YELLOW}\n"
which gsutil
gsutil --version
printf "${NC}"
else
printf "${RED}Error. Please make sure that gsutil is properly installed.\n${NC}"
exit
fi
}
# Function to self-update the script
self_update() {
if test -f "$FPMA_SCRIPT"; then
printf '\nBacking up old script...\n'
mv "$FPMA_SCRIPT" "$FPMA_SCRIPT.$(date +'%Y%m%d%H%M')"
fi
printf '\nPulling latest script...\n'
gsutil cp $CLOUD_BUCKET_PATH/"$SCRIPT_NAME" "$FPMA_SCRIPT.temp"
if ! test -f "$FPMA_SCRIPT.temp"; then
printf "${RED}Error downloading the script.\n${NC}"
if test -f "$FPMA_SCRIPT.$(date +'%Y%m%d%H%M')"; then
printf "Restoring backup...\n"
mv "$FPMA_SCRIPT.$(date +'%Y%m%d%H%M')" "$FPMA_SCRIPT"
fi
exit 1 # Exit with an error code to indicate failure
fi
# At this point, the download was successful
printf '\nGranting permissions...\n'
chmod +x "$FPMA_SCRIPT.temp"
printf '\nReplacing the script with the updated version...\n'
mv "$FPMA_SCRIPT.temp" "$FPMA_SCRIPT"
# Cleanup: Delete all backups
printf '\nCleaning up backups...\n'
rm -f "$FPMA_SCRIPT".*
printf '\nUpdate completed.\n'
source "$FPMA_SCRIPT" noupdate
}
# Check Docker Installation
check_docker() {
if [[ $(which docker) && $(docker --version) && $(which docker-compose) && $(docker-compose --version) ]]; then
printf "${GREEN}Docker installation verified${YELLOW}\n"
which docker
docker --version
which docker-compose
docker-compose --version
printf "${NC}"
else
printf "${RED}Docker is not properly installed. Please visit https://docs.docker.com/engine/install/${NC}\n"
exit
fi
}
if [[ $1 != "noupdate" ]]; then
check_gsutil
self_update
exit
fi
check_docker
Copy the script code and save it as startup.sh in an empty directory of your choice.
Grant executable permissions to the script using the following command:
cd /path/to/script/
chmod +x ./startup.sh
To run the script:
./startup.sh