From d56b4c45d43ea4bf44489ef844355f83427343ac Mon Sep 17 00:00:00 2001 From: narnaud Date: Sun, 30 Oct 2022 16:06:48 +0100 Subject: [PATCH] v2: some cleanup and optimizations --- Makefile | 11 +++++++++-- srcs/bonus/gitea/Dockerfile | 9 ++++++++- srcs/bonus/gitea/start.sh | 18 ++++++------------ srcs/bonus/hexo/Dockerfile | 1 - srcs/bonus/hexo/academia_config.yml | 4 +--- srcs/bonus/hexo/start.sh | 2 +- srcs/bonus/vsftpd/start.sh | 1 - srcs/docker-compose.yml | 3 ++- srcs/mariadb/start.sh | 8 +------- srcs/wordpress/start.sh | 1 + 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 2e9bb69..52f59e6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ NAME = inception +USER = narnaud DATA_FOLDER = /home/$(USER)/data CERT = $(DATA_FOLDER)/ssl/inception.pem @@ -7,14 +8,20 @@ all: clean start domain: echo "127.0.0.1 $(USER).42.fr" >> /etc/hosts +hexo: + docker compose -f srcs/docker-compose.yml run hexo sh + $(CERT): - mkdir -p $(DATA_FOLDER)/ssl openssl req -newkey rsa:4096 -x509 -sha256 -days 365 -nodes \ -out inception.pem -keyout inception.pem \ -subj "/C=FR/ST=Nice/L=Nice/O=42/OU=student/CN=inception_$(USER)/" + mkdir -p $(DATA_FOLDER)/ssl mv inception.pem $(DATA_FOLDER)/ssl start: $(CERT) + docker compose -f srcs/docker-compose.yml up --build + +debug: $(CERT) BUILDKIT_PROGRESS=plain docker compose -f srcs/docker-compose.yml up --build stop: @@ -31,4 +38,4 @@ wipe: stop re: fclean start -.PHONY: domain start stop clean fclean all +.PHONY: all domain hexo start debug stop clean fclean diff --git a/srcs/bonus/gitea/Dockerfile b/srcs/bonus/gitea/Dockerfile index c955511..5950ec4 100644 --- a/srcs/bonus/gitea/Dockerfile +++ b/srcs/bonus/gitea/Dockerfile @@ -2,10 +2,17 @@ FROM alpine:3.15 RUN apk update && apk upgrade && apk add --no-cache git gitea mariadb-client +RUN addgroup git && adduser -D -G git git COPY start.sh /tmp/start.sh COPY app.ini /tmp/app.ini +RUN mkdir -p /var/lib/gitea/{custom,data,log} +RUN chown -R git:git /var/lib/gitea/ && chmod -R 750 /var/lib/gitea/ -WORKDIR /etc/gitea +RUN chown -R root:git /etc/gitea && chmod -R 770 /etc/gitea +RUN chown root:git /tmp/app.ini && chmod 770 /tmp/app.ini + +USER git +WORKDIR /etc/gitea ENTRYPOINT ["sh", "/tmp/start.sh"] diff --git a/srcs/bonus/gitea/start.sh b/srcs/bonus/gitea/start.sh index 562379e..8953049 100644 --- a/srcs/bonus/gitea/start.sh +++ b/srcs/bonus/gitea/start.sh @@ -5,22 +5,16 @@ while ! mariadb -hmariadb -u$GITEA_DATABASE_USR -p$GITEA_DATABASE_PWD $GITEA_DAT echo "Gitea waiting db..." sleep 5 done -ls -la - echo "Initializing gitea..." - adduser -D git - addgroup --system git git - mkdir -p /var/lib/gitea/{custom,data,log} - chown -R git:git /var/lib/gitea/ - chmod -R 750 /var/lib/gitea/ + if [ ! -f "app.ini.bak" ]; then + echo "Initializing gitea..." + mv app.ini app.ini.bak cp /tmp/app.ini . - chown -R root:git . - chmod -R 770 . sed -i "/NAME .*/c\NAME = $GITEA_DATABASE_NAME" app.ini sed -i "/USER .*/c\USER = $GITEA_DATABASE_USR" app.ini sed -i "/PASSWD .*/c\PASSWD = $GITEA_DATABASE_PWD" app.ini - su git -c "gitea migrate" - su git -c "gitea admin user create --username $GITEA_ADMIN_USR --password $GITEA_ADMIN_PWD --email $GITEA_ADMIN_MAIL --admin" + gitea migrate + gitea admin user create --username $GITEA_ADMIN_USR --password $GITEA_ADMIN_PWD --email $GITEA_ADMIN_MAIL --admin fi echo "Launching gitea on localhost:3000" -su git -c "gitea web --config /etc/gitea/app.ini" +gitea web --config /etc/gitea/app.ini &> /dev/null diff --git a/srcs/bonus/hexo/Dockerfile b/srcs/bonus/hexo/Dockerfile index 68c8d51..364e191 100644 --- a/srcs/bonus/hexo/Dockerfile +++ b/srcs/bonus/hexo/Dockerfile @@ -1,7 +1,6 @@ FROM alpine:3.15 RUN apk update && apk upgrade && apk add --no-cache wget git npm -RUN adduser -S nginx && addgroup -S nginx COPY academia_config.yml /tmp/academia_config.yml COPY hexo_config.yml /tmp/hexo_config.yml COPY narnaud.jpg /tmp/narnaud.jpg diff --git a/srcs/bonus/hexo/academia_config.yml b/srcs/bonus/hexo/academia_config.yml index 68a0ca0..efa3c0b 100644 --- a/srcs/bonus/hexo/academia_config.yml +++ b/srcs/bonus/hexo/academia_config.yml @@ -1,6 +1,6 @@ favicon: /img/favicon.png # Change to your profile picture -avatar: /img/avatar.jpg +avatar: /img/narnaud.jpg # if author sets in hexo_config, this string doesn't work author: 'Nicolas Arnaud' author_bio: "I'm a 28 y.o developer still learning at 42Nice school." @@ -11,11 +11,9 @@ since: 2022 # #title 为页内跳转,单页模式 # 可以选择外链或其他页面 menu: - Publications: /#Publications Blog: / #edited in start.sh Gitea: / #edited in start.sh Adminer: / #edited in start.sh - About: / # flink picture will load if avator link calls on error loading_bg: diff --git a/srcs/bonus/hexo/start.sh b/srcs/bonus/hexo/start.sh index f01fa00..94d6c81 100644 --- a/srcs/bonus/hexo/start.sh +++ b/srcs/bonus/hexo/start.sh @@ -11,7 +11,7 @@ if [ ! -f "public/index.html" ]; then cat /tmp/README.md >> source/_posts/README.md cd themes/Academia cp /tmp/academia_config.yml _config.yml - sed -i "/Blog: .*/c\ Blog: https:\/\/$DOMAIN\/wordpress" _config.yml + sed -i "/Blog: .*/c\ Wordpress: https:\/\/$DOMAIN\/wordpress" _config.yml sed -i "/Gitea: .*/c\ Gitea: https:\/\/$DOMAIN\/git" _config.yml sed -i "/Adminer: .*/c\ Adminer: https:\/\/$DOMAIN\/adminer.php" _config.yml fi diff --git a/srcs/bonus/vsftpd/start.sh b/srcs/bonus/vsftpd/start.sh index fc48edb..4cbad9b 100644 --- a/srcs/bonus/vsftpd/start.sh +++ b/srcs/bonus/vsftpd/start.sh @@ -1,7 +1,6 @@ #!/bin/sh if [ ! -f vsftpd.conf.bak ]; then - mkdir -p /var/www mv vsftpd.conf vsftpd.conf.bak mv /tmp/vsftpd.conf . adduser -D $FTP_USR diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 5e7b93e..5a6e0ad 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -16,6 +16,7 @@ services: - local env_file: .env restart: always + vsftpd: build: bonus/vsftpd/ container_name: vsftpd @@ -29,6 +30,7 @@ services: - local restart: always env_file: .env + mariadb: build: mariadb/ container_name: mariadb @@ -58,7 +60,6 @@ services: networks: - local env_file: .env - tty: true wordpress: build: wordpress/ diff --git a/srcs/mariadb/start.sh b/srcs/mariadb/start.sh index 047d053..675c7e6 100644 --- a/srcs/mariadb/start.sh +++ b/srcs/mariadb/start.sh @@ -1,8 +1,7 @@ #!/bin/sh if [ ! -d "/run/mysqld" ]; then - mkdir -p /run/mysqld - chown -R mysql:mysql /run/mysqld + mkdir -p /run/mysqld && chown -R mysql:mysql /run/mysqld fi if [ ! -d "/var/lib/mysql/mysql" ]; then @@ -11,11 +10,6 @@ if [ ! -d "/var/lib/mysql/mysql" ]; then mysql_install_db --basedir=/usr --datadir=/var/lib/mysql --user=mysql --rpm > /dev/null - tfile=`mktemp` - if [ ! -f "$tfile" ]; then - return 1 - fi - mysqld --user=mysql --bootstrap << EOF USE mysql; FLUSH PRIVILEGES; diff --git a/srcs/wordpress/start.sh b/srcs/wordpress/start.sh index 2d41059..12158fe 100644 --- a/srcs/wordpress/start.sh +++ b/srcs/wordpress/start.sh @@ -10,6 +10,7 @@ if [ ! -f "index.php" ]; then wp core install --url=https://$DOMAIN/wordpress --title=$WP_TITLE --admin_user=$WP_ADMIN_USR --admin_password=$WP_ADMIN_PWD --admin_email=$WP_ADMIN_EMAIL --skip-email --allow-root wp user create $WP_USR $WP_EMAIL --role=author --user_pass=$WP_PWD --allow-root wp theme install generatepress --activate --allow-root + wp widget add meta sidebar-1 1 sed -i "90i define('WP_REDIS_HOST', 'redis');" wp-config.php sed -i "91i define('WP_REDIS_PORT', 6379);" wp-config.php