1+ #! /bin/bash
2+ ENV_FILE=" ${1:- .env.prod} "
3+
4+ if [ ! -f " $ENV_FILE " ]; then
5+ echo " Environment file $ENV_FILE not found!"
6+ exit 1
7+ fi
8+
9+ # Add Docker’s official GPG Key:
10+ echo " Adding Docker's official GPG key..."
11+ sudo apt update
12+ sudo apt install ca-certificates curl
13+ sudo install -m 0755 -d /etc/apt/keyrings
14+ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
15+ sudo chmod a+r /etc/apt/keyrings/docker.asc
16+
17+ # Add the repository to apt sources:
18+ echo " Adding Docker's official repository..."
19+ sudo tee /etc/apt/sources.list.d/docker.sources << EOF
20+ Types: deb
21+ URIs: https://download.docker.com/linux/ubuntu
22+ Suites: $( . /etc/os-release && echo " ${UBUNTU_CODENAME:- $VERSION_CODENAME } " )
23+ Components: stable
24+ Architectures: $( dpkg --print-architecture)
25+ Signed-By: /etc/apt/keyrings/docker.asc
26+ EOF
27+
28+ sudo apt update
29+
30+ # Install Docker packages:
31+ echo " Installing Docker packages..."
32+ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
33+
34+ # Verify installation:
35+ if systemctl is-active --quiet docker; then
36+ echo " Docker is installed and running."
37+ else
38+ echo " Docker installation failed or Docker is not running."
39+ echo " Starting Docker..."
40+ sudo systemctl start docker
41+ if systemctl is-active --quiet docker; then
42+ echo " Docker started successfully."
43+ else
44+ echo " Failed to start Docker. Please check the installation and try again."
45+ exit 1
46+ fi
47+ fi
48+
49+ echo " Adding ubuntu user to the docker group..."
50+ sudo usermod -aG docker ubuntu
51+
52+ echo " Installing git..."
53+ sudo apt install git -y
54+
55+ echo " Creating TEKDB directory and cloning repository..."
56+ mkdir tekdb
57+ cd tekdb
58+ git clone https://github.com/Ecotrust/TEKDB.git
59+
60+ # TODO: change to the main branch once the develop branch is merged into main!!
61+ echo " Checking out the develop branch..."
62+ cd TEKDB
63+ git checkout develop
64+ git pull origin develop
65+
66+ echo " Moving the .env.prod file to the Docker directory..."
67+ mv $ENV_FILE docker/.env.prod
68+
69+ echo " Pulling the latest Docker image..."
70+ docker pull ghcr.io/ecotrust/tekdb/web:latest
71+
72+ echo " Starting the Docker containers..."
73+ docker compose --env-file docker/.env.prod -f docker/docker-compose.prod.local.yaml up -d
74+
75+ echo " Verifying that the containers are running..."
76+ if [ " $( docker container inspect -f ' {{.State.Status}}' " tekdb_web" 2> /dev/null) " = " running" ]; then
77+ echo " TEKDB containers are running successfully."
78+ else
79+ echo " Failed to start TEKDB containers. Please check the Docker logs for more information."
80+ exit 1
81+ fi
82+ exit 0
0 commit comments