|
1 | 1 | # Makefile to facilitate the use of Docker in the exelearning-web project
|
2 | 2 |
|
3 |
| -# Get the host IP (works for Unix/macOS, adjust for Windows if needed) |
4 |
| -# HOST_IP = $(shell hostname -I | awk '{print $$1}') |
5 |
| -# Get the host IP using ifconfig (for macOS/Linux) |
6 |
| -HOST_IP = $(shell ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $$2}' |
7 |
| -
|
8 |
| -# Detect the operating system |
| 3 | +# Detect the operating system and shell environment |
9 | 4 | ifeq ($(OS),Windows_NT)
|
10 |
| - # We are on Windows |
11 |
| - ifdef MSYSTEM |
12 |
| - # MSYSTEM is defined, we are in MinGW or MSYS |
13 |
| - SYSTEM_OS := unix |
14 |
| - else ifdef CYGWIN |
15 |
| - # CYGWIN is defined, we are in Cygwin |
16 |
| - SYSTEM_OS := unix |
17 |
| - else |
18 |
| - # Not in MinGW or Cygwin |
19 |
| - SYSTEM_OS := windows |
20 |
| - endif |
| 5 | + # Initially assume Windows shell |
| 6 | + SHELLTYPE := windows |
| 7 | + # Check if we are in Cygwin or MSYS (e.g., Git Bash) |
| 8 | + ifdef MSYSTEM |
| 9 | + SHELLTYPE := unix |
| 10 | + else ifdef CYGWIN |
| 11 | + SHELLTYPE := unix |
| 12 | + endif |
21 | 13 | else
|
22 |
| - # Not Windows, assuming Unix |
23 |
| - SYSTEM_OS := unix |
24 |
| -endif |
25 |
| - |
26 |
| -# Get the host IP based on the operating system |
27 |
| -ifeq ($(SYSTEM_OS),windows) |
28 |
| - # For Windows, use ipconfig and findstr to extract the IP |
29 |
| - HOST_IP := $(shell for /F "tokens=2 delims=[]" %i in ('ping -n 1 -4 %COMPUTERNAME%') do @echo %i) |
30 |
| -else |
31 |
| - # For Unix-like systems, use ifconfig or ip (adjust for macOS/Linux) |
32 |
| - ifeq ($(shell uname), Darwin) |
33 |
| - # For macOS, use ipconfig |
34 |
| - HOST_IP := $(shell ipconfig getifaddr en0) |
35 |
| - else |
36 |
| - # For Linux, use ifconfig or ip to get the IP address |
37 |
| - HOST_IP := $(shell hostname -I | cut -d' ' -f1) |
38 |
| - endif |
| 14 | + SHELLTYPE := unix |
39 | 15 | endif
|
40 | 16 |
|
41 | 17 | # Check if Docker is running
|
42 | 18 | # This target verifies if Docker is installed and running on the system.
|
43 | 19 | check-docker:
|
44 |
| -ifeq ($(SYSTEM_OS),windows) |
| 20 | +ifeq ($(SHELLTYPE),windows) |
45 | 21 | @echo "Detected system: Windows (cmd, powershell)"
|
46 | 22 | @docker version > NUL 2>&1 || (echo. & echo Error: Docker is not running. Please make sure Docker is installed and running. & echo. & exit 1)
|
47 | 23 | else
|
|
52 | 28 | # Check if the .env file exists, if not, copy from .env.dist
|
53 | 29 | # This target ensures that the .env file is present by copying it from .env.dist if it doesn't exist.
|
54 | 30 | check-env:
|
55 |
| -ifeq ($(SYSTEM_OS),windows) |
| 31 | +ifeq ($(SHELLTYPE),windows) |
56 | 32 | @if not exist .env ( \
|
57 | 33 | echo The .env file does not exist. Copying from .env.dist... && \
|
58 | 34 | copy .env.dist .env \
|
|
64 | 40 | fi
|
65 | 41 | endif
|
66 | 42 |
|
67 |
| -# Show the host ip address |
68 |
| -ip: |
69 |
| - @echo "The host ip address is: ${HOST_IP}" |
70 |
| - |
71 | 43 | # Start Docker containers in interactive mode
|
72 | 44 | # This target builds and starts the Docker containers, allowing interaction with the terminal.
|
73 | 45 | up: check-docker
|
74 |
| - HOST_IP=$(HOST_IP) docker compose up --build |
| 46 | + docker compose up --build |
75 | 47 |
|
76 | 48 | # Start Docker containers in background mode (daemon)
|
77 | 49 | # This target builds and starts the Docker containers in the background.
|
78 | 50 | upd: check-docker
|
79 |
| - HOST_IP=$(HOST_IP) docker compose up -d |
| 51 | + docker compose up -d |
80 | 52 |
|
81 | 53 | # Stop and remove Docker containers
|
82 | 54 | # This target stops and removes all running Docker containers.
|
|
0 commit comments