「🏗️」 wip: work in progress, not done yet.
This commit is contained in:
10
Makefile
10
Makefile
@ -20,9 +20,17 @@ build-cms:
|
||||
start-db:
|
||||
docker compose up db --build
|
||||
|
||||
start-nginx:
|
||||
docker compose up nginx --build
|
||||
|
||||
|
||||
clean-db:
|
||||
docker stop inception-db
|
||||
docker container rm inception-db
|
||||
docker volume rm inception_wp-db
|
||||
|
||||
.PHONY: cms-build db-build websrv-build
|
||||
clean-nginx:
|
||||
docker stop inception-nginx
|
||||
docker container rm inception-nginx
|
||||
|
||||
.PHONY: cms-build db-build websrv-build clean-db clean-nginx
|
||||
|
@ -96,7 +96,7 @@ func checkOlderDB(dataDir string) bool {
|
||||
|
||||
func waitForMariaDB(rootPass string) {
|
||||
for i := 0; i < 30; i++ {
|
||||
cmd := exec.Command("mariadb", "-uroot", "-p"+escapePassword(rootPass), "-e", "SELECT 1")
|
||||
cmd := exec.Command("mariadb", "-uroot", "-p"+env.EscapeEnv(rootPass), "-e", "SELECT 1")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err == nil {
|
||||
@ -116,11 +116,6 @@ func waitForMariaDB(rootPass string) {
|
||||
// return fmt.Sprintf("%s", strings.ReplaceAll(identifier, "'", "\""))
|
||||
//}
|
||||
|
||||
func escapePassword(password string) string {
|
||||
// Escape single quotes in passwords
|
||||
new := strings.ReplaceAll(password, "\"", "")
|
||||
return strings.ReplaceAll(new, "'", "\\'")
|
||||
}
|
||||
|
||||
func configureMariaDB(rootPassword, user, password, database string) {
|
||||
cmd := exec.Command("mariadb", "-uroot", "-e", fmt.Sprintf(`
|
||||
@ -131,14 +126,14 @@ func configureMariaDB(rootPassword, user, password, database string) {
|
||||
GRANT ALL PRIVILEGES ON %s.* TO '%s'@'%%';
|
||||
FLUSH PRIVILEGES;
|
||||
`,
|
||||
escapePassword(rootPassword),
|
||||
escapePassword(database),
|
||||
escapePassword(user),
|
||||
escapePassword(database),
|
||||
escapePassword(user),
|
||||
escapePassword(password),
|
||||
escapePassword(database),
|
||||
escapePassword(user),
|
||||
env.EscapeEnv(rootPassword),
|
||||
env.EscapeEnv(database),
|
||||
env.EscapeEnv(user),
|
||||
env.EscapeEnv(database),
|
||||
env.EscapeEnv(user),
|
||||
env.EscapeEnv(password),
|
||||
env.EscapeEnv(database),
|
||||
env.EscapeEnv(user),
|
||||
))
|
||||
|
||||
// Capture standard output and error
|
||||
@ -189,7 +184,7 @@ func main() {
|
||||
|
||||
configureMariaDB(rootPass, user, pass, dbName)
|
||||
|
||||
cmd_stop := exec.Command("mariadb-admin", "-uroot", "-p"+escapePassword(rootPass), "shutdown")
|
||||
cmd_stop := exec.Command("mariadb-admin", "-uroot", "-p"+env.EscapeEnv(rootPass), "shutdown")
|
||||
cmd_stop.Stdout = os.Stdout
|
||||
cmd_stop.Stderr = os.Stderr
|
||||
if err := cmd_stop.Run(); err != nil {
|
||||
|
@ -1,5 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
)
|
@ -1,10 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"git.keyzox.me/42_adjoly/inception/internal/env"
|
||||
)
|
||||
@ -23,16 +22,10 @@ func checkMariaDB(user, password, host, port string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func escapePassword(password string) string {
|
||||
// Escape single quotes in passwords
|
||||
new := strings.ReplaceAll(password, "\"", "")
|
||||
return strings.ReplaceAll(new, "'", "\\'")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Configuration
|
||||
user := escapePassword(env.FileEnv("MYSQL_USER", "mariadb"))
|
||||
password := escapePassword(env.FileEnv("MYSQL_PASSWORD", "default"))
|
||||
user := env.EscapeEnv(env.FileEnv("MYSQL_USER", "mariadb"))
|
||||
password := env.EscapeEnv(env.FileEnv("MYSQL_PASSWORD", "default"))
|
||||
host := "127.0.0.1"
|
||||
port := "3306"
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
14
configs/nginx/wp.conf
Normal file
14
configs/nginx/wp.conf
Normal file
@ -0,0 +1,14 @@
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 'healthy';
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
@ -35,6 +35,8 @@ services:
|
||||
networks:
|
||||
- inception
|
||||
environment:
|
||||
- PHP_MEMORY_LIMIT="512M"
|
||||
- PHP_MAX_UPLOAD="50M"
|
||||
- TZ=Europe/Paris
|
||||
volumes:
|
||||
- wp-site:/var/www/html
|
||||
|
@ -13,12 +13,12 @@ RUN set -x \
|
||||
VOLUME /etc/nginx
|
||||
RUN mkdir -p /etc/nginx/sites-available
|
||||
|
||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||
RUN [ "chmod", "+x", "/docker-entrypoint.sh" ]
|
||||
COPY docker-healthcheck.sh /docker-healthcheck.sh
|
||||
RUN chmod +x /docker-healthcheck.sh
|
||||
|
||||
ENTRYPOINT [ "/docker-entrypoint.sh" ]
|
||||
WORKDIR /etc/nginx
|
||||
STOPSIGNAL SIGQUIT
|
||||
|
||||
EXPOSE 80
|
||||
CMD [ "nginx", "-g", "daemon off;" ]
|
||||
HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD /docker-healthcheck.sh
|
||||
|
@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
exec "$@"
|
3
docker/nginx/docker-healthcheck.sh
Normal file
3
docker/nginx/docker-healthcheck.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
curl -f http://localhost/health || exit 1
|
33
docker/nginx/nginx-health.conf
Normal file
33
docker/nginx/nginx-health.conf
Normal file
@ -0,0 +1,33 @@
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile on;
|
||||
access_log /var/log/nginx/access.log;
|
||||
keepalive_timeout 3000;
|
||||
server {
|
||||
listen 80;
|
||||
root /www;
|
||||
index index.php index.html index.htm;
|
||||
server_name localhost;
|
||||
client_max_body_size 32m;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /var/lib/nginx/html;
|
||||
}
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
}
|
||||
}
|
4
go.sum
4
go.sum
@ -1,4 +0,0 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
11
internal/env/env_util.go
vendored
11
internal/env/env_util.go
vendored
@ -2,6 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.keyzox.me/42_adjoly/inception/internal/log"
|
||||
)
|
||||
@ -32,3 +33,13 @@ func EnvCheck(Value, Default string) string {
|
||||
}
|
||||
return Default
|
||||
}
|
||||
|
||||
func EscapeEnv(str string) string {
|
||||
if str[0] == '"' && str[len(str) - 1] == '"' {
|
||||
return strings.TrimPrefix(strings.TrimSuffix(str, "\""), "\"")
|
||||
} else if str[0] == '"' && str[len(str) - 1] == '"' {
|
||||
return strings.TrimPrefix(strings.TrimSuffix(str, "'"), "'")
|
||||
} else {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user