Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Docker support #41

Merged
merged 9 commits into from
Dec 27, 2020
Merged

✅ Docker support #41

merged 9 commits into from
Dec 27, 2020

Conversation

charlymr
Copy link

I am recreating a PR for docker, replacing
#35

All good now.
As mention, I extended Feather for the DB support via Env variables. It allow to decide the type of DB you want. (not providing anything revert to the default behaviour.

There are example script (Windows/Linux/Mac) to build, start the docker with different DB.

P.S. For postgres we still have an issue with index length. But this is not related to docker. So when it will be fix, rebuilding the docker will also fix this.

Kind Regards,

Denis

    /// # 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)

@charlymr charlymr mentioned this pull request Dec 15, 2020
Sources/Feather/Feather+DataBases.swift Outdated Show resolved Hide resolved
Sources/Feather/Feather+DataBases.swift Outdated Show resolved Hide resolved
Sources/Feather/Feather+DataBases.swift Outdated Show resolved Hide resolved
Sources/Feather/Feather+DataBases.swift Outdated Show resolved Hide resolved
docker/try_embedded.bat Outdated Show resolved Hide resolved
docker/try_mysql.bat Outdated Show resolved Hide resolved
@tib
Copy link
Member

tib commented Dec 16, 2020

Great work, thanks for the updated PR, I only have some minor notes, please take a look at my comments.

@charlymr
Copy link
Author

@tib I did the changes fro the naming. Still need to spend a bit of with the docker compose. Will do that soon. had some computer issue

@tib
Copy link
Member

tib commented Dec 23, 2020

No worries, take your time, I had some struggle with SPM lately, also I have to work on the docs a lot more... :)

@charlymr charlymr requested a review from tib December 23, 2020 21:41
@charlymr
Copy link
Author

@tib added a README to the folder. We are ll good now and using Docker compose. It's quiet nice actually as it will build on demands!

@tib
Copy link
Member

tib commented Dec 27, 2020

I like the changes as they are now, so I'll merge this right away and we can fix the smaller issues later on.

Thank your for this contribution. 😉

@tib tib merged commit f5da187 into FeatherCMS:main Dec 27, 2020
@DesdeChaves
Copy link

I intend to use feather cms in my school to start a blog.
For that I need to create a docker image, but I found the following problem after “docker build”:

[1318/1320] Compiling SystemModule SystemVariableAdminController.swift
/opt/feather/.build/checkouts/system-module/Sources/SystemModule/SystemModule.swift:142:89: error: type 'FileManager.DirectoryEnumerationOptions' has no member 'producesRelativePathURLs'
            let options: FileManager.DirectoryEnumerationOptions = [.skipsHiddenFiles, .producesRelativePathURLs]
                                                                                       ~^~~~~~~~~~~~~~~~~~~~~~~~
The command '/bin/sh -c 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' returned a non-zero code: 1

Is there a way to fix that?

It would be great if the docker hub had an image available for download.

@charlymr
Copy link
Author

Hi @DesdeChaves ,
I don't have this issue when building. Can you give me a bit more context about the build environment? System, version, etc so I can try and recreate the issue.
Thanks,
Denis

@DesdeChaves
Copy link

In discord, #TypeBeta presents the following solution:

 var options: FileManager.DirectoryEnumerationOptions = [.skipsHiddenFiles]
   #if os(macOS) || os(iOS)
       options.insert(.producesRelativePathURLs)
   #endif
   for rawItem as URL in try FileManager.default.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: /* ... */, options: options)! {
       var item = rawItem
       #if !os(macOS) && !os(iOS)
           item = URL(fileURLWithPath: rawItem.path.dropFirst(directoryURL.path.count + 1), relativeTo: directoryURL)
       #endif 

@DesdeChaves
Copy link

I'm in macOs 10.15.7, Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28).

@charlymr
Copy link
Author

Ok I will try. I am on Discord now for about 20 min if you want. In the meantime, I will put an image on Dockerhub.

@charlymr
Copy link
Author

It's building, if working should be available here:
https://hub.docker.com/r/irlmobile/feather

@DesdeChaves
Copy link

Thanks. What's is the tag?

@charlymr
Copy link
Author

charlymr commented Dec 29, 2020 via email

@charlymr
Copy link
Author

Same issue when building from Docker hub. I will investigate

@DesdeChaves
Copy link

Many thanks for your support.

@tib
Copy link
Member

tib commented Dec 29, 2020

@DesdeChaves @charlymr just made a new release that fixes the file manager issue:
https://github.com/FeatherCMS/system-module/releases/tag/1.0.0-beta.9

@DesdeChaves
Copy link

Thanks. Works like a charm.

@charlymr
Copy link
Author

@DesdeChaves the image is available on DokcerHub too now
https://hub.docker.com/r/irlmobile/feather

@charlymr
Copy link
Author

charlymr commented Dec 30, 2020

Hello,

Check in the README, https://github.com/FeatherCMS/feather/tree/main/docker https://github.com/FeatherCMS/feather/tree/main/docker

I added a step in the docker build which will copy and make executable all the scripts under the ‘customscripts’ folder.

They will be accessible at /opt/feather/
This way you can customise the entry point or even replace the start.

Another approach which I personally use is to put a script in the ./datadir shared with feather, then when I start docker I simply do something like this where my script is feathermulti (I am running multiple instance of feather in my case, running on ports 14080 to 14089

Here I have a folder name app in my datadir

datadir/ (shared in docker /var/feather)

  • feathermulti
  • app/
    • blog1
      .env.production
    • blog2
      .env.production
      etc…

Example .env.production

BASE_URL="http://blog1.test.local"
BASE_PATH="/var/feather/app/blog1"
BASE_PORT="14080"
DB_TYPE="mysql"
MAX_BODYSIZE="25mb"
USE_FILE_MIDDLEWARE=true
DB_HOST="localhost"
DB_PORT="3306"
DB_NAME="feather_blog1"
DB_USER=“blog1"
DB_PASS=“1234567"
LOG_PATH="/var/feather/logs/blog1.log”

feathermulti

#!/bin/bash
export APPS_PATH=/var/feather/app

unset BASE_URL
unset BASE_PORT
unset BASE_PATH
unset DB_TYPE
unset MAX_BODYSIZE
unset DB_HOST
unset DB_USER
unset DB_PASS
unset DB_NAME
unset USE_FILE_MIDDLEWARE

# startServer 1.FOLDER 2.BASE_PORT 3.DB_NAME 4.DB_USER 5.DB_PASS 6.LOGPATH
startServer () {
    cd $APPS_PATH
    cd $1
    source .env.production
    Feather serve --hostname 0.0.0.0 --env production --port $BASE_PORT >> $LOG_PATH &
    echo "[NOTICE] --------------------------------------------------- "
    echo "[NOTICE] ✅ Starting App: $1 "
    echo "[NOTICE]          URL: ${BASE_URL}"
    echo "[NOTICE]          DB: ${DB_NAME}"
    echo "[NOTICE]          LOG: ${LOG_PATH}"
    echo "[NOTICE] --------------------------------------------------- "
    sleep 1
}

cd $APPS_PATH
for app in $(ls); do
    startServer $app
done

tail -f /var/feather/logs/*

Here is the command to start the docker (you can use docker compose of course)

export BASE_PATH=$PWD

## Feather App
export APP_NAME=blogs-app
export SQL_NAME= blogs-mariadb

### MySQL Root Password
export MYSQLROOTPW=rootpass

### MariaDB
docker stop $SQL_NAME
docker rm $SQL_NAME
docker run -d --name=$SQL_NAME \
    -p 14080-14089:14080-14089 \
    -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

## Start Feather App - PORT: 14080-14089
docker run -d --name $APP_NAME --restart=unless-stopped \
    --net=container:$SQL_NAME \
    -v $PWD:/var/feather \
    feather \
    /var/feather/feathermulti

Then on Nginx, in my case I use a reverse proxy:

    server {
    listen       80;
    listen       [::]:80;
    server_name  blog1.test.local;
    access_log /usr/local/etc/logs/001-test-access.log;
    error_log /usr/local/etc/logs/001-test-error.log;

    location / {
        proxy_pass http://127.0.0.1:14080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

@tib tib mentioned this pull request Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants