diff --git a/.gitignore b/.gitignore index 80bd12f7eecb46423b76ddcd4d5c1ace6658e830..26f9f5e46a12613bd8f332a9a52e5a50672becc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -base/apps/apps \ No newline at end of file +base/apps/apps +build.env \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aef20c3b043ca349eb053ee99f4f39e774102fc4..21db97f169e63aa3319715544cc5a2c7661aed89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,60 +2,40 @@ variables: GIT_SUBMODULE_STRATEGY: recursive DOCKER_HUB_REPO: libresh/nextcloud -.compute_long_version: &compute_long_version - - export LONG_VERSION=`cat ${CI_PROJECT_DIR}/fullversions | grep $VERSION` +prepare: + stage: .pre + image: + name: registry.gitlab.com/gitlab-ci-utils/curl-jq:latest + entrypoint: [""] + script: + - source ./current_version + - source ./ci/functions + - prepare_env > build.env + artifacts: + reports: + dotenv: build.env -.test: +test: image: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] - variables: - DESTINATION_BASE: "--no-push" - DESTINATION_FR: "--no-push" - DESTINATION_WEB: "--no-push" + dependencies: + - prepare script: - - *compute_long_version - - echo $LONG_VERSION - - cp $DOCKER_SECRET_CONFIG /kaniko/.docker/config.json - - export CONTEXT=${CI_PROJECT_DIR}/base - - cd ${CONTEXT} - - /kaniko/executor --context ${CONTEXT} ${DESTINATION_BASE} --build-arg VERSION=$LONG_VERSION - - export CONTEXT=${CI_PROJECT_DIR}/web - - cd ${CONTEXT} - - /kaniko/executor --context ${CONTEXT} ${DESTINATION_WEB} --build-arg VERSION=$LONG_VERSION + - source ./ci/functions + - test_build except: - master + - /^feature.*$/ -test-v22: - extends: .test - variables: - VERSION: "22.2" - -test-v23: - extends: .test - variables: - VERSION: "23.0" - -.push: - extends: .test - before_script: - - *compute_long_version - - export DESTINATION_PREFIX="--destination ${DOCKER_HUB_REPO}" - - export DATE=`date "+%Y-%m-%d"` - - export DESTINATION_BASE="${DESTINATION_PREFIX}:${VERSION} ${DESTINATION_PREFIX}:${VERSION}-${DATE}" - - export DESTINATION_BASE="${DESTINATION_BASE} ${DESTINATION_PREFIX}:${LONG_VERSION} ${DESTINATION_PREFIX}:${LONG_VERSION}-${DATE}" - - export DESTINATION_WEB="${DESTINATION_PREFIX}:${VERSION}-web ${DESTINATION_PREFIX}:${VERSION}-web-${DATE}" - - export DESTINATION_WEB="${DESTINATION_WEB} ${DESTINATION_PREFIX}:${LONG_VERSION}-web ${DESTINATION_PREFIX}:${LONG_VERSION}-web-${DATE}" - except: [] +push: + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + dependencies: + - prepare + script: + - source ./ci/functions + - build only: - - master - -push-v22: - extends: .push - variables: - VERSION: "22.2" - -push-v23: - extends: .push - variables: - VERSION: "23.0" + - feature-new-versions diff --git a/base/Dockerfile b/base/Dockerfile index 0e3ffe8563bd7b2048313935be8290f724c2f757..8c0def946ee0430b86a6bb7505b5858d08e86351 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -1,13 +1,15 @@ -ARG VERSION +ARG MARKETTING_VERSION +ARG PATCH_VERSION FROM alpine as apps RUN apk add --no-cache jq curl bash patch COPY apps /apps WORKDIR /apps -ARG VERSION +ARG MINOR_VERSION RUN ./install.sh RUN rm ./install.sh ./install-list -FROM nextcloud:${VERSION}-fpm-alpine +FROM nextcloud:${MARKETTING_VERSION}-fpm-alpine +ENV VERSION $PATCH_VERSION RUN apk add --no-cache patch jq COPY redis.ini /usr/local/etc/php/conf.d/ COPY opcache-recommended.ini /usr/local/etc/php/conf.d/opcache.ini diff --git a/base/apps/install.sh b/base/apps/install.sh index d5f4d591b707dce205ab5e9949bbcdb14ca7d31b..fed81265ab797a26ac452eb68e556d6634099768 100755 --- a/base/apps/install.sh +++ b/base/apps/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -eux -curl -Ls https://apps.nextcloud.com/api/v1/platform/${VERSION}/apps.json > /tmp/apps.json +curl -Ls https://apps.nextcloud.com/api/v1/platform/${MINOR_VERSION}/apps.json > /tmp/apps.json function download_link() { cat /tmp/apps.json | jq '.[] | select(.id == "'$1'") | .releases | map(select(.version|test("alpha|beta|rc|RC|build")|not)) | sort_by(.version | split(".") | map(tonumber))[-1] | .download' diff --git a/ci/functions b/ci/functions new file mode 100644 index 0000000000000000000000000000000000000000..223954f5f2b57f013f8b63d0c7321ed791338b27 --- /dev/null +++ b/ci/functions @@ -0,0 +1,76 @@ +function prepare_env() { + curl https://api.github.com/repos/nextcloud/server/tags > /tmp/tags + export MINOR_VERSION=`cat /tmp/tags | jq '.[] | select(.name|test("v'${MARKETTING_VERSION}'.")).name' | head -n1 | cut -d\" -f2 | cut -c2-` + export PATCH_NUMBER=`curl https://raw.githubusercontent.com/nextcloud/server/v${MINOR_VERSION}/version.php | grep '$OC_Version =' | cut -d, -f4 | cut -d] -f1 | xargs` + echo "MARKETTING_VERSION=$MARKETTING_VERSION" + echo "MINOR_VERSION=$MINOR_VERSION" + echo "PATCH_VERSION=$MINOR_VERSION.$PATCH_NUMBER" +} + +function build_kaniko() { + echo "======Building kaniko with following env:" + echo $CONTEXT + echo $DESTINATION + echo $BASE_TAG + echo "======" + /kaniko/executor --context ${CONTEXT} ${DESTINATION} --build-arg MARKETTING_VERSION=$MARKETTING_VERSION --build-arg MINOR_VERSION=$MINOR_VERSION --build-arg PATCH_VERSION=$PATCH_VERSION --build-arg BASE_TAG=$BASE_TAG +} + +function print_versions() { + echo "======Building the following version:" + echo $MARKETTING_VERSION + echo $MINOR_VERSION + echo $PATCH_VERSION + echo "======" +} + +function build_base() { + export CONTEXT=${CI_PROJECT_DIR}/base + cd ${CONTEXT} + build_kaniko +} + +function build_web() { + export CONTEXT=${CI_PROJECT_DIR}/web + cd ${CONTEXT} + build_kaniko +} + +function test_build() { + print_versions + export DESTINATION: "--no-push" + build_base +} + +function build() { + print_versions + cp $DOCKER_SECRET_CONFIG /kaniko/.docker/config.json + export DESTINATION_PREFIX="--destination ${DOCKER_HUB_REPO}" + export DATE=`date "+%Y-%m-%dT%H-%M-%SZ"` + + if [ "$VAR1" = "master" ]; then + export BASE_TAG=${MINOR_VERSION} + export DESTINATION="\ + ${DESTINATION_PREFIX}:${MINOR_VERSION}\ + ${DESTINATION_PREFIX}:${MINOR_VERSION}-${DATE}\ + " + build_base + export DESTINATION="\ + ${DESTINATION_PREFIX}:web-${MINOR_VERSION}\ + ${DESTINATION_PREFIX}:web-${MINOR_VERSION}-${DATE}\ + " + build_web + else # feature branch + export BASE_TAG=${CI_COMMIT_BRANCH} + export DESTINATION="\ + ${DESTINATION_PREFIX}:${CI_COMMIT_BRANCH}\ + ${DESTINATION_PREFIX}:${CI_COMMIT_BRANCH}-${DATE}\ + " + build_base + export DESTINATION="\ + ${DESTINATION_PREFIX}:web-${CI_COMMIT_BRANCH}\ + ${DESTINATION_PREFIX}:web-${CI_COMMIT_BRANCH}-${DATE}\ + " + build_web + fi +} \ No newline at end of file diff --git a/current_version b/current_version new file mode 100644 index 0000000000000000000000000000000000000000..ead8e5189f22a0b4004596c14375dd60e129aaee --- /dev/null +++ b/current_version @@ -0,0 +1 @@ +export MARKETTING_VERSION=23 \ No newline at end of file diff --git a/fr/Dockerfile b/fr/Dockerfile deleted file mode 100644 index bc937d750165199d65b5e9701ca3e2f63fd7a190..0000000000000000000000000000000000000000 --- a/fr/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -ARG VERSION -FROM libresh/nextcloud:${VERSION} as builder -COPY --chown=www-data:root _build/html/release/fr/ /var/www/html/core/doc/user/ diff --git a/fullversion.sh b/fullversion.sh deleted file mode 100755 index e1c3315289d5a3fa76174ad7e0f3ff176ca70dd7..0000000000000000000000000000000000000000 --- a/fullversion.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -min_version='17.0' - -# version_greater_or_equal A B returns whether A >= B -function version_greater_or_equal() { - [[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" || "$1" == "$2" ]]; -} - -fullversions=( $( curl -fsSL 'https://download.nextcloud.com/server/releases/' |tac|tac| \ - grep -oE 'nextcloud-[[:digit:]]+(\.[[:digit:]]+){2}' | \ - grep -oE '[[:digit:]]+(\.[[:digit:]]+){2}' | \ - sort -urV ) ) -versions=( $( printf '%s\n' "${fullversions[@]}" | cut -d. -f1-2 | sort -urV ) ) -for version in "${versions[@]}"; do - fullversion="$( printf '%s\n' "${fullversions[@]}" | grep -E "^$version" | head -1 )" - - if version_greater_or_equal "$version" "$min_version"; then - echo "$fullversion" - fi -done - diff --git a/fullversions b/fullversions deleted file mode 100644 index 52fe2c732cf1d2a830c8c28399ae8f44e9db8688..0000000000000000000000000000000000000000 --- a/fullversions +++ /dev/null @@ -1,2 +0,0 @@ -22.2.10 -23.0.7 diff --git a/web/Dockerfile b/web/Dockerfile index f021c2b7967c5ef16c2058cc7a1e6c6d88897ac4..108d3080ecee116ec2dbec2142b82e2dc4949030 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,5 +1,5 @@ -ARG VERSION -FROM libresh/nextcloud:${VERSION} as builder +ARG BASE_TAG +FROM libresh/nextcloud:${BASE_TAG} as builder FROM nginx:alpine COPY --from=builder /usr/src/nextcloud /usr/src/nextcloud COPY default.conf.template /etc/nginx/templates/