Compare commits

...

1 Commits
master ... test

Author SHA1 Message Date
Willem Haffmans
07506ed53a ff bewaren 2025-05-18 13:49:05 +02:00
11 changed files with 193 additions and 49 deletions

View File

@ -6,17 +6,60 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2025/05/12 15:33:56 by whaffman #+# #+# #
# Updated: 2025/05/12 15:35:21 by whaffman ######## odam.nl #
# Updated: 2025/05/13 08:59:04 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
DOCKER_COMPOSE = docker compose
DOCKER_COMPOSE_FILE = ./srcs/docker-compose.yml
DC = $(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE)
.PHONY: all build up down remove
all: build up
build:
@echo "$(gub)Building Docker containers...$(reset)"
$(DC) build
up:
docker-compose up -d --build
@echo "$(gub)Starting Docker containers...$(reset)"
$(DC) up -d --build
down:
docker-compose down
@echo "$(gub)Stopping Docker containers...$(reset)"
$(DC) down
remove:
docker-compose down --rmi all
@docker volume rm $(shell docker volume ls -qf dangling=true) || true
clean:
@echo "$(gub)Cleaning up Docker containers...$(reset)"
$(DC) down --rmi local --volumes --remove-orphans
logs:
@echo "$(gub)Displaying logs...$(reset)"
@$(DC) logs
ps:
@echo "$(gub)Displaying running containers...$(reset)"
@$(DC) ps
@echo "$(gub)Displaying networks...$(reset)"
@docker network ls
@echo "$(gub)Displaying volumes...$(reset)"
@docker volume ls
@echo "$(gub)Displaying images...$(reset)"
@docker images
@echo "$(gub)Displaying all containers...$(reset)"
@docker ps -a
remove:
@echo "$(gub)Removing Docker containers...$(reset)"
@$(DC) rm -f
@$(DC) volume rm -f
@$(DC) network rm -f
# Colors
green:=$(shell tput setaf 2)
bold:=$(shell tput bold)
uncerline:=$(shell tput smul)
gub:=$(green)$(underline)$(bold)
reset:=$(shell tput sgr0)

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1 @@
test

View File

View File

@ -1,20 +1,8 @@
version: '3.8'
env_file:
- .env
secrets:
mariadb_root_password:
file: ./secrets/db_root_password
mariadb_user_password:
file: ./secrets/db_password
wordpress_admin_password:
file: ./requirements/wordpress/.env
wordpress_user_password:
file: ./requirements/wordpress/.env
name: inception
services:
mariadb:
container_name: mariadb
restart: always
build:
context: ./requirements/mariadb
@ -25,41 +13,60 @@ services:
- docker-network
volumes:
- data_mariadb:/var/lib/mysql
secrets:
- mariadb_root_password
- mariadb_user_password
env_file:
- ./requirements/mariadb/.env
nginx:
restart: always
build:
context: ./requirements/nginx
dockerfile: Dockerfile
ports:
-'443:443'
networks:
- docker-network
volumes:
- data_wordpress:/var/www/html
wordpress:
restart: always
build:
context: ./requirements/wordpress
dockerfile: Dockerfile
depends_on:
- mariadb
ports:
- '9000:9000'
networks:
- docker-network
volumes:
- data_wordpress:/var/www/html
# wordpress:
# container_name: wordpress
# restart: always
# build:
# context: ./requirements/wordpress
# dockerfile: Dockerfile
# depends_on:
# - mariadb
# ports:
# - '9000:9000'
# networks:
# - docker-network
# volumes:
# - data_wordpress:/var/www/html
# nginx:
# container_name: nginx
# restart: always
# build:
# context: ./requirements/nginx
# dockerfile: Dockerfile
# depends_on:
# - wordpress
# ports:
# - '443:443'
# networks:
# - docker-network
# volumes:
# - data_wordpress:/var/www/html
networks:
docker-network:
driver: bridge
volumes:
data_mariadb:
driver: local
data_wordpress:
driver: local
# data_wordpress:
# driver: local
secrets:
mariadb_root_password:
file: ../secrets/db_root_password.txt
mariadb_user_password:
file: ../secrets/db_password.txt
# wordpress_admin_password:
# file: ./requirements/wordpress/.env
# wordpress_user_password:
# file: ./requirements/wordpress/.env

View File

@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=123456
MYSQL_DATABASE=wordpress
MYSQL_USER=wordpress
MYSQL_PASSWORD=123456

View File

@ -1,3 +1,44 @@
FROM alpine:3.20
RUN apk add --no-cache mariadb mariadb-client
RUN apk update && apk upgrade && \
apk add --no-cache \
mariadb \
mariadb-client \
mariadb-server-utils && \
rm -rf /var/cache/apk/*
# Create a new user and group
RUN addgroup -S mariadb && adduser -S mariadb -G mariadb
# Create the data directory
RUN mkdir -p /var/lib/mysql && \
chown -R mariadb:mariadb /var/lib/mysql && \
chmod 700 /var/lib/mysql
# Create the socket directory
RUN mkdir -p /var/run/mysqld && \
chown -R mariadb:mariadb /var/run/mysqld && \
chmod 755 /var/run/mysqld
# Create the configuration directory
# Set the working directory
WORKDIR /var/lib/mysql
# Expose the MySQL port
EXPOSE 3306
# Set the default environment variables
# Copy the configuration file
COPY ./conf/my.cnf /etc/my.cnf
# Make the configuration file readable by the user
RUN chown mariadb:mariadb /etc/my.cnf
# Copy the entrypoint script
COPY ./tools/entrypoint.sh /usr/local/bin/entrypoint.sh
# Make the entrypoint script executable
RUN chmod +x /usr/local/bin/entrypoint.sh
# Set the default user to run the container
USER mariadb
# # Set the entrypoint script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Set the default command to run when the container starts
CMD ["mysqld", "--bind-address=0.0.0.0"]

View File

@ -0,0 +1,6 @@
[mysqld]
port = 3306
datadir = /var/lib/mysql
socket = /var/run/mysqld/mysqld.sock
skip-networking = false
bind-address = 0.0.0.0

View File

@ -0,0 +1,32 @@
#!/bin/sh
echo "Hello from mariadb entrypoint.sh"
echo db: $MYSQL_DATABASE
mysql_install_db
if [ -d "/var/lib/mysql/$MYSQL_DATABASE" ]
then
echo "Database already exists"
else
# Set root option so that connexion without root password is not possible
#Add a root user on 127.0.0.1 to allow remote connexion
#Flush privileges allow to your sql tables to be updated automatically when you modify it
#mysql -uroot launch mysql command line client
echo "GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD'; FLUSH PRIVILEGES;" | mysql -uroot
#Create database and user in the database for wordpress
echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE; GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD'; FLUSH PRIVILEGES;" | mysql -u root
#Import database in the mysql command line
# mysql -uroot -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE < /usr/local/bin/wordpress.sql
fi
exec "$@"

View File

@ -0,0 +1,6 @@
FROM alpine:3.20
RUN apk update && apk upgrade && \
apk add --no-cache \
nginx \
openssl \

View File

@ -0,0 +1,3 @@
FROM alpine:3.20
RUN apk update && apk upgrade