-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-deploy.sh
More file actions
64 lines (51 loc) · 1.68 KB
/
auto-deploy.sh
File metadata and controls
64 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
echo "--- NextbikeSearch Deployment Script ---"
# 1. Detect Distribution and Install Dependencies
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
echo "Could not detect OS. Exiting."
exit 1
fi
echo "Step #1: Installing tools for $OS..."
case "$OS" in
ubuntu|debian|raspbian)
sudo apt update
sudo apt install -y git docker.io wget
;;
fedora)
sudo dnf install -y git docker wget
;;
arch|cachyos)
sudo pacman -Sy --noconfirm git docker wget
;;
*)
echo "Unsupported distribution: $OS"
exit 1
;;
esac
# Start and enable Docker (so it survives a reboot)
sudo systemctl enable --now docker
# 2. User Input
read -p "Enter the host port (e.g., 8080): " port
read -p "Enter the container name: " name
# 3. Setup Workspace
echo "Step #2: Preparing Dockerfile..."
mkdir -p nextbikesearch
cd nextbikesearch
wget -q https://raw.githubusercontent.com/construktdev/nextbikesearch/refs/heads/main/Dockerfile -O ./Dockerfile
# 4. Build and Run
echo "Step #3: Building Docker Image..."
sudo docker build --tag construkter/nextbikesearch:latest .
echo "Step #4: Starting Container '$name' on port $port..."
# Check if a container with that name already exists and remove it to avoid errors
if [ "$(sudo docker ps -aq -f name=$name)" ]; then
echo "Removing existing container with name $name..."
sudo docker rm -f $name
fi
sudo docker run --detach --name "$name" --publish "$port":80 construkter/nextbikesearch:latest
echo "------------------------------------------------"
echo "DONE! Visit http://localhost:$port"