diff --git a/.gitignore b/.gitignore index ab121a93..8cfea409 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .idea build -!hooks/build +!docker/build composer.lock composer.phar vendor/ diff --git a/.travis.yml b/.travis.yml index 4e4c70f5..40e6f0ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ cache: before_install: - echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - yes | pecl install swoole + - yes | pecl install swoole-4.4.15 - phpenv config-rm xdebug.ini || return 0 install: @@ -45,9 +45,14 @@ after_success: # Before deploying, build dist file for current travis tag before_deploy: - rm -f ocular.phar - - ./build.sh ${TRAVIS_TAG#?} + - if [[ ! -z $TRAVIS_TAG && "${TRAVIS_PHP_VERSION}" == "7.4" ]]; then ./build.sh ${TRAVIS_TAG#?} ; fi deploy: + - provider: script + script: bash ./docker/build + on: + condition: $TRAVIS_PULL_REQUEST == 'false' + php: '7.4' - provider: releases api_key: secure: a9dbZchocqeuOViwUeNH54bQR5Sz7rEYXx5b9WPFtnFn9LGKKUaLbA2U91UQ9QKPrcTpsALubUYbw2CnNmvCwzaY+R8lCD3gkU4ohsEnbpnw3deOeixI74sqBHJAuCH9FSaRDGILoBMtUKx2xlzIymFxkIsgIukkGbdkWHDlRWY3oTUUuw1SQ2Xk9KDsbJQtjIc1+G/O6gHaV4qv/R9W8NPmJExKTNDrAZbC1vIUnxqp4UpVo1hst8qPd1at94CndDYM5rG+7imGbdtxTxzamt819qdTO1OfvtctKawNAm7YXZrrWft6c7gI6j6SI4hxd+ZrrPBqbaRFHkZHjnNssO/yn4SaOHFFzccmu0MzvpPCf0qWZwd3sGHVYer1MnR2mHYqU84QPlW3nrHwJjkrpq3+q0JcBY6GsJs+RskHNtkMTKV05Iz6QUI5YZGwTpuXaRm036SmavjGc4IDlMaYCk/NmbB9BKpthJxLdUpczOHpnjXXHziotWD6cfEnbjU3byfD8HY5WrxSjsNT7SKmXN3hRof7bk985ewQVjGT42O3NbnfnqjQQWr/B7/zFTpLR4f526Bkq12CdCyf5lvrbq+POkLVdJ+uFfR7ds248Ue/jBQy6kM1tWmKF9QiwisFlA84eQ4CW3I93Rp97URv+AQa9zmbD0Ve3Udp+g6nF5I= diff --git a/Dockerfile b/Dockerfile index 23a142f8..96733933 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM php:7.4.2-alpine3.11 -LABEL maintainer="Alejandro Celaya " +FROM php:7.4.2-alpine3.11 as base ARG SHLINK_VERSION=2.0.5 ENV SHLINK_VERSION ${SHLINK_VERSION} @@ -9,7 +8,7 @@ ENV LC_ALL "C" WORKDIR /etc/shlink RUN \ - # Install mysl and calendar + # Install mysql and calendar docker-php-ext-install -j"$(nproc)" pdo_mysql calendar && \ # Install sqlite apk add --no-cache sqlite-libs sqlite-dev && \ @@ -36,17 +35,21 @@ RUN wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8 rm msodbcsql17_17.5.1.1-1_amd64.apk && \ rm mssql-tools_17.5.1.1-1_amd64.apk -# Install shlink -COPY . . -COPY --from=composer:1.9.3 /usr/bin/composer ./composer.phar -RUN rm -rf ./docker && \ - php composer.phar install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction && \ - php composer.phar clear-cache && \ - rm composer.* -# Add shlink to the path to ease running it after container is created +# Install shlink +FROM base as builder +COPY . . +COPY --from=composer:1.10.1 /usr/bin/composer ./composer.phar +RUN php composer.phar install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction && \ + sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php + + +# Prepare final image +FROM base +LABEL maintainer="Alejandro Celaya " + +COPY --from=builder /etc/shlink . RUN ln -s /etc/shlink/bin/cli /usr/local/bin/shlink -RUN sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php # Expose swoole port EXPOSE 8080 diff --git a/build.sh b/build.sh index cf42695b..b3d28b9d 100755 --- a/build.sh +++ b/build.sh @@ -25,7 +25,7 @@ cd "${builtcontent}" # Install dependencies echo "Installing dependencies with $composerBin..." ${composerBin} self-update -${composerBin} install --no-dev --optimize-autoloader --no-progress --no-interaction +${composerBin} install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction # Delete development files echo 'Deleting dev files...' diff --git a/docker/README.md b/docker/README.md index 699c1c75..f8e596ce 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,6 +1,5 @@ # Shlink Docker image -[![Docker build status](https://img.shields.io/docker/build/shlinkio/shlink.svg?style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) [![Docker pulls](https://img.shields.io/docker/pulls/shlinkio/shlink.svg?style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) This image provides an easy way to set up [shlink](https://shlink.io) on a container-based runtime. diff --git a/docker/build b/docker/build new file mode 100755 index 00000000..a02bd4e1 --- /dev/null +++ b/docker/build @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + +# If there is a tag, regardless the branch, build that docker tag and also "stable" +if [[ ! -z $TRAVIS_TAG ]]; then + docker build --build-arg VERSION=${TRAVIS_TAG#?} -t shlinkio/shlink:${TRAVIS_TAG#?} -t shlinkio/shlink:stable . + docker push shlinkio/shlink:${TRAVIS_TAG#?} + docker push shlinkio/shlink:stable +# If build branch is develop, build latest (on master, when there's no tag, do not build anything) +elif [[ "$TRAVIS_BRANCH" == 'develop' ]]; then + docker build -t shlinkio/shlink:latest . + docker push shlinkio/shlink:latest +fi diff --git a/hooks/build b/hooks/build deleted file mode 100755 index 6b381d74..00000000 --- a/hooks/build +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -ex - -if [[ ${SOURCE_BRANCH} == 'develop' ]]; then - SHLINK_RELEASE='latest' -else - SHLINK_RELEASE=${SOURCE_BRANCH#?} -fi - -docker build --build-arg SHLINK_VERSION=${SHLINK_RELEASE} -t ${IMAGE_NAME} . diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index 4af8844b..10df9352 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -32,7 +32,7 @@ class ShortUrl extends AbstractEntity private ?Chronos $validSince = null; private ?Chronos $validUntil = null; private ?int $maxVisits = null; - private ?Domain $domain; + private ?Domain $domain = null; private bool $customSlugWasProvided; private int $shortCodeLength; diff --git a/module/Rest/src/Entity/ApiKey.php b/module/Rest/src/Entity/ApiKey.php index f23d22e1..1d372c9c 100644 --- a/module/Rest/src/Entity/ApiKey.php +++ b/module/Rest/src/Entity/ApiKey.php @@ -11,7 +11,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class ApiKey extends AbstractEntity { private string $key; - private ?Chronos $expirationDate; + private ?Chronos $expirationDate = null; private bool $enabled; public function __construct(?Chronos $expirationDate = null)