From add136e4df589ca498787971f35dc91a38c9ba2f Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Tue, 15 Dec 2020 18:04:05 +0100 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=85=20Docker=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 2 + .gitignore | 2 + Dockerfile | 108 ++++++++++++++++++++++++ Package.resolved | 54 ++++++++++++ Package.swift | 4 + Sources/Feather/Feather+DataBases.swift | 91 ++++++++++++++++++++ Sources/Feather/main.swift | 8 +- docker/build.bat | 2 + docker/build.sh | 4 + docker/try_embedded.bat | 15 ++++ docker/try_embedded.sh | 16 ++++ docker/try_mysql.bat | 48 +++++++++++ docker/try_mysql.sh | 70 +++++++++++++++ docker/try_postgres.bat | 43 ++++++++++ docker/try_postgres.sh | 63 ++++++++++++++ 15 files changed, 523 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Sources/Feather/Feather+DataBases.swift create mode 100644 docker/build.bat create mode 100755 docker/build.sh create mode 100644 docker/try_embedded.bat create mode 100755 docker/try_embedded.sh create mode 100644 docker/try_mysql.bat create mode 100755 docker/try_mysql.sh create mode 100644 docker/try_postgres.bat create mode 100755 docker/try_postgres.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d9f16e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.build/ +.swiftpm/ diff --git a/.gitignore b/.gitignore index e6c4c4f..e13feb0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ db.sqlite Public Resources ./feather +docker/docker-feather-data +ssh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d6a529 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,108 @@ +FROM swift:5.3.1-focal as builder +WORKDIR /opt/feather + +COPY . . + +## Install required dependencies for the build +RUN apt-get update && apt-get install libxml2-dev libsqlite3-dev -y + +## Allow the usage of private repository +### This part is for advanced user, ignore it if you don't use private repository in Swift package manager +## 1. Add SSH Hostname to known_host (This is use for Private repo in SPM) +## Here we add github.com hostname as when building the docker file we don't have an interactive shell +## It means it will be known from git, so won't request confirmation of the key +## You may want to add your own +## 2. It will use you private keys to clone private repository +## You private keys should be stored (Password less, decrypted) in the folder `ssh` +## for Continous integration, you will need a step to copy the decrypted key to the folder. Symbolic link won't work +RUN if [ -d "ssh" ]; then \ + mkdir -p ~/.ssh/; \ + eval `ssh-agent`; \ + ssh-keyscan -H github.com >> ~/.ssh/known_hosts; \ +fi + +## Build the application +RUN echo "---> Build application"; \ +if [ -d "ssh" ]; then \ + eval `ssh-agent`; \ + chmod 400 ssh/*; \ + ssh-add ssh/*; \ + swift build -c release --enable-test-discovery; \ +else \ + swift build -c release --enable-test-discovery; \ +fi + +RUN rm -rf */**/.DS_Store + +## Organizing things up +RUN mkdir -p /tmp/app + +## Check if the folder contains preexising DB/Folders. +## It means the user may have prepare Feather-CMS locally, in that case we will copy its content to the template folder +## So the user will keep what he prepared +RUN cd /opt/feather; if [ -f "db.sqlite" ]; then cp -pr db.sqlite /tmp/app; fi +RUN cd /opt/feather; if [ -d "Public" ]; then cp -pr Public /tmp/app; fi +RUN cd /opt/feather; if [ -d "Resources" ]; then cp -pr Resources /tmp/app; fi + +## Prepare entry point +RUN \ +echo '#!/bin/bash' > /tmp/app/start &&\ +echo "[[ ! -d \"\${BASE_PATH}/db.sqlite\" && -d /opt/feather/db.sqlite ]] && cp -pr /opt/feather/db.sqlite \${BASE_PATH}/" >> /tmp/app/start &&\ +echo "[[ ! -d \"\${BASE_PATH}/Public\" && -d /opt/feather/Public ]] && cp -pr /opt/feather/Public \${BASE_PATH}/" >> /tmp/app/start &&\ +echo "[[ ! -d \"\${BASE_PATH}/Resources\" && -d /opt/feather/Resources ]] && cp -pr /opt/feather/Resources \${BASE_PATH}/" >> /tmp/app/start &&\ +echo "Feather serve --hostname 0.0.0.0 --port \${BASE_PORT}" >> /tmp/app/start +RUN chmod 550 /tmp/app/start + +## Keep only executables & resources (will be available in /opt/feather/bin ) +RUN mv /opt/feather/.build/x86_64-unknown-linux-gnu/release /tmp/app/bin + +## Copy any custom scripts under the `customscripts` folder +## If the user decide to use a diffent enty point from start, he can create hsi own scripts. +## Ex. We could imagine, starting 10 servers in one docker. The script would set, different folders, env variables. It will not work with embeded DB here... +## docker run -d -p 8080-8090:8080-8090 feather start_10_apps +RUN if [ -d "/opt/feather/customscripts" ]; then \ + chmod 550 /opt/feather/customscripts/*; \ + cp -pr /opt/feather/customscripts/* /tmp/app/; \ +fi + +## Clean up & keep only executbale from the build +RUN cd /; rm -rf /opt/feather; mv /tmp/app /opt/feather + +## User feather +RUN groupadd -r feather && useradd --no-log-init -r -g feather feather +RUN chown -R feather:feather /opt/feather +RUN chmod 550 /opt/feather/bin/Feather + + + +## Slim version of the container +FROM swift:5.3.1-focal-slim +WORKDIR /var/feather +COPY --from=builder /opt/feather /opt/feather + +RUN \ + groupadd -r feather &&\ + useradd --no-log-init -r -g feather feather &&\ + mkdir -p /var/feather && chown -R feather:feather /var/feather &&\ + ln -s /opt/feather/bin/Feather /usr/local/bin/ + +USER feather + +ENV BASE_URL="http://localhost:8080" +ENV BASE_PORT=8080 +ENV BASE_PATH="/var/feather" + +## Default sqlite +ENV DBTYPE="sqlite" +ENV MAX_BODYSIZE="10mb" +ENV PROVIDE_MIDDLEWARE="true" + +## Using mysql/mariadb/postgres +ENV SQL_HOST="localhost" +# ENV SQL_PORT=3306 or 5432 # The port will use the default one, if you use a custom port, set this env variable +ENV SQL_USER="feather" +ENV SQL_PASSWORD="feather" +ENV SQL_DATABASE="feather" + +CMD [ "bash", "/opt/feather/start" ] + diff --git a/Package.resolved b/Package.resolved index fb8f479..86565d7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -109,6 +109,24 @@ "version": "1.10.1" } }, + { + "package": "fluent-mysql-driver", + "repositoryURL": "https://github.com/vapor/fluent-mysql-driver.git", + "state": { + "branch": null, + "revision": "699e164880387349bf04c2329fe53097524a5904", + "version": "4.0.0" + } + }, + { + "package": "fluent-postgres-driver", + "repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git", + "state": { + "branch": null, + "revision": "11d4fce0c5d8a027a5d131439c9c94dd3230cb8e", + "version": "2.1.2" + } + }, { "package": "fluent-sqlite-driver", "repositoryURL": "https://github.com/vapor/fluent-sqlite-driver", @@ -217,6 +235,42 @@ "version": "1.0.0-beta.2" } }, + { + "package": "mysql-kit", + "repositoryURL": "https://github.com/vapor/mysql-kit.git", + "state": { + "branch": null, + "revision": "fe836ecd52815ed1399e654b5365c108ff1638fd", + "version": "4.1.0" + } + }, + { + "package": "mysql-nio", + "repositoryURL": "https://github.com/vapor/mysql-nio.git", + "state": { + "branch": null, + "revision": "4cbef4c0903c9792ff1f8dc4b55532276fa70c99", + "version": "1.3.2" + } + }, + { + "package": "postgres-kit", + "repositoryURL": "https://github.com/vapor/postgres-kit.git", + "state": { + "branch": null, + "revision": "13f6c735cf9a9053011d03e77e2a81802ad6c680", + "version": "2.3.0" + } + }, + { + "package": "postgres-nio", + "repositoryURL": "https://github.com/vapor/postgres-nio.git", + "state": { + "branch": null, + "revision": "2808c4ff334c20073de92e735dac5587ba398b0d", + "version": "1.4.1" + } + }, { "package": "redirect-module", "repositoryURL": "https://github.com/feather-modules/redirect", diff --git a/Package.swift b/Package.swift index 0fa0994..3298016 100644 --- a/Package.swift +++ b/Package.swift @@ -13,6 +13,8 @@ let package = Package( .package(url: "https://github.com/binarybirds/feather-core", from: "1.0.0-beta"), /// drivers .package(url: "https://github.com/vapor/fluent-sqlite-driver", from: "4.0.0"), + .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0"), + .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"), .package(url: "https://github.com/binarybirds/liquid-local-driver", from: "1.2.0-beta"), /// modules .package(name: "file-module", url: "https://github.com/feather-modules/file", from: "1.0.0-beta"), @@ -32,6 +34,8 @@ let package = Package( .product(name: "FeatherCore", package: "feather-core"), /// drivers .product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"), + .product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"), + .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"), .product(name: "LiquidLocalDriver", package: "liquid-local-driver"), /// modules .product(name: "FileModule", package: "file-module"), diff --git a/Sources/Feather/Feather+DataBases.swift b/Sources/Feather/Feather+DataBases.swift new file mode 100644 index 0000000..4cd437c --- /dev/null +++ b/Sources/Feather/Feather+DataBases.swift @@ -0,0 +1,91 @@ +// +// Feather+DataBases.swift +// +// +// Created by Tibor Bodecs on 2020. 12. 13.. +// + +import FeatherCore +import LiquidLocalDriver +import FluentMySQLDriver +import FluentPostgresDriver +import FluentSQLiteDriver + +extension Feather { + + /// + /// This function will autoconfigure the instance using system environment variables + /// + /// Using this fonction require the system `ENVIRONEMENT variables` to be set OR an env.`` file. + /// # Reference: + /// For more details on how to use env.`` file, refer to the [Vapor 4 documentation](https://docs.vapor.codes/4.0/environment) + /// + /// # Required: + /// ~~~ + /// BASE_URL="http://127.0.0.1:8080" + /// BASE_PATH="/Repo/feather" + /// ~~~ + /// # Optional: + /// ~~~ + /// MAX_BODYSIZE="10mb" (default) - Required format: XXmb + /// PROVIDE_MIDDLEWARE="true" (default) - Required format: true/false + /// + /// DBTYPE="mysql" # Available: sqlite (default) / mysql / postgres + /// SQL_HOST="127.0.0.1" + /// SQL_USER="feather" + /// SQL_PASSWORD="feather" + /// SQL_DATABASE="feather" + /// + /// # Optional: For DBTYPE = "mysql" | "postgres" + /// SQL_PORT=3306 # mysql: 3306 (default) - postgres: 5432(default) + /// ~~~ + /// + + /// - Throws: `Error` due to `modules` registration + /// + /// - parameters: + /// - modules: An Array containing intances of type [ViperBuilder](https://github.com/BinaryBirds/viper-kit) + /// + public func configureWithEnv(modules userModules: [ViperBuilder] = []) throws { + + let dbconfig: DatabaseConfigurationFactory + let dbID: DatabaseID + switch Environment.get("DBTYPE") { + case "mysql": + dbconfig = .mysql(hostname: Environment.fetch("SQL_HOST"), + port: Int(Environment.get("SQL_PORT") ?? "3306")!, + username: Environment.fetch("SQL_USER"), + password: Environment.fetch("SQL_PASSWORD"), + database: Environment.fetch("SQL_DATABASE"), + tlsConfiguration: .forClient(certificateVerification: .none)) + dbID = .mysql + break + case "postgres": + dbconfig = .postgres(hostname: Environment.fetch("SQL_HOST"), + port: Int(Environment.get("SQL_PORT") ?? "5432")!, + username: Environment.fetch("SQL_USER"), + password: Environment.fetch("SQL_PASSWORD"), + database: Environment.fetch("SQL_DATABASE")) + dbID = .psql + break + default: + dbconfig = .sqlite(.file("db.sqlite")) + dbID = .sqlite + break + } + + var middleWare = true + if let provideMiddleWare = Environment.get("PROVIDE_MIDDLEWARE") { + middleWare = Bool(provideMiddleWare) ?? true + } + try feather.configure(database: dbconfig, + databaseId: dbID, + fileStorage: .local(publicUrl: Application.baseUrl, publicPath: Application.Paths.public, workDirectory: "assets"), + fileStorageId: .local, + maxUploadSize: ByteCount(stringLiteral: Environment.get("MAX_BODYSIZE") ?? "10mb"), + modules: userModules, + usePublicFileMiddleware: middleWare + ) + } + +} diff --git a/Sources/Feather/main.swift b/Sources/Feather/main.swift index a447315..6dc9377 100644 --- a/Sources/Feather/main.swift +++ b/Sources/Feather/main.swift @@ -6,8 +6,6 @@ // import FeatherCore -import FluentSQLiteDriver -import LiquidLocalDriver import FileModule import RedirectModule @@ -23,11 +21,7 @@ try LoggingSystem.bootstrap(from: &env) let feather = try Feather(env: env) defer { feather.stop() } -try feather.configure(database: .sqlite(.file("db.sqlite")), - databaseId: .sqlite, - fileStorage: .local(publicUrl: Application.baseUrl, publicPath: Application.Paths.public, workDirectory: "assets"), - fileStorageId: .local, - modules: [ +try feather.configureWithEnv(modules: [ FileBuilder(), RedirectBuilder(), BlogBuilder(), diff --git a/docker/build.bat b/docker/build.bat new file mode 100644 index 0000000..7cc7074 --- /dev/null +++ b/docker/build.bat @@ -0,0 +1,2 @@ +docker build --force-rm=true --no-cache=true -t="feather:1.0" .. +docker tag feather:1.0 feather:latest diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 0000000..6ca8e98 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,4 @@ +# #!/bin/bash + +docker build --force-rm=true --no-cache=true -t="feather:1.0" .. +docker tag feather:1.0 feather:latest diff --git a/docker/try_embedded.bat b/docker/try_embedded.bat new file mode 100644 index 0000000..d59a2bb --- /dev/null +++ b/docker/try_embedded.bat @@ -0,0 +1,15 @@ +@echo off + +REM Base Path (Shared with containers) +set BASE_PATH=C:%homepath%\docker-feather-data\embedded + +set APP_NAME=feather-app-embedded + +REM ## Start Feather App +docker stop %APP_NAME% +docker rm %APP_NAME% +docker run -d --restart=unless-stopped -v %BASE_PATH%:/var/feather -p 8080:8080 --name %APP_NAME% feather + +echo You can connect to: +echo http://127.0.0.1:8080 +timeout 10 diff --git a/docker/try_embedded.sh b/docker/try_embedded.sh new file mode 100755 index 0000000..9120a70 --- /dev/null +++ b/docker/try_embedded.sh @@ -0,0 +1,16 @@ +# #!/bin/bash + +## Base Path (Shared with containers) +export BASE_PATH=$PWD/docker-feather-data/embedded + +export APP_NAME=feather-app-embedded + +## Start Feather App +docker stop $APP_NAME +docker rm $APP_NAME +docker run -d --restart=unless-stopped -v $BASE_PATH:/var/feather -p 8080:8080 --name $APP_NAME feather + +echo "You can connect to: " +echo " http://127.0.0.1:8080" +echo "" +sleep 10 diff --git a/docker/try_mysql.bat b/docker/try_mysql.bat new file mode 100644 index 0000000..0a8b521 --- /dev/null +++ b/docker/try_mysql.bat @@ -0,0 +1,48 @@ +@echo off + +REM Base Path (Shared with containers) +set BASE_PATH=C:%homepath%\docker-feather-data\mysql + + +REM Feather App +set APP_NAME=feather-app-mariadb +set SQL_NAME=feather-db-mariadb + +REM MySQL Root Password +set MYSQLPORT=3306 +set MYSQLROOTPW=rootfeather + +REM MySQL Feather App db details +set MYSQLFEATHERTABLE=feather +set MYSQLFEATHERUSER=feather +set MYSQLFEATHERPW=feather + + +REM MariaDB SQL (You can use mysql if you want) +REM We will use this network for our app, so opening port 8081 here +docker stop %SQL_NAME% +docker rm %SQL_NAME% +docker run -d --name=%SQL_NAME% -p %MYSQLPORT%:3306 -p 8081:8081 -v %BASE_PATH%\mysql\datadir:/var/lib/mysql -v %BASE_PATH%\mysql\log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=%MYSQLROOTPW% -e MYSQL_ROOT_HOST=%% --restart=unless-stopped mariadb:latest + +REM Sleep to give time for the DB to start +echo Waiting 30 secs, to give time for the DB to start... +timeout 30 + +REM Create DB, user +echo CREATE DATABASE %MYSQLFEATHERTABLE%; > feathermysql.sql +echo CREATE USER '%MYSQLFEATHERUSER%'@'%%' IDENTIFIED BY '%MYSQLFEATHERPW%'; >> feathermysql.sql +echo GRANT ALL ON `%MYSQLFEATHERTABLE%`.* TO '%MYSQLFEATHERUSER%'@'%%'; >> feathermysql.sql +echo SELECT host, user FROM mysql.user; >> feathermysql.sql + +docker exec -i %SQL_NAME% mysql -uroot -p%MYSQLROOTPW% < feathermysql.sql +del feathermysql.sql + + +REM Start Feather App +docker stop %APP_NAME% +docker rm %APP_NAME% +docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8081" -e BASE_PORT=8081 -e DBTYPE=mysql -e SQL_HOST=127.0.0.1 -e SQL_PORT=3306 -e SQL_DATABASE=%MYSQLFEATHERTABLE% -e SQL_USER=%MYSQLFEATHERUSER% -e SQL_PASSWORD=%MYSQLFEATHERPW% -e MAX_BODYSIZE="10mb" -d feather + +echo You can connect to: +echo http://127.0.0.1:8081 +timeout 10 diff --git a/docker/try_mysql.sh b/docker/try_mysql.sh new file mode 100755 index 0000000..ff4996c --- /dev/null +++ b/docker/try_mysql.sh @@ -0,0 +1,70 @@ +# #!/bin/bash + +## Base Path (Shared with containers) +export BASE_PATH=$PWD/docker-feather-data/mysql + +## Feather App +export APP_NAME=feather-app-mariadb +export SQL_NAME=feather-db-mariadb + +### MySQL Root Password +export MYSQLPORT=3306 +export MYSQLROOTPW=rootfeather + +### MySQL Feather App db details +export MYSQLFEATHERTABLE=feather +export MYSQLFEATHERUSER=feather +export MYSQLFEATHERPW=feather + + +### MariaDB SQL (You can use mysql if you want) +### We will use this network for our app, so opening port 8081 here +docker stop $SQL_NAME +docker rm $SQL_NAME +docker run -d --name=$SQL_NAME \ + -p $MYSQLPORT:3306 \ + -p 8081:8081 \ + -v $BASE_PATH/mysql/datadir:/var/lib/mysql \ + -v $BASE_PATH/mysql/log:/var/log/mysql \ + -e MYSQL_ROOT_PASSWORD=$MYSQLROOTPW \ + -e MYSQL_ROOT_HOST=% \ + --restart=unless-stopped \ + mariadb:latest \ + --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + +## Sleep to give time for the DB to start +echo "Waiting 30 secs, to give time for the DB to start..." +sleep 30 + +### Create DB, user +echo "CREATE DATABASE ${MYSQLFEATHERTABLE}; \ +CREATE USER '${MYSQLFEATHERUSER}'@'%' IDENTIFIED BY '${MYSQLFEATHERPW}'; \ +grant all on \`${MYSQLFEATHERTABLE}\`.* to '${MYSQLFEATHERUSER}'@'%'; \ +SELECT host, user FROM mysql.user;" \ +> feathermysql.sql +docker exec -i $SQL_NAME mysql -uroot -p$MYSQLROOTPW < feathermysql.sql && true +rm feathermysql.sql + + +## Start Feather App +docker stop $APP_NAME +docker rm $APP_NAME +docker run -d --name $APP_NAME \ + --restart=unless-stopped \ + --net=container:$SQL_NAME \ + -v $BASE_PATH:/var/feather \ + -e BASE_URL="http://localhost:8081" \ + -e BASE_PORT=8081 \ + -e DBTYPE=mysql \ + -e SQL_HOST=127.0.0.1 \ + -e SQL_PORT=3306 \ + -e SQL_DATABASE=$MYSQLFEATHERTABLE \ + -e SQL_USER=$MYSQLFEATHERUSER \ + -e SQL_PASSWORD=$MYSQLFEATHERPW \ + -e MAX_BODYSIZE="10mb" \ + -d feather + +echo "You can connect to: " +echo " http://127.0.0.1:8081" +echo "" +sleep 10 diff --git a/docker/try_postgres.bat b/docker/try_postgres.bat new file mode 100644 index 0000000..1b927d3 --- /dev/null +++ b/docker/try_postgres.bat @@ -0,0 +1,43 @@ +@echo off + +REM Base Path (Shared with containers) +set BASE_PATH=C:%homepath%\docker-feather-data\postgres + +REM Feather App +set APP_NAME=feather-app-postgres +set SQL_NAME=feather-db-postgres + +REM postgres Root Password +set POSTGRESPORT=5432 +set POSTGRES_ROOTPW=postgres +set POSTGRES_USER=feather +set POSTGRES_PASSWORD=feather +set POSTGRES_DB=feather + +REM Postgres SQL +REM We will use this network for our app, so opening port 8082 here +docker stop %SQL_NAME% +docker rm %SQL_NAME% +docker run -d --name=%SQL_NAME% --restart=unless-stopped -p %POSTGRESPORT%:5432 -p 8082:8082 -v %BASE_PATH%\postgresql\data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=%POSTGRES_ROOTPW% -d postgres + +REM Sleep to give time for the DB to start +echo "Waiting 30 secs, to give time for the DB to start..." +timeout 30 + +REM Create DB, user +echo CREATE DATABASE %POSTGRES_DB%; > featherpostgres.sql +echo CREATE USER %POSTGRES_DB% WITH PASSWORD '%POSTGRES_DB%'; >> featherpostgres.sql +echo GRANT ALL PRIVILEGES ON DATABASE %POSTGRES_DB% TO %POSTGRES_DB%; >> featherpostgres.sql + +docker exec -i %SQL_NAME% psql -U postgres < featherpostgres.sql +del featherpostgres.sql + + +REM Start Feather App +docker stop %APP_NAME% +docker rm %APP_NAME% +docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8082" -e BASE_PORT=8082 -e DBTYPE=postgres -e SQL_HOST=127.0.0.1 -e SQL_PORT=5432 -e SQL_DATABASE=%POSTGRES_DB% -e SQL_USER=%POSTGRES_USER% -e SQL_PASSWORD=%POSTGRES_PASSWORD% -e MAX_BODYSIZE="10mb" -d feather + +echo You can connect to: +echo http://127.0.0.1:8082 +timeout 10 diff --git a/docker/try_postgres.sh b/docker/try_postgres.sh new file mode 100755 index 0000000..934ccf4 --- /dev/null +++ b/docker/try_postgres.sh @@ -0,0 +1,63 @@ +# #!/bin/bash + +## Base Path (Shared with containers) +export BASE_PATH=$PWD/docker-feather-data/postgres + +## Feather App +export APP_NAME=feather-app-postgres +export SQL_NAME=feather-db-postgres + +### postgres Root Password +export POSTGRESPORT=5432 +export POSTGRES_ROOTPW=postgres +export POSTGRES_USER=feather +export POSTGRES_PASSWORD=feather +export POSTGRES_DB=feather + +### Postgres SQL +### We will use this network for our app, so opening port 8082 here +docker stop $SQL_NAME +docker rm $SQL_NAME +docker run -d --name=$SQL_NAME \ + --restart=unless-stopped \ + -p $POSTGRESPORT:5432 \ + -p 8082:8082 \ + -v $BASE_PATH/postgresql/data:/var/lib/postgresql/data \ + -e POSTGRES_PASSWORD=$POSTGRES_ROOTPW \ + -d postgres + +## Sleep to give time for the DB to start +echo "Waiting 30 secs, to give time for the DB to start..." +sleep 30 + +### Create DB, user +echo "CREATE DATABASE ${POSTGRES_DB}; \ +CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}'; \ +GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_USER};" \ +> featherpostgres.sql +docker exec -i $SQL_NAME psql -U postgres < featherpostgres.sql && true +rm featherpostgres.sql + + +## Start Feather App +docker stop $APP_NAME +docker rm $APP_NAME +docker run -d --name $APP_NAME \ + --restart=unless-stopped \ + --net=container:$SQL_NAME \ + -v $BASE_PATH:/var/feather \ + -e BASE_URL="http://localhost:8082" \ + -e BASE_PORT=8082 \ + -e DBTYPE=postgres \ + -e SQL_HOST=127.0.0.1 \ + -e SQL_PORT=5432 \ + -e SQL_DATABASE=$POSTGRES_DB \ + -e SQL_USER=$POSTGRES_USER \ + -e SQL_PASSWORD=$POSTGRES_PASSWORD \ + -e MAX_BODYSIZE="10mb" \ + -d feather + +echo "You can connect to: " +echo " http://127.0.0.1:8082" +echo "" +sleep 10 From 73fbaa52236a6af91da71dbd60d54da2603989c1 Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Sat, 19 Dec 2020 15:48:30 +0100 Subject: [PATCH 2/7] Updated environment variable naming / removed extension --- Dockerfile | 14 ++-- Sources/Feather/Feather+DataBases.swift | 91 ------------------------- Sources/Feather/main.swift | 87 +++++++++++++++++++++-- docker/try_mysql.bat | 2 +- docker/try_mysql.sh | 12 ++-- docker/try_postgres.bat | 2 +- docker/try_postgres.sh | 12 ++-- 7 files changed, 104 insertions(+), 116 deletions(-) delete mode 100644 Sources/Feather/Feather+DataBases.swift diff --git a/Dockerfile b/Dockerfile index 9d6a529..70d7944 100644 --- a/Dockerfile +++ b/Dockerfile @@ -93,16 +93,16 @@ ENV BASE_PORT=8080 ENV BASE_PATH="/var/feather" ## Default sqlite -ENV DBTYPE="sqlite" +ENV DB_TYPE="sqlite" ENV MAX_BODYSIZE="10mb" -ENV PROVIDE_MIDDLEWARE="true" +ENV USE_FILE_MIDDLEWARE="true" ## Using mysql/mariadb/postgres -ENV SQL_HOST="localhost" -# ENV SQL_PORT=3306 or 5432 # The port will use the default one, if you use a custom port, set this env variable -ENV SQL_USER="feather" -ENV SQL_PASSWORD="feather" -ENV SQL_DATABASE="feather" +ENV DB_HOST="localhost" +# ENV DB_PORT=3306 or 5432 # The port will use the default one, if you use a custom port, set this env variable +ENV DB_USER="feather" +ENV DB_PASS="feather" +ENV DB_NAME="feather" CMD [ "bash", "/opt/feather/start" ] diff --git a/Sources/Feather/Feather+DataBases.swift b/Sources/Feather/Feather+DataBases.swift deleted file mode 100644 index 4cd437c..0000000 --- a/Sources/Feather/Feather+DataBases.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// Feather+DataBases.swift -// -// -// Created by Tibor Bodecs on 2020. 12. 13.. -// - -import FeatherCore -import LiquidLocalDriver -import FluentMySQLDriver -import FluentPostgresDriver -import FluentSQLiteDriver - -extension Feather { - - /// - /// This function will autoconfigure the instance using system environment variables - /// - /// Using this fonction require the system `ENVIRONEMENT variables` to be set OR an env.`` file. - /// # Reference: - /// For more details on how to use env.`` file, refer to the [Vapor 4 documentation](https://docs.vapor.codes/4.0/environment) - /// - /// # Required: - /// ~~~ - /// BASE_URL="http://127.0.0.1:8080" - /// BASE_PATH="/Repo/feather" - /// ~~~ - /// # Optional: - /// ~~~ - /// MAX_BODYSIZE="10mb" (default) - Required format: XXmb - /// PROVIDE_MIDDLEWARE="true" (default) - Required format: true/false - /// - /// DBTYPE="mysql" # Available: sqlite (default) / mysql / postgres - /// SQL_HOST="127.0.0.1" - /// SQL_USER="feather" - /// SQL_PASSWORD="feather" - /// SQL_DATABASE="feather" - /// - /// # Optional: For DBTYPE = "mysql" | "postgres" - /// SQL_PORT=3306 # mysql: 3306 (default) - postgres: 5432(default) - /// ~~~ - /// - - /// - Throws: `Error` due to `modules` registration - /// - /// - parameters: - /// - modules: An Array containing intances of type [ViperBuilder](https://github.com/BinaryBirds/viper-kit) - /// - public func configureWithEnv(modules userModules: [ViperBuilder] = []) throws { - - let dbconfig: DatabaseConfigurationFactory - let dbID: DatabaseID - switch Environment.get("DBTYPE") { - case "mysql": - dbconfig = .mysql(hostname: Environment.fetch("SQL_HOST"), - port: Int(Environment.get("SQL_PORT") ?? "3306")!, - username: Environment.fetch("SQL_USER"), - password: Environment.fetch("SQL_PASSWORD"), - database: Environment.fetch("SQL_DATABASE"), - tlsConfiguration: .forClient(certificateVerification: .none)) - dbID = .mysql - break - case "postgres": - dbconfig = .postgres(hostname: Environment.fetch("SQL_HOST"), - port: Int(Environment.get("SQL_PORT") ?? "5432")!, - username: Environment.fetch("SQL_USER"), - password: Environment.fetch("SQL_PASSWORD"), - database: Environment.fetch("SQL_DATABASE")) - dbID = .psql - break - default: - dbconfig = .sqlite(.file("db.sqlite")) - dbID = .sqlite - break - } - - var middleWare = true - if let provideMiddleWare = Environment.get("PROVIDE_MIDDLEWARE") { - middleWare = Bool(provideMiddleWare) ?? true - } - try feather.configure(database: dbconfig, - databaseId: dbID, - fileStorage: .local(publicUrl: Application.baseUrl, publicPath: Application.Paths.public, workDirectory: "assets"), - fileStorageId: .local, - maxUploadSize: ByteCount(stringLiteral: Environment.get("MAX_BODYSIZE") ?? "10mb"), - modules: userModules, - usePublicFileMiddleware: middleWare - ) - } - -} diff --git a/Sources/Feather/main.swift b/Sources/Feather/main.swift index 6dc9377..2d81c97 100644 --- a/Sources/Feather/main.swift +++ b/Sources/Feather/main.swift @@ -6,29 +6,108 @@ // import FeatherCore +import FluentSQLiteDriver +import LiquidLocalDriver + +import SystemModule +import UserModule +import ApiModule +import AdminModule +import FrontendModule import FileModule import RedirectModule -import BlogModule +//import BlogModule import AnalyticsModule import AggregatorModule import SponsorModule import SwiftyModule import MarkdownModule +/// setup metadata delegate object +Feather.metadataDelegate = FrontendMetadataDelegate() + var env = try Environment.detect() try LoggingSystem.bootstrap(from: &env) let feather = try Feather(env: env) defer { feather.stop() } -try feather.configureWithEnv(modules: [ +let dbconfig: DatabaseConfigurationFactory +let dbID: DatabaseID +switch Environment.get("DB_TYPE") { +case "mysql": + dbconfig = .mysql(hostname: Environment.fetch("DB_HOST"), + port: Int(Environment.get("DB_PORT") ?? "3306")!, + username: Environment.fetch("DB_USER"), + password: Environment.fetch("DB_PASS"), + database: Environment.fetch("DB_NAME"), + tlsConfiguration: .forClient(certificateVerification: .none)) + dbID = .mysql + break +case "postgres": + dbconfig = .postgres(hostname: Environment.fetch("DB_HOST"), + port: Int(Environment.get("DB_PORT") ?? "5432")!, + username: Environment.fetch("DB_USER"), + password: Environment.fetch("DB_PASS"), + database: Environment.fetch("DB_NAME")) + dbID = .psql + break +default: + dbconfig = .sqlite(.file("db.sqlite")) + dbID = .sqlite + break +} + +var middleWare = true +if let provideMiddleWare = Environment.get("USE_FILE_MIDDLEWARE") { + middleWare = Bool(provideMiddleWare) ?? true +} + +/// # Required: +/// ~~~ +/// BASE_URL="http://127.0.0.1:8080" +/// BASE_PATH="/Repo/feather" +/// ~~~ +/// # Optional: +/// ~~~ +/// MAX_BODYSIZE="10mb" (default) - Required format: XXmb +/// USE_FILE_MIDDLEWARE="true" (default) - Required format: true/false +/// +/// DB_TYPE="mysql" # Available: sqlite (default) / mysql / postgres +/// DB_HOST="127.0.0.1" +/// DB_USER="feather" +/// DB_PASS="feather" +/// DB_NAME="feather" +/// +/// # Optional: For DB_TYPE = "mysql" | "postgres" +/// DB_PORT=3306 # mysql: 3306 (default) - postgres: 5432(default) +/// ~~~ +/// + +try feather.configure(database: dbconfig, + databaseId: dbID, + fileStorage: .local(publicUrl: Application.baseUrl, publicPath: Application.Paths.public, workDirectory: "assets"), + fileStorageId: .local, + maxUploadSize: ByteCount(stringLiteral: Environment.get("MAX_BODYSIZE") ?? "10mb"), + modules: [ + SystemBuilder(), + UserBuilder(), + ApiBuilder(), + AdminBuilder(), + FrontendBuilder(), + FileBuilder(), RedirectBuilder(), - BlogBuilder(), +// BlogBuilder(), AnalyticsBuilder(), AggregatorBuilder(), SponsorBuilder(), SwiftyBuilder(), MarkdownBuilder(), - ]) + ], + usePublicFileMiddleware: middleWare) + +if feather.app.isDebug { + try feather.reset(resourcesOnly: true) +} try feather.start() diff --git a/docker/try_mysql.bat b/docker/try_mysql.bat index 0a8b521..8b20502 100644 --- a/docker/try_mysql.bat +++ b/docker/try_mysql.bat @@ -41,7 +41,7 @@ del feathermysql.sql REM Start Feather App docker stop %APP_NAME% docker rm %APP_NAME% -docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8081" -e BASE_PORT=8081 -e DBTYPE=mysql -e SQL_HOST=127.0.0.1 -e SQL_PORT=3306 -e SQL_DATABASE=%MYSQLFEATHERTABLE% -e SQL_USER=%MYSQLFEATHERUSER% -e SQL_PASSWORD=%MYSQLFEATHERPW% -e MAX_BODYSIZE="10mb" -d feather +docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8081" -e BASE_PORT=8081 -e DB_TYPE=mysql -e DB_HOST=127.0.0.1 -e DB_PORT=3306 -e DB_NAME=%MYSQLFEATHERTABLE% -e DB_USER=%MYSQLFEATHERUSER% -e DB_PASS=%MYSQLFEATHERPW% -e MAX_BODYSIZE="10mb" -d feather echo You can connect to: echo http://127.0.0.1:8081 diff --git a/docker/try_mysql.sh b/docker/try_mysql.sh index ff4996c..45fc474 100755 --- a/docker/try_mysql.sh +++ b/docker/try_mysql.sh @@ -55,12 +55,12 @@ docker run -d --name $APP_NAME \ -v $BASE_PATH:/var/feather \ -e BASE_URL="http://localhost:8081" \ -e BASE_PORT=8081 \ - -e DBTYPE=mysql \ - -e SQL_HOST=127.0.0.1 \ - -e SQL_PORT=3306 \ - -e SQL_DATABASE=$MYSQLFEATHERTABLE \ - -e SQL_USER=$MYSQLFEATHERUSER \ - -e SQL_PASSWORD=$MYSQLFEATHERPW \ + -e DB_TYPE=mysql \ + -e DB_HOST=127.0.0.1 \ + -e DB_PORT=3306 \ + -e DB_NAME=$MYSQLFEATHERTABLE \ + -e DB_USER=$MYSQLFEATHERUSER \ + -e DB_PASS=$MYSQLFEATHERPW \ -e MAX_BODYSIZE="10mb" \ -d feather diff --git a/docker/try_postgres.bat b/docker/try_postgres.bat index 1b927d3..bdcde0c 100644 --- a/docker/try_postgres.bat +++ b/docker/try_postgres.bat @@ -36,7 +36,7 @@ del featherpostgres.sql REM Start Feather App docker stop %APP_NAME% docker rm %APP_NAME% -docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8082" -e BASE_PORT=8082 -e DBTYPE=postgres -e SQL_HOST=127.0.0.1 -e SQL_PORT=5432 -e SQL_DATABASE=%POSTGRES_DB% -e SQL_USER=%POSTGRES_USER% -e SQL_PASSWORD=%POSTGRES_PASSWORD% -e MAX_BODYSIZE="10mb" -d feather +docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8082" -e BASE_PORT=8082 -e DB_TYPE=postgres -e DB_HOST=127.0.0.1 -e DB_PORT=5432 -e DB_NAME=%POSTGRES_DB% -e DB_USER=%POSTGRES_USER% -e DB_PASS=%POSTGRES_PASSWORD% -e MAX_BODYSIZE="10mb" -d feather echo You can connect to: echo http://127.0.0.1:8082 diff --git a/docker/try_postgres.sh b/docker/try_postgres.sh index 934ccf4..40598dd 100755 --- a/docker/try_postgres.sh +++ b/docker/try_postgres.sh @@ -48,12 +48,12 @@ docker run -d --name $APP_NAME \ -v $BASE_PATH:/var/feather \ -e BASE_URL="http://localhost:8082" \ -e BASE_PORT=8082 \ - -e DBTYPE=postgres \ - -e SQL_HOST=127.0.0.1 \ - -e SQL_PORT=5432 \ - -e SQL_DATABASE=$POSTGRES_DB \ - -e SQL_USER=$POSTGRES_USER \ - -e SQL_PASSWORD=$POSTGRES_PASSWORD \ + -e DB_TYPE=postgres \ + -e DB_HOST=127.0.0.1 \ + -e DB_PORT=5432 \ + -e DB_NAME=$POSTGRES_DB \ + -e DB_USER=$POSTGRES_USER \ + -e DB_PASS=$POSTGRES_PASSWORD \ -e MAX_BODYSIZE="10mb" \ -d feather From 42a77dc1fc478eee81772ddd9a7c13ab3e036078 Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Wed, 23 Dec 2020 18:06:34 +0100 Subject: [PATCH 3/7] Fixed missing imports and moved doc --- Sources/Feather/main.swift | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Sources/Feather/main.swift b/Sources/Feather/main.swift index 906e11e..6a6a36e 100644 --- a/Sources/Feather/main.swift +++ b/Sources/Feather/main.swift @@ -7,6 +7,8 @@ import FeatherCore import FluentSQLiteDriver +import FluentMySQLDriver +import FluentPostgresDriver import LiquidLocalDriver import SystemModule @@ -27,6 +29,27 @@ import MarkdownModule /// setup metadata delegate object Feather.metadataDelegate = FrontendMetadataDelegate() +/// Detect the DB type from .env.development or the environement variables +/// # Required: +/// ~~~ +/// BASE_URL="http://127.0.0.1:8080" +/// BASE_PATH="/Repo/feather" +/// ~~~ +/// # Optional: +/// ~~~ +/// MAX_BODYSIZE="10mb" (default) - Required format: XXmb +/// USE_FILE_MIDDLEWARE="true" (default) - Required format: true/false +/// +/// DB_TYPE="mysql" # Available: sqlite (default) / mysql / postgres +/// DB_HOST="127.0.0.1" +/// DB_USER="feather" +/// DB_PASS="feather" +/// DB_NAME="feather" +/// +/// # Optional: For DB_TYPE = "mysql" | "postgres" +/// DB_PORT=3306 # mysql: 3306 (default) - postgres: 5432(default) +/// ~~~ +/// var env = try Environment.detect() try LoggingSystem.bootstrap(from: &env) let feather = try Feather(env: env) @@ -63,27 +86,6 @@ if let provideMiddleWare = Environment.get("USE_FILE_MIDDLEWARE") { middleWare = Bool(provideMiddleWare) ?? true } -/// # Required: -/// ~~~ -/// BASE_URL="http://127.0.0.1:8080" -/// BASE_PATH="/Repo/feather" -/// ~~~ -/// # Optional: -/// ~~~ -/// MAX_BODYSIZE="10mb" (default) - Required format: XXmb -/// USE_FILE_MIDDLEWARE="true" (default) - Required format: true/false -/// -/// DB_TYPE="mysql" # Available: sqlite (default) / mysql / postgres -/// DB_HOST="127.0.0.1" -/// DB_USER="feather" -/// DB_PASS="feather" -/// DB_NAME="feather" -/// -/// # Optional: For DB_TYPE = "mysql" | "postgres" -/// DB_PORT=3306 # mysql: 3306 (default) - postgres: 5432(default) -/// ~~~ -/// - try feather.configure(database: dbconfig, databaseId: dbID, fileStorage: .local(publicUrl: Application.baseUrl, publicPath: Application.Paths.public, workDirectory: "assets"), From a2fb6c4a4b507aedf82d247e8944686f23454b4f Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Wed, 23 Dec 2020 22:17:17 +0100 Subject: [PATCH 4/7] Added Docker compose for sqlite, postgres & mysql --- Package.resolved | 8 ++-- Package.swift | 4 +- docker/build.bat | 2 - docker/build.sh | 4 -- docker/docker-compose.yml | 9 ++++ docker/mysql.yml | 42 ++++++++++++++++++ docker/postgres.yml | 40 +++++++++++++++++ docker/scripts/1-mysql-init.sql | 4 ++ docker/scripts/1-postgres-init.sql | 3 ++ docker/scripts/waitfor | 12 +++++ docker/try_embedded.bat | 15 ------- docker/try_embedded.sh | 16 ------- docker/try_mysql.bat | 48 -------------------- docker/try_mysql.sh | 70 ------------------------------ docker/try_postgres.bat | 43 ------------------ docker/try_postgres.sh | 63 --------------------------- 16 files changed, 116 insertions(+), 267 deletions(-) delete mode 100644 docker/build.bat delete mode 100755 docker/build.sh create mode 100644 docker/docker-compose.yml create mode 100644 docker/mysql.yml create mode 100644 docker/postgres.yml create mode 100644 docker/scripts/1-mysql-init.sql create mode 100644 docker/scripts/1-postgres-init.sql create mode 100755 docker/scripts/waitfor delete mode 100644 docker/try_embedded.bat delete mode 100755 docker/try_embedded.sh delete mode 100644 docker/try_mysql.bat delete mode 100755 docker/try_mysql.sh delete mode 100644 docker/try_postgres.bat delete mode 100755 docker/try_postgres.sh diff --git a/Package.resolved b/Package.resolved index f0d4d2c..15e8ac3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -129,7 +129,7 @@ }, { "package": "fluent-mysql-driver", - "repositoryURL": "https://github.com/vapor/fluent-mysql-driver.git", + "repositoryURL": "https://github.com/vapor/fluent-mysql-driver", "state": { "branch": null, "revision": "699e164880387349bf04c2329fe53097524a5904", @@ -138,7 +138,7 @@ }, { "package": "fluent-postgres-driver", - "repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git", + "repositoryURL": "https://github.com/vapor/fluent-postgres-driver", "state": { "branch": null, "revision": "11d4fce0c5d8a027a5d131439c9c94dd3230cb8e", @@ -465,8 +465,8 @@ "repositoryURL": "https://github.com/FeatherCMS/system-module", "state": { "branch": null, - "revision": "5d6804551621f154aeb11aaec88870b58bcdee80", - "version": "1.0.0-beta.6" + "revision": "4e10c15c3ed45cdcc2edc67f205daa29b5f23199", + "version": "1.0.0-beta.8" } }, { diff --git a/Package.swift b/Package.swift index a0fbfb4..e295bd1 100644 --- a/Package.swift +++ b/Package.swift @@ -15,8 +15,8 @@ let package = Package( .package(url: "https://github.com/binarybirds/spec.git", from: "1.2.0-beta"), /// drivers .package(url: "https://github.com/vapor/fluent-sqlite-driver", from: "4.0.0"), - .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0"), - .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"), + .package(url: "https://github.com/vapor/fluent-mysql-driver", from: "4.0.0"), + .package(url: "https://github.com/vapor/fluent-postgres-driver", from: "2.0.0"), .package(url: "https://github.com/binarybirds/liquid-local-driver", from: "1.2.0-beta"), /// feather core .package(url: "https://github.com/FeatherCMS/feather-core", from: "1.0.0-beta"), diff --git a/docker/build.bat b/docker/build.bat deleted file mode 100644 index 7cc7074..0000000 --- a/docker/build.bat +++ /dev/null @@ -1,2 +0,0 @@ -docker build --force-rm=true --no-cache=true -t="feather:1.0" .. -docker tag feather:1.0 feather:latest diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 6ca8e98..0000000 --- a/docker/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -# #!/bin/bash - -docker build --force-rm=true --no-cache=true -t="feather:1.0" .. -docker tag feather:1.0 feather:latest diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..7b01748 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3.9" +## docker-compose up +services: + feather: + build: .. + ports: + - "8080:8080" + volumes: + - ./docker-feather-data/sqlite:/var/feather \ No newline at end of file diff --git a/docker/mysql.yml b/docker/mysql.yml new file mode 100644 index 0000000..7f1f08b --- /dev/null +++ b/docker/mysql.yml @@ -0,0 +1,42 @@ +version: "3.9" +## docker-compose -f mysql.yml up +services: + + ## Database + database: + container_name: mariadb + image: mariadb + command: --default-authentication-plugin=mysql_native_password + volumes: + - "./scripts/1-mysql-init.sql:/docker-entrypoint-initdb.d/1.sql" + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_ROOT_HOST: '%' + ports: + - "3306:3306" + expose: + - 3306 + + ## Application + feather: + depends_on: + - database + container_name: feather-mariadb + build: .. + ports: + - "8081:8081" + expose: + - 8081 + environment: + BASE_URL: "http://localhost:8081" + BASE_PORT: 8081 + DB_HOST: database + DB_PORT: 3306 + DB_TYPE: mysql + DB_USER: "feather" + DB_PASS: "feather" + DB_NAME: "feather" + volumes: + - ./docker-feather-data/mysql:/var/feather + - ./scripts/waitfor:/opt/feather/waitfor + command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file diff --git a/docker/postgres.yml b/docker/postgres.yml new file mode 100644 index 0000000..ae09afa --- /dev/null +++ b/docker/postgres.yml @@ -0,0 +1,40 @@ +version: "3.9" +## docker-compose -f postgres.yml up +services: + + ## Database + database: + container_name: postgres + image: postgres + volumes: + - "./scripts/1-postgres-init.sql:/docker-entrypoint-initdb.d/1.sql" + environment: + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + expose: + - 5432 + + ## Application + feather: + depends_on: + - database + container_name: feather-postgres + build: .. + ports: + - "8082:8082" + expose: + - 8082 + environment: + BASE_URL: "http://localhost:8082" + BASE_PORT: 8082 + DB_HOST: database + DB_PORT: 5432 + DB_TYPE: postgres + DB_USER: "feather" + DB_PASS: "feather" + DB_NAME: "feather" + volumes: + - ./docker-feather-data/postgres:/var/feather + - ./scripts/waitfor:/opt/feather/waitfor + command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file diff --git a/docker/scripts/1-mysql-init.sql b/docker/scripts/1-mysql-init.sql new file mode 100644 index 0000000..d8d5196 --- /dev/null +++ b/docker/scripts/1-mysql-init.sql @@ -0,0 +1,4 @@ +CREATE DATABASE feather; +CREATE USER 'feather'@'%' IDENTIFIED BY 'feather'; +GRANT ALL ON `feather`.* to 'feather'@'%'; +SELECT host, user FROM mysql.user; \ No newline at end of file diff --git a/docker/scripts/1-postgres-init.sql b/docker/scripts/1-postgres-init.sql new file mode 100644 index 0000000..8e1a289 --- /dev/null +++ b/docker/scripts/1-postgres-init.sql @@ -0,0 +1,3 @@ +CREATE DATABASE feather; +CREATE USER feather WITH PASSWORD 'feather'; +GRANT ALL PRIVILEGES ON DATABASE feather TO feather; \ No newline at end of file diff --git a/docker/scripts/waitfor b/docker/scripts/waitfor new file mode 100755 index 0000000..75ea85b --- /dev/null +++ b/docker/scripts/waitfor @@ -0,0 +1,12 @@ +#!/bin/sh + +set -eu +echo "Waiting for ${1}..." +i=0 +until [ $i -ge 10 ] +do + i=$(( i + 1 )) + echo "$i: Waiting for ${1} | ${i}/10 seconds..." + sleep 1 +done +echo "${1} should be ready ..." diff --git a/docker/try_embedded.bat b/docker/try_embedded.bat deleted file mode 100644 index d59a2bb..0000000 --- a/docker/try_embedded.bat +++ /dev/null @@ -1,15 +0,0 @@ -@echo off - -REM Base Path (Shared with containers) -set BASE_PATH=C:%homepath%\docker-feather-data\embedded - -set APP_NAME=feather-app-embedded - -REM ## Start Feather App -docker stop %APP_NAME% -docker rm %APP_NAME% -docker run -d --restart=unless-stopped -v %BASE_PATH%:/var/feather -p 8080:8080 --name %APP_NAME% feather - -echo You can connect to: -echo http://127.0.0.1:8080 -timeout 10 diff --git a/docker/try_embedded.sh b/docker/try_embedded.sh deleted file mode 100755 index 9120a70..0000000 --- a/docker/try_embedded.sh +++ /dev/null @@ -1,16 +0,0 @@ -# #!/bin/bash - -## Base Path (Shared with containers) -export BASE_PATH=$PWD/docker-feather-data/embedded - -export APP_NAME=feather-app-embedded - -## Start Feather App -docker stop $APP_NAME -docker rm $APP_NAME -docker run -d --restart=unless-stopped -v $BASE_PATH:/var/feather -p 8080:8080 --name $APP_NAME feather - -echo "You can connect to: " -echo " http://127.0.0.1:8080" -echo "" -sleep 10 diff --git a/docker/try_mysql.bat b/docker/try_mysql.bat deleted file mode 100644 index 8b20502..0000000 --- a/docker/try_mysql.bat +++ /dev/null @@ -1,48 +0,0 @@ -@echo off - -REM Base Path (Shared with containers) -set BASE_PATH=C:%homepath%\docker-feather-data\mysql - - -REM Feather App -set APP_NAME=feather-app-mariadb -set SQL_NAME=feather-db-mariadb - -REM MySQL Root Password -set MYSQLPORT=3306 -set MYSQLROOTPW=rootfeather - -REM MySQL Feather App db details -set MYSQLFEATHERTABLE=feather -set MYSQLFEATHERUSER=feather -set MYSQLFEATHERPW=feather - - -REM MariaDB SQL (You can use mysql if you want) -REM We will use this network for our app, so opening port 8081 here -docker stop %SQL_NAME% -docker rm %SQL_NAME% -docker run -d --name=%SQL_NAME% -p %MYSQLPORT%:3306 -p 8081:8081 -v %BASE_PATH%\mysql\datadir:/var/lib/mysql -v %BASE_PATH%\mysql\log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=%MYSQLROOTPW% -e MYSQL_ROOT_HOST=%% --restart=unless-stopped mariadb:latest - -REM Sleep to give time for the DB to start -echo Waiting 30 secs, to give time for the DB to start... -timeout 30 - -REM Create DB, user -echo CREATE DATABASE %MYSQLFEATHERTABLE%; > feathermysql.sql -echo CREATE USER '%MYSQLFEATHERUSER%'@'%%' IDENTIFIED BY '%MYSQLFEATHERPW%'; >> feathermysql.sql -echo GRANT ALL ON `%MYSQLFEATHERTABLE%`.* TO '%MYSQLFEATHERUSER%'@'%%'; >> feathermysql.sql -echo SELECT host, user FROM mysql.user; >> feathermysql.sql - -docker exec -i %SQL_NAME% mysql -uroot -p%MYSQLROOTPW% < feathermysql.sql -del feathermysql.sql - - -REM Start Feather App -docker stop %APP_NAME% -docker rm %APP_NAME% -docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8081" -e BASE_PORT=8081 -e DB_TYPE=mysql -e DB_HOST=127.0.0.1 -e DB_PORT=3306 -e DB_NAME=%MYSQLFEATHERTABLE% -e DB_USER=%MYSQLFEATHERUSER% -e DB_PASS=%MYSQLFEATHERPW% -e MAX_BODYSIZE="10mb" -d feather - -echo You can connect to: -echo http://127.0.0.1:8081 -timeout 10 diff --git a/docker/try_mysql.sh b/docker/try_mysql.sh deleted file mode 100755 index 45fc474..0000000 --- a/docker/try_mysql.sh +++ /dev/null @@ -1,70 +0,0 @@ -# #!/bin/bash - -## Base Path (Shared with containers) -export BASE_PATH=$PWD/docker-feather-data/mysql - -## Feather App -export APP_NAME=feather-app-mariadb -export SQL_NAME=feather-db-mariadb - -### MySQL Root Password -export MYSQLPORT=3306 -export MYSQLROOTPW=rootfeather - -### MySQL Feather App db details -export MYSQLFEATHERTABLE=feather -export MYSQLFEATHERUSER=feather -export MYSQLFEATHERPW=feather - - -### MariaDB SQL (You can use mysql if you want) -### We will use this network for our app, so opening port 8081 here -docker stop $SQL_NAME -docker rm $SQL_NAME -docker run -d --name=$SQL_NAME \ - -p $MYSQLPORT:3306 \ - -p 8081:8081 \ - -v $BASE_PATH/mysql/datadir:/var/lib/mysql \ - -v $BASE_PATH/mysql/log:/var/log/mysql \ - -e MYSQL_ROOT_PASSWORD=$MYSQLROOTPW \ - -e MYSQL_ROOT_HOST=% \ - --restart=unless-stopped \ - mariadb:latest \ - --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci - -## Sleep to give time for the DB to start -echo "Waiting 30 secs, to give time for the DB to start..." -sleep 30 - -### Create DB, user -echo "CREATE DATABASE ${MYSQLFEATHERTABLE}; \ -CREATE USER '${MYSQLFEATHERUSER}'@'%' IDENTIFIED BY '${MYSQLFEATHERPW}'; \ -grant all on \`${MYSQLFEATHERTABLE}\`.* to '${MYSQLFEATHERUSER}'@'%'; \ -SELECT host, user FROM mysql.user;" \ -> feathermysql.sql -docker exec -i $SQL_NAME mysql -uroot -p$MYSQLROOTPW < feathermysql.sql && true -rm feathermysql.sql - - -## Start Feather App -docker stop $APP_NAME -docker rm $APP_NAME -docker run -d --name $APP_NAME \ - --restart=unless-stopped \ - --net=container:$SQL_NAME \ - -v $BASE_PATH:/var/feather \ - -e BASE_URL="http://localhost:8081" \ - -e BASE_PORT=8081 \ - -e DB_TYPE=mysql \ - -e DB_HOST=127.0.0.1 \ - -e DB_PORT=3306 \ - -e DB_NAME=$MYSQLFEATHERTABLE \ - -e DB_USER=$MYSQLFEATHERUSER \ - -e DB_PASS=$MYSQLFEATHERPW \ - -e MAX_BODYSIZE="10mb" \ - -d feather - -echo "You can connect to: " -echo " http://127.0.0.1:8081" -echo "" -sleep 10 diff --git a/docker/try_postgres.bat b/docker/try_postgres.bat deleted file mode 100644 index bdcde0c..0000000 --- a/docker/try_postgres.bat +++ /dev/null @@ -1,43 +0,0 @@ -@echo off - -REM Base Path (Shared with containers) -set BASE_PATH=C:%homepath%\docker-feather-data\postgres - -REM Feather App -set APP_NAME=feather-app-postgres -set SQL_NAME=feather-db-postgres - -REM postgres Root Password -set POSTGRESPORT=5432 -set POSTGRES_ROOTPW=postgres -set POSTGRES_USER=feather -set POSTGRES_PASSWORD=feather -set POSTGRES_DB=feather - -REM Postgres SQL -REM We will use this network for our app, so opening port 8082 here -docker stop %SQL_NAME% -docker rm %SQL_NAME% -docker run -d --name=%SQL_NAME% --restart=unless-stopped -p %POSTGRESPORT%:5432 -p 8082:8082 -v %BASE_PATH%\postgresql\data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=%POSTGRES_ROOTPW% -d postgres - -REM Sleep to give time for the DB to start -echo "Waiting 30 secs, to give time for the DB to start..." -timeout 30 - -REM Create DB, user -echo CREATE DATABASE %POSTGRES_DB%; > featherpostgres.sql -echo CREATE USER %POSTGRES_DB% WITH PASSWORD '%POSTGRES_DB%'; >> featherpostgres.sql -echo GRANT ALL PRIVILEGES ON DATABASE %POSTGRES_DB% TO %POSTGRES_DB%; >> featherpostgres.sql - -docker exec -i %SQL_NAME% psql -U postgres < featherpostgres.sql -del featherpostgres.sql - - -REM Start Feather App -docker stop %APP_NAME% -docker rm %APP_NAME% -docker run -d --name %APP_NAME% --restart=unless-stopped --net=container:%SQL_NAME% -v %BASE_PATH%:/var/feather -e BASE_URL="http://localhost:8082" -e BASE_PORT=8082 -e DB_TYPE=postgres -e DB_HOST=127.0.0.1 -e DB_PORT=5432 -e DB_NAME=%POSTGRES_DB% -e DB_USER=%POSTGRES_USER% -e DB_PASS=%POSTGRES_PASSWORD% -e MAX_BODYSIZE="10mb" -d feather - -echo You can connect to: -echo http://127.0.0.1:8082 -timeout 10 diff --git a/docker/try_postgres.sh b/docker/try_postgres.sh deleted file mode 100755 index 40598dd..0000000 --- a/docker/try_postgres.sh +++ /dev/null @@ -1,63 +0,0 @@ -# #!/bin/bash - -## Base Path (Shared with containers) -export BASE_PATH=$PWD/docker-feather-data/postgres - -## Feather App -export APP_NAME=feather-app-postgres -export SQL_NAME=feather-db-postgres - -### postgres Root Password -export POSTGRESPORT=5432 -export POSTGRES_ROOTPW=postgres -export POSTGRES_USER=feather -export POSTGRES_PASSWORD=feather -export POSTGRES_DB=feather - -### Postgres SQL -### We will use this network for our app, so opening port 8082 here -docker stop $SQL_NAME -docker rm $SQL_NAME -docker run -d --name=$SQL_NAME \ - --restart=unless-stopped \ - -p $POSTGRESPORT:5432 \ - -p 8082:8082 \ - -v $BASE_PATH/postgresql/data:/var/lib/postgresql/data \ - -e POSTGRES_PASSWORD=$POSTGRES_ROOTPW \ - -d postgres - -## Sleep to give time for the DB to start -echo "Waiting 30 secs, to give time for the DB to start..." -sleep 30 - -### Create DB, user -echo "CREATE DATABASE ${POSTGRES_DB}; \ -CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}'; \ -GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_USER};" \ -> featherpostgres.sql -docker exec -i $SQL_NAME psql -U postgres < featherpostgres.sql && true -rm featherpostgres.sql - - -## Start Feather App -docker stop $APP_NAME -docker rm $APP_NAME -docker run -d --name $APP_NAME \ - --restart=unless-stopped \ - --net=container:$SQL_NAME \ - -v $BASE_PATH:/var/feather \ - -e BASE_URL="http://localhost:8082" \ - -e BASE_PORT=8082 \ - -e DB_TYPE=postgres \ - -e DB_HOST=127.0.0.1 \ - -e DB_PORT=5432 \ - -e DB_NAME=$POSTGRES_DB \ - -e DB_USER=$POSTGRES_USER \ - -e DB_PASS=$POSTGRES_PASSWORD \ - -e MAX_BODYSIZE="10mb" \ - -d feather - -echo "You can connect to: " -echo " http://127.0.0.1:8082" -echo "" -sleep 10 From 42f43607992001d6e8b54bdc5ce88ab047b25328 Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Wed, 23 Dec 2020 22:28:51 +0100 Subject: [PATCH 5/7] Updated datadir --- .gitignore | 2 +- docker/docker-compose.yml | 2 +- docker/mysql.yml | 5 +++-- docker/postgres.yml | 5 +++-- docker/scripts/1-mysql-init.sql | 3 +-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index e13feb0..ea14afd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,5 @@ db.sqlite Public Resources ./feather -docker/docker-feather-data +docker/datadir ssh \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7b01748..6644ce1 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,4 +6,4 @@ services: ports: - "8080:8080" volumes: - - ./docker-feather-data/sqlite:/var/feather \ No newline at end of file + - "./datadir/sqlite:/var/feather" \ No newline at end of file diff --git a/docker/mysql.yml b/docker/mysql.yml index 7f1f08b..10e6c75 100644 --- a/docker/mysql.yml +++ b/docker/mysql.yml @@ -8,6 +8,7 @@ services: image: mariadb command: --default-authentication-plugin=mysql_native_password volumes: + - "./datadir/mysql/db:/var/lib/mysql" - "./scripts/1-mysql-init.sql:/docker-entrypoint-initdb.d/1.sql" environment: MYSQL_ROOT_PASSWORD: root @@ -37,6 +38,6 @@ services: DB_PASS: "feather" DB_NAME: "feather" volumes: - - ./docker-feather-data/mysql:/var/feather - - ./scripts/waitfor:/opt/feather/waitfor + - "./datadir/mysql:/var/feather" + - "./scripts/waitfor:/opt/feather/waitfor" command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file diff --git a/docker/postgres.yml b/docker/postgres.yml index ae09afa..0fea0d0 100644 --- a/docker/postgres.yml +++ b/docker/postgres.yml @@ -7,6 +7,7 @@ services: container_name: postgres image: postgres volumes: + - "./datadir/mysql/db:/var/lib/postgresql/data" - "./scripts/1-postgres-init.sql:/docker-entrypoint-initdb.d/1.sql" environment: POSTGRES_PASSWORD: postgres @@ -35,6 +36,6 @@ services: DB_PASS: "feather" DB_NAME: "feather" volumes: - - ./docker-feather-data/postgres:/var/feather - - ./scripts/waitfor:/opt/feather/waitfor + - "./datadir/postgres:/var/feather" + - "./scripts/waitfor:/opt/feather/waitfor" command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file diff --git a/docker/scripts/1-mysql-init.sql b/docker/scripts/1-mysql-init.sql index d8d5196..9425de0 100644 --- a/docker/scripts/1-mysql-init.sql +++ b/docker/scripts/1-mysql-init.sql @@ -1,4 +1,3 @@ CREATE DATABASE feather; CREATE USER 'feather'@'%' IDENTIFIED BY 'feather'; -GRANT ALL ON `feather`.* to 'feather'@'%'; -SELECT host, user FROM mysql.user; \ No newline at end of file +GRANT ALL ON `feather`.* to 'feather'@'%'; From f16421adbe0ceaf5d3530f1125a25513dc89b848 Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Wed, 23 Dec 2020 22:38:08 +0100 Subject: [PATCH 6/7] Updated waitfor script and waiting time for DB to be ready. --- docker/mysql.yml | 2 +- docker/postgres.yml | 2 +- docker/scripts/waitfor | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/mysql.yml b/docker/mysql.yml index 10e6c75..6c8ab29 100644 --- a/docker/mysql.yml +++ b/docker/mysql.yml @@ -40,4 +40,4 @@ services: volumes: - "./datadir/mysql:/var/feather" - "./scripts/waitfor:/opt/feather/waitfor" - command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file + command: sh -c "/opt/feather/waitfor database 30 && /opt/feather/start" \ No newline at end of file diff --git a/docker/postgres.yml b/docker/postgres.yml index 0fea0d0..0ea373f 100644 --- a/docker/postgres.yml +++ b/docker/postgres.yml @@ -38,4 +38,4 @@ services: volumes: - "./datadir/postgres:/var/feather" - "./scripts/waitfor:/opt/feather/waitfor" - command: sh -c "/opt/feather/waitfor database && /opt/feather/start" \ No newline at end of file + command: sh -c "/opt/feather/waitfor database 30 && /opt/feather/start" \ No newline at end of file diff --git a/docker/scripts/waitfor b/docker/scripts/waitfor index 75ea85b..adc6620 100755 --- a/docker/scripts/waitfor +++ b/docker/scripts/waitfor @@ -3,10 +3,10 @@ set -eu echo "Waiting for ${1}..." i=0 -until [ $i -ge 10 ] +until [ $i -ge $2 ] do i=$(( i + 1 )) - echo "$i: Waiting for ${1} | ${i}/10 seconds..." + echo "$i: Waiting for ${1} | ${i}/${2} seconds..." sleep 1 done echo "${1} should be ready ..." From deb0839d810ed6023762432e1c5c23b569104465 Mon Sep 17 00:00:00 2001 From: MARTIN Denis Date: Thu, 24 Dec 2020 07:37:51 +0100 Subject: [PATCH 7/7] Added a README, fixed datadir path for postgres --- docker/README.md | 162 ++++++++++++++++++++++++++++++++++++++++++++ docker/postgres.yml | 2 +- 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100755 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100755 index 0000000..050484c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,162 @@ +# Docker + Feather CMS 🪶 + +- Feather is a modern Swift-based content management system powered by Vapor 4. + +- Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. + +## Requirements + +- Docker installed on your computer. [Get Docker.com](https://docs.docker.com/get-docker/) + +- Basic knowledge of [Docker Compose](https://docs.docker.com/compose/) + +- Basic knowledge of [Docker](https://docs.docker.com/) + + +## Installation + +- Clone or download the source files + +- Start the application using `docker-compose` + +## Usage + +### Testing the integrated database (sqlite) +the base url of your web server will be http://localhost:8080 + + +```bash +docker-compose up +``` + +### Testing mysql database +the base url of your web server will be http://localhost:8081 +& the database will be accessible on port `3306`. +- `root password`: root +- `TABLE`: feather - `USER`: feather - `PASS`: feather + +```bash +docker-compose -f mysql.yml up +``` + +### Testing postgres database +`⚠️ There is a pending issue with Postgres. It is unsuable for the moment` + +the base url of your web server will be http://localhost:8082 +& the database will be accessible on port `5432`. +- `root password`: postgres +- `TABLE`: feather - `USER`: feather - `PASS`: feather + +```bash +docker-compose -f postgres.yml up +``` + +## Custumazing the docker + +You can check the [Dockerfile](https://github.com/FeatherCMS/feather/blob/main/Dockerfile?raw=true) and the different step of the build. + +Here is a brief descritpion of the process + +1. We use `swift:5.3.1-focal` as our main builder +2. You can have your own `PRIVATE` custom module and cloning over `ssh` is supported: + - We need to add the SSH Hostname to `known_host` (This is use for Private repo in SPM) + In our example `Line 21` -> `ssh-keyscan -H github.com >> ~/.ssh/known_hosts;` + - At the root levele of the repository, create a folder `ssh` and copy your `unencrypted` private key in this folder. The Docker build will picked it up. + - The private key will not be part of the final build. So you can distribute the image. +4. You can also add some customs scripts/content to be part of the docker. They will be available at the path `/opt/feather` + - create a folder `customscripts` at the root lever of the repository + - add your content to it + - Please note that a `chmod 550` will be apply to it + +3. When the build complete, we will use `swift:5.3.1-focal-slim` to build the final result. + - Using this will drastycally decrease the final size of the docker image + - User details running the application inside the container:(`uid=999(feather) gid=999(feather) groups=999(feather)`. Please make sure you give read/write to this user + +## Available environement variable + +``` +BASE_URL="http://localhost:8080" +BASE_PATH="/var/feather" +BASE_PORT=8080 + +## Default sqlite +DB_TYPE="sqlite" +MAX_BODYSIZE="10mb" +USE_FILE_MIDDLEWARE="true" + +## Using mysql/mariadb/postgres +DB_HOST="localhost" +DB_PORT=3306 or 5432 # The port will use the default one, if you use a custom port, set this env variable +DB_USER="feather" +DB_PASS="feather" +``` +## Docker Working directory + +The default working directory is `/var/feather` you can mount a volume at this path. You may also use a different folder by setting the `BASE_PATH` environment variable. + + +## Docker entry point + +The default entry point is `/opt/feather/start`. You may want to custumize the start behaviour. In that case, add a script `start` to the `customscripts` folder, it will be overwriten durring the build. + +### Default provided entry point + +This script will check if you had previously prepared data and put then in the define `BASE_PATH`. It will then start `Feather` + +``` +#!/bin/bash + +[[ ! -d \"\${BASE_PATH}/db.sqlite\" && -d /opt/feather/db.sqlite ]] && cp -pr /opt/feather/db.sqlite \${BASE_PATH}/ + +[[ ! -d \"\${BASE_PATH}/Public\" && -d /opt/feather/Public ]] && cp -pr /opt/feather/Public \${BASE_PATH}/" + +[[ ! -d \"\${BASE_PATH}/Resources\" && -d /opt/feather/Resources ]] && cp -pr /opt/feather/Resources \${BASE_PATH}/ + +Feather serve --hostname 0.0.0.0 --port \${BASE_PORT} +``` + +## Examples + +``` +docker run -d -v :/var/feather -p 8080:8080 feather +``` + +``` +docker run -d \ + -v :/var/feather \ + -e BASE_URL="http://localhost:8081" \ + -e BASE_PORT=8081 \ + -e DB_TYPE=mysql \ + -e DB_HOST= \ + -e DB_PORT=3306 \ + -e DB_NAME=feather \ + -e DB_USER=feather \ + -e DB_PASS=feather \ + -e MAX_BODYSIZE="10mb" \ + -d feather + +``` + + +## Known issues + +### Postgress database + +When running the app using a Postgres database, the index lenght is limited to 63 characthers trucating some of feather indentifier: +``` +identifier "uq:user_permissions.module+user_permissions.context+user_permissions.action" will be truncated to "uq:user_permissions.module+user_permissions.context+user_permis" (truncate_identifier) +identifier "uq:frontend_metadatas.module+frontend_metadatas.model+frontend_metadatas.reference" will be truncated to "uq:frontend_metadatas.module+frontend_metadatas.model+frontend_" (truncate_identifier) +``` + +Until the issue is resolved, postgres databases are unusable. + +## Credits + +- [Vapor](https://vapor.codes) - underlying framework +- [Feather icons](https://feathericons.com) - feather icons + + +### License + +[WTFPL](LICENSE) + diff --git a/docker/postgres.yml b/docker/postgres.yml index 0ea373f..28981fe 100644 --- a/docker/postgres.yml +++ b/docker/postgres.yml @@ -7,7 +7,7 @@ services: container_name: postgres image: postgres volumes: - - "./datadir/mysql/db:/var/lib/postgresql/data" + - "./datadir/postgres/db:/var/lib/postgresql/data" - "./scripts/1-postgres-init.sql:/docker-entrypoint-initdb.d/1.sql" environment: POSTGRES_PASSWORD: postgres