Skip to content

Commit

Permalink
docker build
Browse files Browse the repository at this point in the history
ajout du fichier ".dockerignore" : comme pour .git les fichiers listés ici ne sont pas copiés par l'instruction COPY . du Dockerfile
copier "install.sh" dans /root car on l'utilise pendant la séquence d'initialisation "init.sh"
Ajout du "healthcheck": permet de valider la bonne initialisation du container, on peut ainsi le tester dans le workflow
Ne pas re-télécharger le source jeedom durant l'initialisation (init.sh) puisqu'on l'a déjà fait durant le build (Dockerfile).
Fix la fonction "trap" à l'arrêt du conteneur
  • Loading branch information
pifou25 committed Feb 2, 2025
1 parent 61c6ce2 commit cd941b8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
/vendor
/docs
14 changes: 10 additions & 4 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,26 @@ jobs:
run: |
docker build -t jeedom:bullseye --build-arg DEBIAN=bullseye --build-arg DATABASE=1 .
- name: run jeedom:bullseye and check
# build current image for bullseye and check it
# run current image for bullseye and check it
run: |
docker run -p 80:80 -d --rm --name jeedom_bullseye jeedom:bullseye
sleep 45
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bullseye`" == "healthy" ]; do
echo "waiting container to be healthy..."
sleep 5;
done;
docker exec jeedom_bullseye php sick.php
- name: Build jeedom:bookworm
# build current image for bookworm
run: |
docker build -t jeedom:bookworm --build-arg DEBIAN=bookworm --build-arg DATABASE=1 .
- name: run jeedom:bookworm and check
# build current image for bookworm and check it
# run current image for bookworm and check it
run: |
docker run -p 81:80 -d --rm --name jeedom_bookworm jeedom:bookworm
sleep 45
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bookworm`" == "healthy" ]; do
echo "waiting container to be healthy..."
sleep 5;
done;
docker exec jeedom_bookworm php sick.php
- name: Clean docker image
Expand Down
49 changes: 36 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,53 @@ VOLUME /var/lib/mysql

#speed up build using docker cache
RUN apt update -y
RUN apt -o Dpkg::Options::="--force-confdef" -y install software-properties-common \
RUN apt -o Dpkg::Options::="--force-confdef" -y -q install software-properties-common \
ntp ca-certificates unzip curl sudo cron locate tar telnet wget logrotate dos2unix ntpdate htop \
iotop vim iftop smbclient git python3 python3-pip libexpat1 ssl-cert \
apt-transport-https xvfb cutycapt xauth at mariadb-client espeak net-tools nmap ffmpeg usbutils \
gettext libcurl3-gnutls chromium librsync-dev ssl-cert iputils-ping \
apache2 apache2-utils libexpat1 ssl-cert \
php libapache2-mod-php php-json php-mysql php-curl php-gd php-imap php-xml php-opcache php-soap php-xmlrpc \
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp && apt -y remove brltty
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp \
npm && \
# install npm, and node with fixed version
npm install n -g && n 20.18.1 && \
#clean
apt -y remove brltty

COPY install/install.sh /tmp/
RUN sh /tmp/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
COPY --chown=root:root --chmod=550 install/install.sh /root/
# install step by step : step_1_upgrade ... useless, using the LATEST debian
# RUN sh /root/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_2_mainpackage ... useless, already installed before
# RUN sh /root/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_3_database ... only if $DATABASE
RUN sh /root/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_4_apache
RUN sh /root/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_5_php : install php with extensions
RUN sh /root/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step 6 : copy jeedom source files from local
COPY . ${WEBSERVER_HOME}
RUN sh /tmp/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_7_jeedom_customization_mariadb
RUN sh /root/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_8_jeedom_customization
RUN sh /root/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_9_jeedom_configuration
RUN sh /root/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_10_jeedom_installation : install composer
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer
RUN composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader
# RUN sh /root/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_11_jeedom_post
RUN sh /root/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker

RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN echo >${WEBSERVER_HOME}/initialisation

# check if apache is running
HEALTHCHECK --interval=1m --timeout=3s --retries=5 --start-period=10s --start-interval=5s \
CMD curl -f http://localhost/ || exit 1

WORKDIR ${WEBSERVER_HOME}
EXPOSE 80
EXPOSE 443
Expand Down
43 changes: 33 additions & 10 deletions install/OS_specific/Docker/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ docker_stop() {
echo "${JAUNE}Stopping Jeedom container${NORMAL}"
echo "${VERT}Stopping Apache gracefully${NORMAL}"
service apache2 stop
if [[ 1 -eq ${ISMARIABDBINSTALLED} ]]; then
# check if mariadb is installed
dpkg --list mariadb-server > /dev/null 2>&1
status=$?
ISMARIADBSERVER=$(( 1 - ${status} ))
if [[ 1 -eq ${ISMARIADBSERVER} ]]; then
echo "${VERT}Stopping Database gracefully${NORMAL}"
service mariadb stop
else
echo "${VERT}no mariadb server${NORMAL}"
fi

echo "${VERT}Stopping ATD gracefully${NORMAL}"
service atd stop
echo "${VERT}Stoping CRON${NORMAL}"
service cron stop
echo "${ROUGE}Requesting stop on init.sh${NORMAL}"
echo "${VERT}Killing CRON${NORMAL}"
killall cron
exit 0
}

Expand Down Expand Up @@ -81,10 +88,15 @@ if [ -f ${WEBSERVER_HOME}/core/config/common.config.php ]; then
else
echo 'Start jeedom installation'
JEEDOM_INSTALL=0
rm -rf /root/install.sh
wget https://raw.githubusercontent.com/jeedom/core/${VERSION}/install/install.sh -O /root/install.sh
chmod +x /root/install.sh
/root/install.sh -s 6 -v ${VERSION} -w ${WEBSERVER_HOME}

# do not re-install jeedom
if [ ! -f ${WEBSERVER_HOME}/core/config/common.config.sample.php ]; then
echo 'download again Jeedom'
/root/install.sh -s 6 -v ${VERSION} -w ${WEBSERVER_HOME}
# jeedom installation : install composer
/root/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -i docker
fi

if [ $(which mysqld | wc -l) -ne 0 ]; then
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/
Expand All @@ -101,8 +113,14 @@ else
sed -i "s/#USERNAME#/jeedom/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#PORT#/3306/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#HOST#/localhost/g" ${WEBSERVER_HOME}/core/config/common.config.php
/root/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME}
/root/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME}
# init database
php ${WEBSERVER_HOME}/install/install.php mode=force
if [ $? -ne 0 ]; then
echo "${RED}Cannot install Jeedom - Cancelling${NORMAL}"
exit 1
fi
# jeedom post-install
/root/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -i docker
fi
fi

Expand Down Expand Up @@ -148,4 +166,9 @@ service apache2 start
echo "Add trap docker_stop"
trap "docker_stop $$ ;" 15

cron -f
# launch cron daemon in background
cron -f &
# hold the cron daemon PID
child=$!
# wait for cron stopping
wait "$child"
16 changes: 9 additions & 7 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ step_5_php() {
step_6_jeedom_download() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 6 - download Jeedom${NORMAL}"
wget https://codeload.github.com/jeedom/core/zip/refs/heads/${VERSION} -O /tmp/jeedom.zip
wget https://codeload.github.com/jeedom/core/zip/refs/heads/${VERSION} -O /tmp/jeedom.zip --no-verbose

if [ $? -ne 0 ]; then
echo "${YELLOW}Cannot download Jeedom from Github. Use deployment version if exist.${NORMAL}"
Expand Down Expand Up @@ -184,7 +184,7 @@ step_7_jeedom_customization_mariadb() {
echo 'Restart=always' >> /lib/systemd/system/mariadb.service.d/override.conf
echo 'RestartSec=10' >> /lib/systemd/system/mariadb.service.d/override.conf

# do not start oany new service during docker build sequence
# do not start any new service during docker build sequence
if [ "${INSTALLATION_TYPE}" != "docker" ];then
systemctl daemon-reload

Expand Down Expand Up @@ -331,9 +331,6 @@ step_10_jeedom_installation() {
export COMPOSER_ALLOW_SUPERUSER=1
cd ${WEBSERVER_HOME}
composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader
mkdir -p /tmp/jeedom
chmod 777 -R /tmp/jeedom
chown www-data:www-data -R /tmp/jeedom

if [ "${INSTALLATION_TYPE}" != "docker" ];then
php ${WEBSERVER_HOME}/install/install.php mode=force
Expand All @@ -349,6 +346,9 @@ step_10_jeedom_installation() {
step_11_jeedom_post() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 11 - Jeedom post-install${NORMAL}"
mkdir -p /tmp/jeedom
chmod 777 -R /tmp/jeedom
chown www-data:www-data -R /tmp/jeedom
if [ $(crontab -l | grep jeedom | wc -l) -ne 0 ];then
(echo crontab -l | grep -v "jeedom") | crontab -

Expand Down Expand Up @@ -380,8 +380,10 @@ step_11_jeedom_post() {
echo 'tmpfs /tmp/jeedom tmpfs defaults,size=256M 0 0' >> /etc/fstab
fi
fi
chmod +x ${WEBSERVER_HOME}/resources/install_nodejs.sh
${WEBSERVER_HOME}/resources/install_nodejs.sh
if [ "${INSTALLATION_TYPE}" != "docker" ];then
chmod +x ${WEBSERVER_HOME}/resources/install_nodejs.sh
${WEBSERVER_HOME}/resources/install_nodejs.sh
fi
echo "${GREEN}Step 11 - Jeedom post-install done${NORMAL}"
}

Expand Down

0 comments on commit cd941b8

Please sign in to comment.