Sign inSign up

manthanp/baikal

By manthanp

Updated over 2 years ago

Based on ckulka/baikal:nginx with modifications to run on Azure App Service w/ SQLite

Image
Web servers
0

10K+

manthanp/baikal repository overview

Running

Enable apps service storage by adding/setting WEBSITES_ENABLE_APP_SERVICE_STORAGE to true in app settings (configuration) of the App Service. Then use the below docker-compose.yml in Deployment Center.

docker-compose.yml
version: "3.4"

services:
  manthanp-baikal:
    image: manthanp/baikal:0.9.3-nginx
    container_name: manthanp-baikal
    restart: always
    ports:
      # These ports are in format <host-port>:<container-port>
      - "80:80"

    volumes:
      - ${WEBAPP_STORAGE_HOME}/site/wwwroot/Specific:/var/www/baikal/Specific
      - ${WEBAPP_STORAGE_HOME}/site/wwwroot/config:/var/www/baikal/config

Note: The image tags are mapped 1:1 to ckulka/baikal tags.

What

This image is based on ckulka/baikal:nginx with some custom initialization scripts to create an new SQLite DB with journal mode set to WAL.

Why

I wanted to self-host Baikal on Azure App Service. Unfortunately, the Linux host machine mounts the storage as CIFS. SQLite is known to have problems running on CIFS as it cannot provide the necessary locks. As such, if you go through the normal Baikal setup process, it will never complete the 2nd step (setting up SQLite DB) as it won't be able to open the DB to write to it.

Some links describing the problem

Note: I didn't want to use an external MySQL server and wanted the simplicity of an SQLite database.

How

Apparently, configuring the SQLite DB with journal_mode=WAL doesn't require any locks and thus can work in CIFS mounted storage. Some links I came across while trying to get this to work,

The initialization script will first check if db.sqlite is already present in /var/www/baikal/Specific/db/ directory. If it is, then it exits without doing anything. However, if not then,

  1. it touches a new db.sqlite in containers' / directory
  2. runs sqlite3 "$DATABASE_FILE" 'PRAGMA journal_mode=wal;'
  3. moves the db.sqlite from / to /var/www/baikal/Specific/db/

Notice the DB creation and options setting is done in the root directory of the container (it can be any internal directory which is not mapped to host). We cannot do this directly in the /var/www/baikal/Specific/db/ directory as it would be mounted as CIFS and it won't allow modifying the DB (to set journal_mode=WAL) after touching db.sqlite

Scripts

Dockerfile
# https://github.com/ckulka/baikal-docker/blob/master/nginx.dockerfile
FROM ckulka/baikal:0.9.3-nginx
LABEL maintainer="[email protected]"

COPY CreateDBIfNotExist.sh /
COPY Main.sh /
RUN chmod +x /CreateDBIfNotExist.sh
RUN chmod +x /Main.sh

CMD ["nginx", "-g", "daemon off;"]
# this command will be passed to entrypoint below as arguments
# the Main.sh script will pass all the above args as-is to the original entrypoint script (docker-entrypoint.sh)

ENTRYPOINT [ "/Main.sh" ]
Main.sh
#!/bin/bash
/bin/bash /CreateDBIfNotExist.sh
/bin/sh /docker-entrypoint.sh "$@"
CreateDBIfNotExist.sh
#!/bin/bash
echo "executing CreateDBIfNotExist.sh"

DATABASE_DIRECTORY="/var/www/baikal/Specific/db"
DATABASE_FILE="db.sqlite"
# https://stackoverflow.com/a/4181721/6818945
DATABASE="${DATABASE_DIRECTORY}/${DATABASE_FILE}"

echo "LOG -- checking if $DATABASE already exists???"
# exit if db already exists
if [ -f "$DATABASE" ]
then
    echo "LOG -- ${DATABASE} already exists"
    exit 0
fi

echo "LOG -- ${DATABASE} does not exist"

echo "LOG -- creating ${DATABASE_DIRECTORY}"
# https://stackoverflow.com/a/793867/6818945
mkdir -p "$DATABASE_DIRECTORY"

echo "LOG -- cd /"
cd /
echo "LOG -- touching $DATABASE_FILE"
touch "$DATABASE_FILE"
echo "LOG -- applying PRAGMA journal mode = wal"
sqlite3 "$DATABASE_FILE" 'PRAGMA journal_mode=wal;'
echo "LOG -- moving to $DATABASE_DIRECTORY"
mv "$DATABASE_FILE" "$DATABASE_DIRECTORY"

Tag summary

Content type

Image

Digest

sha256:a3e076cd4

Size

87.3 MB

Last updated

over 2 years ago

docker pull manthanp/baikal