From f48c98da5a458f841d53fb746eee55e5265279e0 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 7 Feb 2025 18:00:30 +0100 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20Started=20re=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 45 ++-------- srcs/cmd/mariadb/healthcheck/healthcheck.go | 2 +- srcs/docker-compose-prod.yml | 0 srcs/docker-compose.yml | 84 ++---------------- srcs/docker/composes/db.yml | 20 +++++ srcs/docker/composes/nginx-prod.yml | 11 +++ srcs/docker/composes/nginx.yml | 43 +++++++++ srcs/docker/composes/wordp-php.yml | 22 +++++ srcs/docker/{ => images}/alpine/Dockerfile | 0 .../alpine-minirootfs-3.21.2-x86_64.tar.gz | Bin srcs/docker/{ => images}/mariadb/Dockerfile | 2 +- srcs/docker/{ => images}/nginx/Dockerfile | 4 +- srcs/docker/{ => images}/nginx/health.conf | 0 srcs/docker/{ => images}/wordpress/Dockerfile | 4 +- .../wordpress/wp-config-docker.php | 0 .../{ => images}/wordpress/www-docker.conf | 0 16 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 srcs/docker-compose-prod.yml create mode 100644 srcs/docker/composes/db.yml create mode 100644 srcs/docker/composes/nginx-prod.yml create mode 100644 srcs/docker/composes/nginx.yml create mode 100644 srcs/docker/composes/wordp-php.yml rename srcs/docker/{ => images}/alpine/Dockerfile (100%) rename srcs/docker/{ => images}/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz (100%) rename srcs/docker/{ => images}/mariadb/Dockerfile (94%) rename srcs/docker/{ => images}/nginx/Dockerfile (89%) rename srcs/docker/{ => images}/nginx/health.conf (100%) rename srcs/docker/{ => images}/wordpress/Dockerfile (91%) rename srcs/docker/{ => images}/wordpress/wp-config-docker.php (100%) rename srcs/docker/{ => images}/wordpress/www-docker.conf (100%) diff --git a/Makefile b/Makefile index 30c4585..3f90f39 100644 --- a/Makefile +++ b/Makefile @@ -8,29 +8,19 @@ DOCKERFILE_DB := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(DB_SERVER_NAME)/Dockerfile DOCKERFILE_WEVSRV := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(WEB_SERVER_NAME)/Dockerfile DOCKERFILE_CMS := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(CMS_NAME)/Dockerfile -all: +dev: + docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build + +prod: docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build -build-db: - docker build -f $(DOCKERFILE_DB) -t $(DB_SERVER_NAME) $(DOCKER_CONTEXT) - -build-websrv: - docker build -f $(DOCKERFILE_WEVSRV) -t $(WEB_SERVER_NAME) $(DOCKER_CONTEXT) - -build-cms: - docker build -f $(DOCKERFILE_CMS) -t $(CMS_NAME) $(DOCKER_CONTEXT) - -start-db: - docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up db --build - -start-nginx: - docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up nginx --build - -start-wordp: - docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up wordpress-php --build +all: dev stop: - docker compose -f $(DOCKER_CONTEXT)docker-compose.yml stop + docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml stop + +stop-prod: + docker compose -f $(DOCKER_CONTEXT)docker-compose-prod.yml stop clean: stop docker system prune @@ -38,23 +28,6 @@ clean: stop fclean: clean docker system prune -a -clean-db: - docker stop inception-db - docker container rm inception-db - docker volume rm inception_wp-db - docker image rm inception-db - -clean-wordp: - docker stop inception-wordp-php - docker container rm inception-wordp-php - docker volume rm inception_wp-site - docker image rm inception-wordpress-php - -clean-nginx: - docker stop inception-nginx - docker container rm inception-nginx - docker image rm inception-nginx - re: clean all .PHONY: cms-build db-build websrv-build clean-db clean-nginx diff --git a/srcs/cmd/mariadb/healthcheck/healthcheck.go b/srcs/cmd/mariadb/healthcheck/healthcheck.go index bbffffc..859f3ed 100644 --- a/srcs/cmd/mariadb/healthcheck/healthcheck.go +++ b/srcs/cmd/mariadb/healthcheck/healthcheck.go @@ -18,7 +18,7 @@ func checkMariaDB(user, password, host, port string) bool { fmt.Printf("Health check failed: %v\n", err) return false } - fmt.Println("MariaDB is healthy") + fmt.Println("Maria DB is healthy") return true } diff --git a/srcs/docker-compose-prod.yml b/srcs/docker-compose-prod.yml new file mode 100644 index 0000000..e69de29 diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 1deb8df..30223ab 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -1,82 +1,14 @@ name: inception -volumes: - wp-db: - wp-site: +include: + - path: ./docker/composes/nginx.yml + project_directory: ./ + - path: ./docker/composes/wordp-php.yml + project_directory: ./ + - path: ./docker/composes/db.yml + project_directory: ./ networks: inception: + name: inception external: false - -services: - nginx: - container_name: inception-nginx - build: - context: . - dockerfile: docker/nginx/Dockerfile - networks: - - inception - environment: - - TZ=Europe/Paris - - NGINX_PHP_HOST=inception-wordp-php - - NGINX_SSL_KEY_FILE=/etc/nginx/ssl/adjoly-wp.key - - NGINX_SSL_CERT_FILE=/etc/nginx/ssl/adjoly-wp.crt - - NGINX_EXPOSED_HOSTS=adjoly.42.fr - depends_on: - wordpress-php: - condition: service_healthy - db: - condition: service_healthy - volumes: - - wp-site:/var/www/html - - ./configs/nginx/templates:/etc/nginx/templates - - ./configs/nginx/entry:/docker-entrypoint.d - ports: - - "10443:443" - restart: unless-stopped - labels: - - traefik.enable=true - - traefik.docker.network=traefik-back - - - traefik.http.routers.inception.rule=Host(`inception.kanel.ovh`) - - traefik.http.routers.inception.entrypoints=websecure - - traefik.http.routers.inception.tls=true - - traefik.http.routers.inception.tls.certresolver=letsencrypt - - traefik.http.routers.inception.service=inception - - traefik.http.services.inception.loadbalancer.server.port=80 - - wordpress-php: - container_name: inception-wordp-php - build: - context: . - dockerfile: docker/wordpress/Dockerfile - networks: - - inception - depends_on: - db: - condition: service_healthy - environment: - - PHP_MEMORY_LIMIT="512M" - - PHP_MAX_UPLOAD="50M" - - PHP_PORT=9000 - - TZ=Europe/Paris - volumes: - - wp-site:/var/www/html - restart: unless-stopped - - db: - container_name: inception-db - build: - context: . - dockerfile: docker/mariadb/Dockerfile - networks: - - inception - environment: - - MYSQL_ROOT_PASSWORD="alpine" - - MYSQL_PASSWORD="alpine" - - MYSQL_USER="kanel" - - MYSQL_DATABASE="knl" - - TZ=Europe/Paris - volumes: - - wp-db:/var/lib/mysql - restart: unless-stopped diff --git a/srcs/docker/composes/db.yml b/srcs/docker/composes/db.yml new file mode 100644 index 0000000..c24eb42 --- /dev/null +++ b/srcs/docker/composes/db.yml @@ -0,0 +1,20 @@ +volumes: + wp-db: + +services: + db: + container_name: inception-db + build: + context: . + dockerfile: docker/images/mariadb/Dockerfile + networks: + - inception + environment: + - MYSQL_ROOT_PASSWORD="alpine" + - MYSQL_PASSWORD="alpine" + - MYSQL_USER="kanel" + - MYSQL_DATABASE="knl" + - TZ=Europe/Paris + volumes: + - wp-db:/var/lib/mysql + restart: unless-stopped diff --git a/srcs/docker/composes/nginx-prod.yml b/srcs/docker/composes/nginx-prod.yml new file mode 100644 index 0000000..a1d39a7 --- /dev/null +++ b/srcs/docker/composes/nginx-prod.yml @@ -0,0 +1,11 @@ + + labels: + - traefik.enable=true + - traefik.docker.network=traefik-back + + - traefik.http.routers.inception.rule=Host(`inception.kanel.ovh`) + - traefik.http.routers.inception.entrypoints=websecure + - traefik.http.routers.inception.tls=true + - traefik.http.routers.inception.tls.certresolver=letsencrypt + - traefik.http.routers.inception.service=inception + - traefik.http.services.inception.loadbalancer.server.port=80 diff --git a/srcs/docker/composes/nginx.yml b/srcs/docker/composes/nginx.yml new file mode 100644 index 0000000..18b804e --- /dev/null +++ b/srcs/docker/composes/nginx.yml @@ -0,0 +1,43 @@ +volumes: + nginx-templates: + name: nginx-templates + driver: local + driver_opts: + device: ./configs/nginx/templates + o: "bind,ro" + type: none + nginx-entry: + name: nginx-entry + driver: local + driver_opts: + device: ./configs/nginx/entry + o: "bind,ro" + type: none + + +services: + nginx: + container_name: inception-nginx + build: + context: . + dockerfile: docker/images/nginx/Dockerfile + networks: + - inception + environment: + - TZ=Europe/Paris + - NGINX_PHP_HOST=inception-wordp-php + - NGINX_SSL_KEY_FILE=/etc/nginx/ssl/adjoly-wp.key + - NGINX_SSL_CERT_FILE=/etc/nginx/ssl/adjoly-wp.crt + - NGINX_EXPOSED_HOSTS=adjoly.42.fr + depends_on: + wordpress-php: + condition: service_healthy + db: + condition: service_healthy + volumes: + - wp-site:/var/www/html + - nginx-templates:/etc/nginx/templates + - nginx-entry:/docker-entrypoint.d + ports: + - "10443:443" + restart: unless-stopped diff --git a/srcs/docker/composes/wordp-php.yml b/srcs/docker/composes/wordp-php.yml new file mode 100644 index 0000000..3dc4577 --- /dev/null +++ b/srcs/docker/composes/wordp-php.yml @@ -0,0 +1,22 @@ +volumes: + wp-site: + +services: + wordpress-php: + container_name: inception-wordp-php + build: + context: . + dockerfile: docker/images/wordpress/Dockerfile + networks: + - inception + depends_on: + db: + condition: service_healthy + environment: + - PHP_MEMORY_LIMIT="512M" + - PHP_MAX_UPLOAD="50M" + - PHP_PORT=9000 + - TZ=Europe/Paris + volumes: + - wp-site:/var/www/html + restart: unless-stopped diff --git a/srcs/docker/alpine/Dockerfile b/srcs/docker/images/alpine/Dockerfile similarity index 100% rename from srcs/docker/alpine/Dockerfile rename to srcs/docker/images/alpine/Dockerfile diff --git a/srcs/docker/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz b/srcs/docker/images/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz similarity index 100% rename from srcs/docker/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz rename to srcs/docker/images/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz diff --git a/srcs/docker/mariadb/Dockerfile b/srcs/docker/images/mariadb/Dockerfile similarity index 94% rename from srcs/docker/mariadb/Dockerfile rename to srcs/docker/images/mariadb/Dockerfile index 2e093c6..43a18c4 100644 --- a/srcs/docker/mariadb/Dockerfile +++ b/srcs/docker/images/mariadb/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ADD docker/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / +ADD docker/images/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / LABEL version="0.1" LABEL maintainer="KeyZox" diff --git a/srcs/docker/nginx/Dockerfile b/srcs/docker/images/nginx/Dockerfile similarity index 89% rename from srcs/docker/nginx/Dockerfile rename to srcs/docker/images/nginx/Dockerfile index 7562023..76593d9 100644 --- a/srcs/docker/nginx/Dockerfile +++ b/srcs/docker/images/nginx/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ADD docker/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / +ADD docker/images/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / LABEL version="0.1" LABEL maintainer="KeyZox" @@ -28,7 +28,7 @@ RUN set -x \ VOLUME /etc/nginx/templates VOLUME /docker-entrypoint.d -COPY docker/nginx/health.conf /etc/nginx/http.d/health.conf +COPY docker/images/nginx/health.conf /etc/nginx/http.d/health.conf ENTRYPOINT [ "/docker-entrypoint" ] WORKDIR /etc/nginx diff --git a/srcs/docker/nginx/health.conf b/srcs/docker/images/nginx/health.conf similarity index 100% rename from srcs/docker/nginx/health.conf rename to srcs/docker/images/nginx/health.conf diff --git a/srcs/docker/wordpress/Dockerfile b/srcs/docker/images/wordpress/Dockerfile similarity index 91% rename from srcs/docker/wordpress/Dockerfile rename to srcs/docker/images/wordpress/Dockerfile index c96625c..9415cd7 100644 --- a/srcs/docker/wordpress/Dockerfile +++ b/srcs/docker/images/wordpress/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ADD docker/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / +ADD docker/images/alpine/alpine-minirootfs-3.21.2-x86_64.tar.gz / LABEL version="0.1" LABEL maintainer="KeyZox" @@ -10,7 +10,7 @@ RUN set -x \ COPY go.mod /build/go.mod COPY cmd /build/cmd COPY internal /build/internal -COPY docker/wordpress/www-docker.conf /www-docker.conf +COPY docker/images/wordpress/www-docker.conf /www-docker.conf RUN apk add --no-cache go curl php84-mysqli php84-fpm tzdata fcgi \ && cd /build \ diff --git a/srcs/docker/wordpress/wp-config-docker.php b/srcs/docker/images/wordpress/wp-config-docker.php similarity index 100% rename from srcs/docker/wordpress/wp-config-docker.php rename to srcs/docker/images/wordpress/wp-config-docker.php diff --git a/srcs/docker/wordpress/www-docker.conf b/srcs/docker/images/wordpress/www-docker.conf similarity index 100% rename from srcs/docker/wordpress/www-docker.conf rename to srcs/docker/images/wordpress/www-docker.conf