Browse Source

v2: some cleanup and optimizations

master
narnaud 2 years ago
parent
commit
d56b4c45d4
  1. 11
      Makefile
  2. 9
      srcs/bonus/gitea/Dockerfile
  3. 18
      srcs/bonus/gitea/start.sh
  4. 1
      srcs/bonus/hexo/Dockerfile
  5. 4
      srcs/bonus/hexo/academia_config.yml
  6. 2
      srcs/bonus/hexo/start.sh
  7. 1
      srcs/bonus/vsftpd/start.sh
  8. 3
      srcs/docker-compose.yml
  9. 8
      srcs/mariadb/start.sh
  10. 1
      srcs/wordpress/start.sh

11
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

9
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"]

18
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

1
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

4
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:

2
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

1
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

3
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/

8
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;

1
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

Loading…
Cancel
Save