Automating Setup with a Bash Script

🚀 What This Script Does

✅ setup.sh

#!/bin/bash

# Exit immediately on error
set -e

echo "🔄 Updating system packages..."
sudo apt update && sudo apt upgrade -y

echo "🐙 Installing Git..."
sudo apt install -y git

echo "🐳 Installing Docker..."
sudo apt install -y docker.io

echo "🧱 Installing Docker Compose..."
sudo apt install -y docker-compose

echo "📁 Cloning your GitHub repo..."
git clone https://github.com/arduino731/DevOps-Linux-System-Admin.git
cd DevOps-Linux-System-Admin

echo "🚀 Building and running Docker containers..."
docker compose up -d --build

echo "✅ Setup complete! Frontend running on http://localhost:8080 and backend on http://localhost:5001"

💡 Instructions

Save as setup.sh, then run:

chmod +x setup.sh
./setup.sh

⚠️ Requirements

Your repo must contain a docker-compose.yml that defines:

✅ docker-compose.yml

services:
  frontend:
    build:
      context: ./frontend
    ports:
      - "8080:80"
    volumes:
      - ./frontend/public:/usr/share/nginx/html
    container_name: frontend_container

  backend:
    build:
      context: ./backend
    ports:
      - "5001:5001"
    container_name: backend_container

📁 Expected Directory Structure

DevOps-Linux-System-Admin/
├── setup.sh
├── docker-compose.yml
├── frontend/
│   ├── Dockerfile
│   └── public/
│       └── index.html
└── backend/
    ├── Dockerfile
    └── app.js

✅ frontend/Dockerfile

FROM nginx:alpine
COPY public/ /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

✅ backend/Dockerfile

FROM node:22-alpine
WORKDIR /usr/src/app
COPY . .
RUN npm install
EXPOSE 5001
CMD ["node", "app.js"]

✅ Example backend/app.js

const express = require('express');
const app = express();
const port = 5001;

app.get('/', (req, res) => {
  res.send('Hello from the backend!');
});

app.listen(port, () => {
  console.log(`Backend is running on http://localhost:${port}`);
});