From 2213fc70f5ab693e0f6b0292d22900799440ef68 Mon Sep 17 00:00:00 2001 From: Danil Titarenko <77471369+danilapog@users.noreply.github.com> Date: Thu, 21 Jul 2022 18:44:06 +0300 Subject: [PATCH] Add another tags processing (#464) * Add support for processing other tags * Print build-info before build start * Cosmetic changes * Add architecture and URL processing * Refactoring action code * Refactoring code * Refactoring code * Cosmetic changes * Remove some check package version * Refactoring code * Redefining url variable for dockerfile * Cosmetic changes * Changes platform conditions check * Set to use default TARGETARCH in build --- .github/workflows/4testing-build.yml | 76 +++++++++++++++++----------- Dockerfile | 3 +- docker-bake.hcl | 12 ++++- 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/.github/workflows/4testing-build.yml b/.github/workflows/4testing-build.yml index 0716979..306b6e1 100644 --- a/.github/workflows/4testing-build.yml +++ b/.github/workflows/4testing-build.yml @@ -29,6 +29,7 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v2 - name: Login to Docker Hub @@ -38,38 +39,55 @@ jobs: password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Get Tag Name - id: tag_name run: | - echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: Build 4testing run: | - DOCKER_TAG=$(echo ${{ steps.tag_name.outputs.SOURCE_TAG }} | sed 's/^.//' ) - PACKAGE_VERSION=$(echo $DOCKER_TAG | sed 's/\./-/3') - PACKAGE_URL=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_amd64.deb - STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "$PACKAGE_URL") - if [[ "$STATUS" = "200" ]]; then - echo "Have access to documentserver${{ matrix.edition }} amd64 arch >> check arm64 access" - else - echo "FAILED: Have no access to documentserver${{ matrix.edition }} amd64 arch" - exit 1 - fi - PACKAGE_URL=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_arm64.deb - STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "$PACKAGE_URL") - if [[ "$STATUS" = "200" ]]; then - echo "Have access to documentserver${{ matrix.edition }} arm64 arch" - echo "All architecture are available >> build is starting." - sed -i "s|http://download.onlyoffice.com/install/documentserver/linux/\${COMPANY_NAME}-\${PRODUCT_NAME}\${PRODUCT_EDITION}|${{ secrets.REPO_URL }}${{ matrix.edition }}_$PACKAGE_VERSION|g" Dockerfile - PRODUCT_EDITION=${{ matrix.edition }} COMPANY_NAME=${{ env.COMPANY_NAME }} \ - PRODUCT_NAME=${{ env.PRODUCT_NAME }} DOCKERFILE=Dockerfile \ - PREFIX_NAME=4testing- TAG=$DOCKER_TAG \ - docker buildx bake \ - -f docker-bake.hcl ${{ matrix.images }} \ - --push - echo "DONE: Build success >> exit with 0" - exit 0 - else - echo "FAILED: Have no access to some required architecture documentserver${{ matrix.edition }} >> Exit with 0." - exit 1 + ### ==>> At this step build variable declaration ### + DOCKER_TAG=$( echo ${{ env.RELEASE_VERSION }} | sed 's/^.//' ) + PACKAGE_VERSION=$( echo $DOCKER_TAG | sed -E 's/(.*)\./\1-/' ) + NODE_PLATFORMS=$( echo ${{ steps.buildx.outputs.platforms }} | sed 's/linux\///g' | sed 's/,/ /g' ) + echo "Start check avalivable build platforms >>" + + ### ==>> In this loop we will check all avalivable documentserver architectures. After that all accessed arch will be added to build-platforms list. ### + for ARCH in ${NODE_PLATFORMS}; do + REPO_URL=${{ secrets.REPO_URL }} + if [[ ${{ env.RELEASE_VERSION }} == v99.* ]]; then + REPO_URL=${{ secrets.UNSTABLE_REPO_URL }} + fi + PACKAGE_URL_CHECK=${REPO_URL}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb + STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "${PACKAGE_URL_CHECK}") + if [[ "$STATUS" = "200" ]]; then + echo "✔ ${ARCH} is avalivable >> set like one of build platforms" + PLATFORMS+=(linux/${ARCH},) + BUILD_PLATFORMS=$( echo ${PLATFORMS[@]} | sed 's/ //g' | sed 's/\(.*\),/\1/' ) + else + echo "${ARCH} in not avalivable" + fi + done + PACKAGE_URL_BUILD=$( echo ${PACKAGE_URL_CHECK} | sed -e "s/${PACKAGE_VERSION}_.*.deb/${PACKAGE_VERSION}_TARGETARCH.deb/g" ) + + ### ==>> At this step if there is no access to any platform and platform list is empty, build will exit with 1. ### + if [[ -z ${BUILD_PLATFORMS} ]]; then + echo "Have no access to any platform >> exit with 1" + exit 1 fi + echo "DONE: Check passed >> Build for platforms: ${BUILD_PLATFORMS}" + echo "Build is starting ... >>" + + ### ==>> Build and push images at this step ### + PRODUCT_EDITION=${{ matrix.edition }} \ + PACKAGE_URL=$PACKAGE_URL_BUILD \ + PRODUCT_NAME=${{ env.PRODUCT_NAME }} \ + DOCKERFILE=Dockerfile \ + PREFIX_NAME=4testing- \ + TAG=$DOCKER_TAG \ + PLATFORM=$BUILD_PLATFORMS \ + COMPANY_NAME=${{ env.COMPANY_NAME }} \ + docker buildx bake \ + -f docker-bake.hcl ${{ matrix.images }} \ + --push + echo "DONE: Build success >> exit with 0" + exit 0 shell: bash diff --git a/Dockerfile b/Dockerfile index 7405b2b..dc73ab6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -81,7 +81,8 @@ ENV COMPANY_NAME=$COMPANY_NAME \ PRODUCT_NAME=$PRODUCT_NAME \ PRODUCT_EDITION=$PRODUCT_EDITION -RUN wget -q -P /tmp "$PACKAGE_URL" && \ +RUN PACKAGE_URL=$( echo ${PACKAGE_URL} | sed "s/TARGETARCH/"${TARGETARCH}"/g") && \ + wget -q -P /tmp "$PACKAGE_URL" && \ apt-get -y update && \ service postgresql start && \ apt-get -yq install /tmp/$(basename "$PACKAGE_URL") && \ diff --git a/docker-bake.hcl b/docker-bake.hcl index 04ed4a0..6932d4b 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -30,15 +30,25 @@ variable "DOCKERFILE" { default = "" } +variable "PLATFORM" { + default = "" +} + +variable "PACKAGE_URL" { + default = "" +} + target "documentserver" { target = "documentserver" dockerfile= "${DOCKERFILE}" tags = ["docker.io/${COMPANY_NAME}/${PREFIX_NAME}${PRODUCT_NAME}${PRODUCT_EDITION}:${TAG}"] - platforms = ["linux/amd64", "linux/arm64"] + platforms = ["${PLATFORM}"] args = { "PRODUCT_EDITION": "${PRODUCT_EDITION}" "PRODUCT_NAME": "${PRODUCT_NAME}" "COMPANY_NAME": "${COMPANY_NAME}" + "PACKAGE_URL": "{PACKAGE_URL}" + "PLATFORM": "${PLATFORM}" } }