-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·163 lines (136 loc) · 4.91 KB
/
init.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Set pod name
POD_NAME=devserver1
CONTAINER_ALIAS=${POD_NAME}-cont-
# Define ALl Ports to be used container:host
PORTS=(
"80:80" #Nginx
"8080:8080" #used default by laravel app
"5432:5432" #postgresql
"9000:9000" #PHP FPM
"11211:11211" # memcached
)
#FILE PATHS
NGINX_CONFIG_PATH=$(pwd)/config/nginx/config
PHP_CONFIG_PATH=$(pwd)/config/php/config
POSTGRE_DATA_PATH=$(pwd)/config/postgres #Bitnami
POSTGRE_CONFIG_PATH=$(pwd)/config/postgres/config
SOURCE_PATH=../sites
# Create necessary directories
mkdir -p ${NGINX_CONFIG_PATH}
mkdir -p ${PHP_CONFIG_PATH}
mkdir -p ${POSTGRE_DATA_PATH}
mkdir -p ${POSTGRE_CONFIG_PATH}
mkdir -p ${SOURCE_PATH}/html
# Create NGINX default.conf
cat <<EOF > ${NGINX_CONFIG_PATH}/default.conf
server {
listen 80; # Listen on port 80 for HTTP traffic
server_name localhost; # Server name or IP address
root /var/www/html; # Document root directory
index index.php index.html index.htm; # Default index files
location / {
try_files \$uri \$uri/ /index.php?\$query_string; # This ensures NGINX tries PHP if the file doesn't exist
}
# PHP-FPM handling
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass ${CONTAINER_ALIAS}php-fpm:9000; # Name of the PHP-FPM container and port (inside the pod)
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
## Sample template to support other PHP versions multiple
#location ~ \.php$ {
# include fastcgi_params;
# fastcgi_pass ${CONTAINER_ALIAS}php-fpm8.3:9000; # Name of the PHP-FPM container and port (inside the pod)
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
#}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
}
EOF
# Create custom PHP configuration files
cat <<EOF > ${PHP_CONFIG_PATH}/custom.ini
# Disable opcache in the container, if not PHP files are cached
opcache.enable=0
opcache.enable_cli=0
# Enable other Extensions
extension=pdo_pgsql
extension=memcached
display_errors = On
error_reporting = ~E_ALL
EOF
touch ${PHP_CONFIG_PATH}/php-fpm.conf
# Create a simple HTML page in src/html/index.html
cat <<EOF > ${SOURCE_PATH}/html/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello</title>
</head>
<body>
<h1>Greetings from PODMAN Container</h1>
</body>
</html>
EOF
# Create a simple PHP page in src/html/index.php
cat <<EOF > ${SOURCE_PATH}/html/index.php
<?php
echo "Greetings from PODMAN Container (PHP is Running!)";
//phpinfo();
?>
EOF
# Create the Pod with the PORTS
# Port 74784 will be used for PHP-FPM socket to parse php-8.4
# Add ports here if you plan to support multiple PHP 74783 is added also
# Create the pod with the ports
POD_CREATE_CMD="podman pod create --name ${POD_NAME}"
for PORT in "${PORTS[@]}"; do
POD_CREATE_CMD+=" -p $PORT"
done
# Execute the command
echo "Executing: $POD_CREATE_CMD"
eval "$POD_CREATE_CMD"
# Adjust for Rootless Podman and ports < 1024
sudo sysctl net.ipv4.ip_unprivileged_port_start=80
# Create PostgreSQL Container BITNAMI
#podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}postgres \
# -v ${POSTGRE_DATA_PATH}:/bitnami/postgresql \
# -e POSTGRES_USER=user \
# -e POSTGRES_PASSWORD=pass \
# -e POSTGRES_DB=mydatabase \
# bitnami/postgresql
podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}postgres \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=pass \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v ${POSTGRE_DATA_PATH}:/var/lib/postgresql/data \
postgres
# Create PHP-FPM Container for PHP Latest version, bind to port 9000
#podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}php-fpm \
# --mount type=bind,source=${SOURCE_PATH},target=/var/www,bind-propagation=rshared \
# --mount type=bind,source=${PHP_CONFIG_PATH},target=/opt/bitnami/php/etc/conf.d,bind-propagation=rshared \
# bitnami/php-fpm
## Create PHP-FPM container for a specific php version
## https://hub.docker.com/r/bitnami/php-fpm
podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}php-fpm8.3 \
--mount type=bind,source=${SOURCE_PATH},target=/var/www,bind-propagation=rshared \
--mount type=bind,source=${PHP_CONFIG_PATH},target=/opt/bitnami/php/etc/conf.d,bind-propagation=rshared \
bitnami/php-fpm:8.3
# Create Nginx Container
podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}nginx \
-v ${NGINX_CONFIG_PATH}:/etc/nginx/conf.d \
-v ${SOURCE_PATH}/html:/usr/share/nginx/html \
-v ${SOURCE_PATH}:/var/www \
nginx
# Create Node.js Container
podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}nodejs \
-v ${SOURCE_PATH}:/var/www \
node:latest tail -f /dev/null
# Create Memcached Container
podman run -d --pod ${POD_NAME} --name ${CONTAINER_ALIAS}memcached memcached