Browse Source

v2: better hexo initiatization

master
narnaud 2 years ago
parent
commit
26e44be900
  1. 6
      Makefile
  2. 20
      README.md
  3. 4
      srcs/bonus/gitea/Dockerfile
  4. 6
      srcs/bonus/gitea/app.ini
  5. 16
      srcs/bonus/gitea/start.sh
  6. 4
      srcs/bonus/hexo/Dockerfile
  7. 58
      srcs/bonus/hexo/README.md
  8. 8
      srcs/bonus/hexo/start.sh
  9. 1
      srcs/docker-compose.yml

6
Makefile

@ -12,6 +12,7 @@ $(CERT):
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)/"
mv inception.pem $(DATA_FOLDER)/ssl
start: $(CERT)
BUILDKIT_PROGRESS=plain docker compose -f srcs/docker-compose.yml up --build
@ -22,9 +23,12 @@ stop:
clean: stop
docker system prune -f
fclean: prune
fclean: stop
docker system prune -af --volumes
wipe: stop
rm -rf $(DATA_FOLDER)
re: fclean start
.PHONY: domain start stop clean fclean all

20
README.md

@ -16,26 +16,26 @@ DOMAIN=narnaud.42.fr
WP_TITLE=Inception
WP_ADMIN_USR=theboss
WP_ADMIN_PWD=thebossword
WP_ADMIN_PWD= ***
WP_ADMIN_EMAIL=theboss@mail.com
WP_USR=narnaud
WP_PWD=narnaudword
WP_PWD= ***
WP_EMAIL=narnaud@student.42nice.fr
MYSQL_ROOT_PWD=mariadbword
MYSQL_ROOT_PWD= ***
WP_DATABASE_NAME=wordpressdb
WP_DATABASE_USR=wordpress
WP_DATABASE_PWD=wordpressword
WP_DATABASE_PWD= ***
GITEA_DATABASE_NAME=giteadb
GITEA_DATABASE_USR=gitea
GITEA_DATABASE_PWD=giteaword
GITEA_DATABASE_PWD= ***
GITEA_ADMIN_USR=theboss
GITEA_ADMIN_PWD=thebossword
GITEA_ADMIN_PWD= ***
GITEA_ADMIN_MAIL=theboss@mail.com
FTP_USR=ftpuser
FTP_PWD=ftpuserword
FTP_PWD= **
```
### Start it:
@ -50,3 +50,9 @@ To custom static page content, just edit `srcs/bonus/hexo/*_conf.yml` files with
For acces to homepage, visit `localhost` or your domain url (`DOMAIN_URL`) from your browser.
You can access all services except ftp server from the homepage.
To access ftp, connect using ftp://FTP_USER@localhost:21 and the FTP_PWD with your favourite ftp client.
### Static publishing:
To publish some content to the static homepage:
- first create a new article file either from the `~/data/www/html/source/_post` or using the hexo container command `hexo n post TITLE`.
You can access hexo container cli using `docker compose run hexo sh` command.
- Once you have fullfilled the new file with the content you want, you can either `hexo generate` if you still in the container cli or just launch the container without custom parameters.

4
srcs/bonus/gitea/Dockerfile

@ -1,11 +1,11 @@
FROM alpine:3.15
RUN apk update && apk upgrade && apk add --no-cache git gitea mariadb-client
RUN mkdir -p /var/ssl
COPY start.sh /tmp/start.sh
COPY app.ini /tmp/app.ini
WORKDIR /etc/gitea
ENTRYPOINT ["sh", "/tmp/start.sh"]

6
srcs/bonus/gitea/app.ini

@ -5,9 +5,9 @@ RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = mariadb:3306
NAME = giteadb
USER = gitea
PASSWD = giteaword
NAME =
USER =
PASSWD =
SCHEMA =
SSL_MODE = disable
CHARSET = utf8

16
srcs/bonus/gitea/start.sh

@ -5,20 +5,22 @@ while ! mariadb -hmariadb -u$GITEA_DATABASE_USR -p$GITEA_DATABASE_PWD $GITEA_DAT
echo "Gitea waiting db..."
sleep 5
done
if [ ! -f "app.ini" ]; then
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/
mkdir -p /etc/gitea
cp /tmp/app.ini /etc/gitea/
chown -R root:git /etc/gitea
chmod -R 770 /etc/gitea
if [ ! -f "app.ini.bak" ]; then
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"
fi
echo "Launching gitea on localhost:3000"
su git -c "gitea web --config /etc/gitea/app.ini" &> /dev/null
su git -c "gitea web --config /etc/gitea/app.ini"

4
srcs/bonus/hexo/Dockerfile

@ -5,8 +5,10 @@ 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
COPY README.md /tmp/README.md
WORKDIR /var/www/html
COPY start.sh /tmp/start.sh
ENTRYPOINT [ "sh", "/tmp/start.sh" ]
RUN npm install -g hexo
CMD [ "sh", "/tmp/start.sh" ]

58
srcs/bonus/hexo/README.md

@ -0,0 +1,58 @@
# Inception
Projet 42:
Sujet: Conteneuriser un serveur web qui hebergera wordpress localement à l'aide de docker, alpine/debian, nginx et mariadb
## Todo:
- add login/register/admin buttons in wordpress
## Instructions:
### Setup it:
Create a `.env` file in `srcs` folder with settings you want.
e.g:
```
DOMAIN=narnaud.42.fr
#DOMAIN=localhost
WP_TITLE=Inception
WP_ADMIN_USR=theboss
WP_ADMIN_PWD= ***
WP_ADMIN_EMAIL=theboss@mail.com
WP_USR=narnaud
WP_PWD= ***
WP_EMAIL=narnaud@student.42nice.fr
MYSQL_ROOT_PWD= ***
WP_DATABASE_NAME=wordpressdb
WP_DATABASE_USR=wordpress
WP_DATABASE_PWD= ***
GITEA_DATABASE_NAME=giteadb
GITEA_DATABASE_USR=gitea
GITEA_DATABASE_PWD= ***
GITEA_ADMIN_USR=theboss
GITEA_ADMIN_PWD= ***
GITEA_ADMIN_MAIL=theboss@mail.com
FTP_USR=ftpuser
FTP_PWD= **
```
### Start it:
If you want to use a custom domain as local host, modify the Makefile DOMAIN variable and `make domain`.
To custom static page content, just edit `srcs/bonus/hexo/*_conf.yml` files with what you what to use before build.
`make` to build and start.
`make clean` to cleanup unused datas.
`make fclean` to wipe all.
`sudo make wipe` to wipe all servers datas.
### Use it:
For acces to homepage, visit `localhost` or your domain url (`DOMAIN_URL`) from your browser.
You can access all services except ftp server from the homepage.
To access ftp, connect using ftp://FTP_USER@localhost:21 and the FTP_PWD with your favourite ftp client.
### Static publishing:
To publish some content to the static homepage:
- first create a new article file either from the `~/data/www/html/source/_post` or using the hexo container command `hexo n post TITLE`.
You can access hexo container cli using `docker compose run hexo sh` command.
- Once you have fullfilled the new file with the content you want, you can either `hexo generate` if you still in the container cli or just launch the container without custom parameters.

8
srcs/bonus/hexo/start.sh

@ -1,19 +1,19 @@
#!/bin/sh
if [ ! -f "public/index.html" ]; then
npm install -g hexo-cli
hexo init && npm install
git clone https://github.com/PhosphorW/hexo-theme-academia.git themes/Academia
npm install hexo-renderer-pug hexo-renderer-stylus --save
cp /tmp/hexo_config.yml _config.yml
cp /tmp/narnaud.jpg themes/Academia/source/img/narnaud.jpg
hexo n post "README"
sed -i "5i academia: true" source/_posts/README.md
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 "/Gitea: .*/c\ Gitea: https:\/\/$DOMAIN\/git" _config.yml
sed -i "/Adminer: .*/c\ Adminer: https:\/\/$DOMAIN\/adminer.php" _config.yml
hexo generate
fi
hexo generate

1
srcs/docker-compose.yml

@ -58,6 +58,7 @@ services:
networks:
- local
env_file: .env
tty: true
wordpress:
build: wordpress/

Loading…
Cancel
Save