Artples commited on
Commit
71f21dc
·
verified ·
1 Parent(s): 40477af

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -21
Dockerfile CHANGED
@@ -1,19 +1,21 @@
1
- # Dockerfile
2
  FROM nextcloud:apache
3
 
4
- ENV APACHE_PORT=7860 \
5
- MYSQL_HOST=127.0.0.1
6
 
7
  RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
8
  && sed -i "s/Listen 80/Listen ${APACHE_PORT}/" /etc/apache2/ports.conf \
9
  && sed -i "s/:80/:${APACHE_PORT}/" /etc/apache2/sites-available/000-default.conf
10
 
 
11
  RUN apt-get update \
12
  && apt-get install -y --no-install-recommends mariadb-server mariadb-client \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # Keep MariaDB local to the container and set sane defaults for Nextcloud
16
- RUN printf "%s\n" \
 
17
  "[mysqld]" \
18
  "bind-address=127.0.0.1" \
19
  "skip-name-resolve" \
@@ -22,6 +24,7 @@ RUN printf "%s\n" \
22
  "innodb_file_per_table=1" \
23
  > /etc/mysql/mariadb.conf.d/99-hf-space.cnf
24
 
 
25
  COPY start.sh /start.sh
26
  RUN chmod +x /start.sh
27
 
@@ -31,37 +34,33 @@ ENTRYPOINT ["/start.sh"]
31
  CMD ["apache2-foreground"]
32
 
33
 
34
- # start.sh
35
  #!/usr/bin/env bash
36
  set -euo pipefail
37
 
38
- # Required variables (set them in Hugging Face Space Secrets or Variables)
39
- : "${MYSQL_DATABASE:?Set MYSQL_DATABASE in the Space}"
40
- : "${MYSQL_USER:?Set MYSQL_USER in the Space}"
41
- : "${MYSQL_PASSWORD:?Set MYSQL_PASSWORD in the Space}"
42
-
43
- # Optional, but recommended to automate Nextcloud initial setup
44
- # NEXTCLOUD_ADMIN_USER
45
- # NEXTCLOUD_ADMIN_PASSWORD
46
- # NEXTCLOUD_TRUSTED_DOMAINS
47
 
 
48
  mkdir -p /run/mysqld
49
  chown -R mysql:mysql /run/mysqld
50
 
51
- # Initialize MariaDB data directory on first run
52
  if [ ! -d /var/lib/mysql/mysql ]; then
53
  mariadb-install-db --user=mysql --datadir=/var/lib/mysql > /dev/null
54
  fi
55
 
56
  # Start MariaDB in the background
57
- mysqld_safe --datadir=/var/lib/mysql --bind-address=127.0.0.1 --skip-networking=0 &
58
 
59
- # Wait until MariaDB is ready
60
  until mariadb-admin ping --silent > /dev/null 2>&1; do
61
  sleep 1
62
  done
63
 
64
- # Create database and user (idempotent)
65
  mariadb -uroot <<SQL
66
  CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
67
  CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
@@ -69,8 +68,8 @@ GRANT ALL PRIVILEGES ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'localhost';
69
  FLUSH PRIVILEGES;
70
  SQL
71
 
72
- # Ensure Nextcloud connects to the local DB via env (supported by the official image)
73
- export MYSQL_HOST="${MYSQL_HOST:-127.0.0.1}"
74
 
75
  # Hand off to the official Nextcloud entrypoint
76
  exec /entrypoint.sh "$@"
 
1
+ # File: Dockerfile
2
  FROM nextcloud:apache
3
 
4
+ # Hugging Face will route HTTPS to this container port
5
+ ENV APACHE_PORT=7860
6
 
7
  RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
8
  && sed -i "s/Listen 80/Listen ${APACHE_PORT}/" /etc/apache2/ports.conf \
9
  && sed -i "s/:80/:${APACHE_PORT}/" /etc/apache2/sites-available/000-default.conf
10
 
11
+ # Install MariaDB server inside the same container
12
  RUN apt-get update \
13
  && apt-get install -y --no-install-recommends mariadb-server mariadb-client \
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
+ # Configure MariaDB to listen only locally
17
+ RUN printf "%s
18
+ " \
19
  "[mysqld]" \
20
  "bind-address=127.0.0.1" \
21
  "skip-name-resolve" \
 
24
  "innodb_file_per_table=1" \
25
  > /etc/mysql/mariadb.conf.d/99-hf-space.cnf
26
 
27
+ # Startup script that launches MariaDB and then Nextcloud
28
  COPY start.sh /start.sh
29
  RUN chmod +x /start.sh
30
 
 
34
  CMD ["apache2-foreground"]
35
 
36
 
37
+ # File: start.sh
38
  #!/usr/bin/env bash
39
  set -euo pipefail
40
 
41
+ # Required variables (set these in Hugging Face Space Variables or Secrets)
42
+ : "${MYSQL_DATABASE:?Set MYSQL_DATABASE}"
43
+ : "${MYSQL_USER:?Set MYSQL_USER}"
44
+ : "${MYSQL_PASSWORD:?Set MYSQL_PASSWORD}"
 
 
 
 
 
45
 
46
+ # Ensure runtime directories exist
47
  mkdir -p /run/mysqld
48
  chown -R mysql:mysql /run/mysqld
49
 
50
+ # Initialize MariaDB on first start
51
  if [ ! -d /var/lib/mysql/mysql ]; then
52
  mariadb-install-db --user=mysql --datadir=/var/lib/mysql > /dev/null
53
  fi
54
 
55
  # Start MariaDB in the background
56
+ mysqld_safe --datadir=/var/lib/mysql --bind-address=127.0.0.1 &
57
 
58
+ # Wait for MariaDB
59
  until mariadb-admin ping --silent > /dev/null 2>&1; do
60
  sleep 1
61
  done
62
 
63
+ # Create DB and user (idempotent)
64
  mariadb -uroot <<SQL
65
  CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
66
  CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
 
68
  FLUSH PRIVILEGES;
69
  SQL
70
 
71
+ # Tell the official Nextcloud entrypoint how to reach MariaDB
72
+ export MYSQL_HOST=127.0.0.1
73
 
74
  # Hand off to the official Nextcloud entrypoint
75
  exec /entrypoint.sh "$@"