diff --git a/.github/workflows/chevereto.yml b/.github/workflows/chevereto.yml new file mode 100644 index 0000000..ac3704c --- /dev/null +++ b/.github/workflows/chevereto.yml @@ -0,0 +1,42 @@ +name: "chevereto docker build" + +env: + PROJECT: chevereto + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set tag + id: tag + run: | + TAG=$(cat ${{ env.PROJECT }}/Dockerfile | awk 'NR==4 {print $3}') + echo "::set-env name=TAG::$TAG" + - name: Docker Hub login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin + - name: Set up Docker Buildx + id: buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + buildx-version: latest + - name: Build Dockerfile + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + run: | + docker buildx build \ + --platform=linux/amd64,linux/arm64 \ + --output "type=image,push=true" \ + --file ${{ env.PROJECT }}/Dockerfile ./${{ env.PROJECT }} \ + --tag $(echo "${DOCKER_USERNAME}" | tr '[:upper:]' '[:lower:]')/${{ env.PROJECT }}:latest \ + --tag $(echo "${DOCKER_USERNAME}" | tr '[:upper:]' '[:lower:]')/${{ env.PROJECT }}:${TAG} diff --git a/chevereto/.dockerignore b/chevereto/.dockerignore new file mode 100644 index 0000000..c410af0 --- /dev/null +++ b/chevereto/.dockerignore @@ -0,0 +1,2 @@ +* +!settings.php diff --git a/chevereto/Dockerfile b/chevereto/Dockerfile new file mode 100644 index 0000000..47306aa --- /dev/null +++ b/chevereto/Dockerfile @@ -0,0 +1,52 @@ +ARG PHP_VERSION=7.4-apache +FROM alpine as downloader + +ENV VERSION 1.3.0 +ARG CHEVERETO_VERSION=1.3.0 +RUN apk add --no-cache curl && \ + curl -sS -o /tmp/chevereto.zip -L "https://github.com/Chevereto/Chevereto-Free/archive/${CHEVERETO_VERSION}.zip" && \ + mkdir -p /extracted && \ + cd /extracted && \ + unzip /tmp/chevereto.zip && \ + mv "Chevereto-Free-${CHEVERETO_VERSION}/" Chevereto/ +COPY settings.php /extracted/Chevereto/app/settings.php + +FROM php:$PHP_VERSION + +# Install required packages and configure plugins + mods for Chevereto +RUN apt-get update && apt-get install -y \ + libgd-dev \ + libzip-dev && \ + bash -c 'if [[ $PHP_VERSION == 7.4.* ]]; then \ + docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/; \ + else \ + docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/; \ + fi' && \ + docker-php-ext-install \ + exif \ + gd \ + mysqli \ + pdo \ + pdo_mysql \ + zip && \ + a2enmod rewrite + +# Download installer script +COPY --from=downloader --chown=33:33 /extracted/Chevereto /var/www/html + +# Expose the image directory as a volume +VOLUME /var/www/html/images + +# DB connection environment variables +ENV CHEVERETO_DB_HOST=db CHEVERETO_DB_USERNAME=chevereto CHEVERETO_DB_PASSWORD=chevereto CHEVERETO_DB_NAME=chevereto CHEVERETO_DB_PREFIX=chv_ CHEVERETO_DB_PORT=3306 +ARG BUILD_DATE +ARG CHEVERETO_VERSION=1.2.2 + +# Set all required labels, we set it here to make sure the file is as reusable as possible +LABEL org.label-schema.url="https://github.com/tanmng/docker-chevereto" \ + org.label-schema.name="Chevereto Free" \ + org.label-schema.license="Apache-2.0" \ + org.label-schema.version="${CHEVERETO_VERSION}" \ + org.label-schema.vcs-url="https://github.com/tanmng/docker-chevereto" \ + maintainer="Tan Nguyen " \ + build_signature="Chevereto free version ${CHEVERETO_VERSION}; built on ${BUILD_DATE}; Using PHP version ${PHP_VERSION}" diff --git a/chevereto/Dockerfile-installer b/chevereto/Dockerfile-installer new file mode 100644 index 0000000..23481c4 --- /dev/null +++ b/chevereto/Dockerfile-installer @@ -0,0 +1,47 @@ +# Specify the version of PHP we use for our Chevereto +ARG PHP_VERSION=7.4-apache +FROM alpine as downloader + +RUN apk add --no-cache curl && \ + mkdir -p /extracted/Chevereto/images && \ + cd /extracted/Chevereto && \ + curl -sS -o index.php -L "https://chevereto.com/download/file/installer" +COPY settings.php /extracted/Chevereto/app/settings.php + +FROM php:$PHP_VERSION + +# Install required packages and configure +RUN apt-get update && apt-get install -y \ + libgd-dev \ + libzip-dev && \ + bash -c 'if [[ $PHP_VERSION == 7.4.* ]]; then \ + docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/; \ + else \ + docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/; \ + fi' && \ + docker-php-ext-install \ + exif \ + gd \ + mysqli \ + pdo \ + pdo_mysql \ + zip && \ + a2enmod rewrite + +# Download installer script +COPY --from=downloader --chown=33:33 /extracted/Chevereto /var/www/html + +# Expose the image directory as a volume +VOLUME /var/www/html/images + +# DB connection environment variables +ENV CHEVERETO_DB_HOST=db CHEVERETO_DB_USERNAME=chevereto CHEVERETO_DB_PASSWORD=chevereto CHEVERETO_DB_NAME=chevereto CHEVERETO_DB_PREFIX=chv_ CHEVERETO_DB_PORT=3306 +ARG BUILD_DATE + +# Set all required labels, we set it here to make sure the file is as reusable as possible +LABEL org.label-schema.url="https://github.com/tanmng/docker-chevereto" \ + org.label-schema.name="Chevereto Free" \ + org.label-schema.license="Apache-2.0" \ + org.label-schema.vcs-url="https://github.com/tanmng/docker-chevereto" \ + maintainer="Tan Nguyen " \ + build_signature="Chevereto installer; built on ${BUILD_DATE}; Using PHP version ${PHP_VERSION}" diff --git a/chevereto/LICENSE b/chevereto/LICENSE new file mode 100644 index 0000000..2132252 --- /dev/null +++ b/chevereto/LICENSE @@ -0,0 +1,7 @@ +Copyright 2017 Tan Nguyen + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/chevereto/README.md b/chevereto/README.md new file mode 100644 index 0000000..9f61626 --- /dev/null +++ b/chevereto/README.md @@ -0,0 +1,158 @@ +[cheveretourl]: https://chevereto.com/ +[cheveretogithub]: https://github.com/Chevereto/Chevereto-Free + +[![chevereto](http://chevereto.com/app/themes/v3/img/chevereto-blue.svg)][cheveretourl] + +# nmtan/chevereto - Chevereto Free Docker + +[Chevereto][cheveretourl] is a powerful and fast image hosting script that allows you to create your very own full featured image hosting website in just minutes. + +Please note that the `installer` tag will provide you with the installer script +from Chevereto, which can be used to install either the [free Chevereto version][cheveretogithub] +or the paid version, while all the other tags will only provide the [free version][cheveretogithub]. + +## Supported tags and respective Dockerfile links + +> Here we list only the most relevant and recent tags, for the full list, please +use the `tags` tab in [Dockerhub page](https://hub.docker.com/r/nmtan/chevereto) + +* `latest` - Using latest commit of the branch `master` from [original repo][cheveretogithub] ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/latest/Dockerfile)) +* `installer` - Using latest [installer script](https://cdn.rawgit.com/Chevereto/php-repo-installer/master/index.php) ([Dockerfile-installer](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile-installer)) - Once you start the container with this image, you will have to wait for it to download latest source code from [original repo][cheveretogithub] +* `1.3.0` - Using the [`1.3.0` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.3.0) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) +* `1.2.3` - Using the [`1.2.3` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.2.3) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) +* `1.2.2` - Using the [`1.2.2` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.2.2) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) +* `1.2.1` - Using the [`1.2.1` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.2.1) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) +* `1.2.0` - Using the [`1.2.0` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.2.0) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) +* `1.1.4` - Using the [`1.1.4` release](https://github.com/Chevereto/Chevereto-Free/releases/tag/1.1.4) ([Dockerfile](https://github.com/tanmng/docker-chevereto/blob/master/Dockerfile)) + +> Note on PHP version: [Chevereto](cheveretourl) added support for PHP 7.4 since release `1.3.0`, PHP 7.3 since release `1.2.0`, PHP 7.2 since release `1.1.0`, and support for PHP 7.1 since release `1.0.6`, thus, the Docker images use the appropriate version of PHP to ensure the best performance and stability. You can check the [images' labels](https://docs.docker.com/config/labels-custom-metadata/) (by running `docker image inspect IMAGE_NAME`) for this information. + +> Some older tag of Chevereto are no longer supported to save up on build resources + +## Environment variables + +The most essentials environments variables are listed below + +* `CHEVERETO_DB_HOST` - Hostname of the Database machine that you wish to connect, default to `db` +* `CHEVERETO_DB_PORT` - The port of the Database machine to connect to, default to `3306` +* `CHEVERETO_DB_USERNAME` - Username to authenticate to MySQL database, default to `chevereto` +* `CHEVERETO_DB_PASSWORD` - Password of the user when connect to MySQL database, default to `chevereto` +* `CHEVERETO_DB_NAME` - Name of the database in MySQL server, default to `chevereto` +* `CHEVERETO_DB_PREFIX` - Table prefix (you can use this to run multiple instance of Chevereto using the same Database), default to `chv_` + +> For other environment variables, please consult the file [`settings.php`](https://github.com/tanmng/docker-chevereto/blob/master/settings.php) and the section "Advanced configuration" below. + +## Connection to database + +[Chevereto][cheveretourl] requires an Mysql database to store its information. You can use a [Mysql](https://hub.docker.com/_/mysql/) or [MariaDB](https://hub.docker.com/_/mariadb/) container to host this. + +Information on connection to database is provided to container via environment variables explained above. + +## Persistent storage + +[Chevereto][cheveretourl] stores images uploaded by users in `/var/www/html/images` directory within the container. + +You can mount a [data volume](https://docs.docker.com/engine/tutorials/dockervolumes/#data-volumes) at this location to ensure that you don't lose your images if you relaunch/remove container. + +## Max image size + +By default, PHP allow a maximum file upload to be 2MB. You can change such behaviour by updating the `php.ini` in your container, either by bind-mount the file, or build a new image with the updated file, that way you can reuse the image on demand. + +> Note that by default, Chevereto set a file upload limit of 10MB, so after you modify your `php.ini`, you should also update this settings in Chevereto settings page (available at CHEVERETO_URL/dashboard/settings/image-upload) + +> The customized `php.ini` should set the values of `upload_max_filesize`, `post_max_size` and potentially `memory_limit`, as showed in [the discussion from Chevereto Forum](https://chevereto.com/community/threads/chevereto-supports-only-2mb-max-upload-size.4729/). Further details on these parameters are available from [PHP documentation](http://php.net/manual/en/ini.core.php) + +An example of this is available in the [`examples/bigger-files` directory](examples/bigger-files) + +## Advanced configuration + +Chevereto is written using the [`G\` framework](https://g.chevereto.com/) which supports some [advanced configurations](https://github.com/Chevereto/Chevereto-Free/blob/master/lib/G/G.php). Ultimate, that means we can use the variable `$settings` from `settings.php` to add more configurations to the applications. I have added multiple environment variables to support these configurations, please consult [the file `settings.php` from the repo](https://github.c m/tanmng/docker-chevereto/blob/master/settings.php) for the list of these environment variables as well as their purpose. Among these settings, I would say the following two are the most useful + +* `CHEVERETO_SESSION_SAVE_PATH` - Specify where Chevereto can save the user session. Combining this with a shared volume/EFS/File synching, you can set up a highly available cluster of Free Chevereto while ensure user login status are not lost if they reconnect to another container. +* `CHEVERETO_DEFAULT_TIMEZONE` - Specify the default timezone for any newly created/registered user, please make sure to use a [PHP supported value](https://www.php.net/manual/en/timezones.php) eg. `America/New_York`. + + +## Example Usage + +I recommend you to use [Docker-compose](https://docs.docker.com/compose/) / [Docker swarm](https://docs.docker.com/engine/swarm/) to launch Chevereto in conjunction with a MySQL database. A sample of docker-compose.yaml can be found below. + +### Docker compose + +```yaml +version: '3' + +services: + db: + image: mariadb + volumes: + - database:/var/lib/mysql:rw + restart: always + networks: + - private + environment: + MYSQL_ROOT_PASSWORD: chevereto_root + MYSQL_DATABASE: chevereto + MYSQL_USER: chevereto + MYSQL_PASSWORD: chevereto + + chevereto: + depends_on: + - db + image: nmtan/chevereto + restart: always + networks: + - private + environment: + CHEVERETO_DB_HOST: db + CHEVERETO_DB_USERNAME: chevereto + CHEVERETO_DB_PASSWORD: chevereto + CHEVERETO_DB_NAME: chevereto + CHEVERETO_DB_PREFIX: chv_ + volumes: + - chevereto_images:/var/www/html/images:rw + ports: + - 8080:80 + +networks: + private: +volumes: + database: + chevereto_images: +``` + +Once `docker-compose.yaml` is ready, you can run + +```bash +docker-compose up +``` + +To run the service + +### Standalone + +```bash +docker run -it --name chevereto -d \ + --link mysql:mysql \ + -p 80:80 \ + -v "$PWD/images":/var/www/html/images \ + -e "CHEVERETO_DB_HOST=db" \ + -e "CHEVERETO_DB_USERNAME=chevereto" \ + -e "CHEVERETO_DB_PASSWORD=chevereto" \ + -e "CHEVERETO_DB_NAME=chevereto" \ + -e "CHEVERETO_DB_PREFIX=chv_" \ + nmtan/chevereto +``` + +## Note on multi platform + +It is feasible to run a Docker container image on different architectures. For now, I don't yet have the time to work on this, but will make sure to include that in future releases. + +## Contributions + +For now, this project is being maintained solely by me, for any questions or suggestions of improvements, please feel free [to reach out](mailto:tan.mng90@gmail.com) + +## License + +The docker image is released under the [MIT license](LICENSE) + +Please note that [Chevereto](cheveretourl) is a product of [Rodolfo Berrios](http://rodolfoberrios.com/), this project aims mainly at encapsulating the free version (released under AGPL v3 License) into a Docker container image, which can then be used easily. diff --git a/chevereto/examples/bigger-files/docker-compose.yaml b/chevereto/examples/bigger-files/docker-compose.yaml new file mode 100644 index 0000000..c9c1015 --- /dev/null +++ b/chevereto/examples/bigger-files/docker-compose.yaml @@ -0,0 +1,40 @@ +version: '3' + +services: + db: + image: mariadb:10.1.22 + volumes: + - database:/var/lib/mysql:rw + restart: always + networks: + - private + environment: + MYSQL_ROOT_PASSWORD: chevereto_root + MYSQL_DATABASE: chevereto + MYSQL_USER: chevereto + MYSQL_PASSWORD: chevereto + + chevereto: + depends_on: + - db + image: nmtan/chevereto:latest + restart: always + networks: + - private + environment: + CHEVERETO_DB_HOST: db + CHEVERETO_DB_USERNAME: chevereto + CHEVERETO_DB_PASSWORD: chevereto + CHEVERETO_DB_NAME: chevereto + CHEVERETO_DB_PREFIX: chv_ + volumes: + - chevereto_images:/var/www/html/images:rw + - ./php.ini:/usr/local/etc/php/php.ini:ro + ports: + - 8080:80 + +networks: + private: +volumes: + database: + chevereto_images: diff --git a/chevereto/examples/bigger-files/php.ini b/chevereto/examples/bigger-files/php.ini new file mode 100644 index 0000000..1a87278 --- /dev/null +++ b/chevereto/examples/bigger-files/php.ini @@ -0,0 +1,3 @@ +memory_limit = 256M; +upload_max_filesize = 100M; +post_max_size = 100M; diff --git a/chevereto/hooks/build b/chevereto/hooks/build new file mode 100644 index 0000000..644764f --- /dev/null +++ b/chevereto/hooks/build @@ -0,0 +1,81 @@ +#!/bin/bash + +# build +# +# This is a hook in the docker-chevereto repo by Tan Nguyen +# This is intended to be run locally, or via the automatic builder by Docker hub +# The script should be execute from the root of the project +# The list of versions of the image (ie. tag) which we wish to build is available in the file versions in the root of the project + +echo "------ HOOK START - BUILD -------" + +DOCKER_HUB_NAME=nmtan/chevereto +VERSION_LIST_FILE=versions +BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` + +function build_image(){ + if [ $# -lt 1 ]; then + # missing the damn tag + return 0; + fi + + tag_name="${1}" + image_full_name="${DOCKER_HUB_NAME}:${tag_name}" + case "${tag_name}" in + latest) + # Latest version - we do not need the version argument - latest version is defined in Dockerfile itself + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg CHEVERETO_VERSION="master" \ + -t "${image_full_name}" . + ;; + installer) + # Latest version - we do not need the version argument - latest version is defined in Dockerfile itself + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + -f Dockerfile-installer \ + -t "${image_full_name}" . + ;; + 1.3.*) + # These versions support php 7.3 + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg CHEVERETO_VERSION="${1}" \ + -t "${image_full_name}" . + ;; + 1.2.*) + # These versions support php 7.3 + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg PHP_VERSION="7.3-apache" \ + --build-arg CHEVERETO_VERSION="${1}" \ + -t "${image_full_name}" . + ;; + 1.1.*) + # These versions support php 7.2 + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg CHEVERETO_VERSION="${1}" \ + --build-arg PHP_VERSION="7.2-apache" \ + -t "${image_full_name}" . + ;; + 1.0.1[0-3]|1.0.[6-9]) + # These versions support PHP 7.1 + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg CHEVERETO_VERSION="${1}" \ + --build-arg PHP_VERSION="7.1.23-apache" \ + -t "${image_full_name}" . + ;; + *) + # These versions support PHP below 7.1 + docker build --rm --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg CHEVERETO_VERSION="${1}" \ + --build-arg PHP_VERSION="7.0.32-apache" \ + -t "${image_full_name}" . + ;; + esac + + docker push "${image_full_name}" +} + +while read -r tag; do + echo "Building the image ${DOCKER_HUB_NAME}:${tag}" + build_image "${tag}" +done < ${VERSION_LIST_FILE} + +echo "------ HOOK END - BUILD -------" diff --git a/chevereto/settings.php b/chevereto/settings.php new file mode 100644 index 0000000..75912e4 --- /dev/null +++ b/chevereto/settings.php @@ -0,0 +1,77 @@ +