Refactoring testing build (#496)

* Fix dockerfile args

* Refactoring testing build action

* Secret repo baseurl

* Fix package version
This commit is contained in:
Semyon Bezrukov 2022-09-16 12:28:44 +03:00 committed by GitHub
parent b9bfa7b90c
commit bac88530c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 76 deletions

@ -2,23 +2,78 @@
name: 4testing multiarch-build name: 4testing multiarch-build
on: on:
push: workflow_dispatch:
tags: inputs:
- "v*" build:
description: 'Build number (ex. 45)'
type: string
required: true
amd64:
type: boolean
description: 'Build AMD64'
default: true
arm64:
type: boolean
description: 'Build ARM64'
default: true
community:
type: boolean
description: 'Build Community Edition'
default: true
enterprise:
type: boolean
description: 'Build Enterprise Edition'
default: true
developer:
type: boolean
description: 'Build Developer Edition'
default: true
env: env:
COMPANY_NAME: "onlyoffice" COMPANY_NAME: "onlyoffice"
PRODUCT_NAME: "documentserver" PRODUCT_NAME: "documentserver"
jobs: jobs:
build: prepare:
name: "Build image: DocumentServer${{ matrix.edition }}"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps:
- id: matrix
run: |
set -ex
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if ! [[ $BRANCH_NAME == develop || $BRANCH_NAME =~ hotfix || $BRANCH_NAME =~ release ]]; then
echo "Wrong branch."
exit 1
fi
[ ${{ github.event.inputs.amd64 }} = true ] && PLATFORMS+=("amd64")
[ ${{ github.event.inputs.arm64 }} = true ] && PLATFORMS+=("arm64")
if [ -z ${PLATFORMS} ]; then
echo "None of the platforms are selected."
exit 1
fi
[ ${{ github.event.inputs.community }} = true ] && EDITIONS+=("community")
[ ${{ github.event.inputs.enterprise }} = true ] && EDITIONS+=("enterprise")
[ ${{ github.event.inputs.developer }} = true ] && EDITIONS+=("developer")
if [ -z ${EDITIONS} ]; then
echo "None of the editions are selected."
exit 1
fi
echo "::set-output name=editions::$(jq -n -c --arg s "${EDITIONS[*]}" '($s|split(" "))')"
outputs:
editions: ${{ steps.matrix.outputs.editions }}
build:
name: "Build ${{ matrix.image }}-${{ matrix.edition }}"
runs-on: ubuntu-latest
needs: prepare
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
images: ["documentserver"] image: ["documentserver"]
edition: ["", "-ee", "-de"] edition: ${{ fromJSON(needs.prepare.outputs.editions) }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -36,68 +91,49 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }} username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get Tag Name
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build 4testing - name: Build 4testing
run: | run: |
set -eux
### ==>> At this step build variable declaration ### ### ==>> 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' )
EXPECTED_PLATFORMS="linux/amd64,linux/arm64"
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. ### case ${{ matrix.edition }} in
for ARCH in ${NODE_PLATFORMS}; do community)
REPO_URL=${{ secrets.REPO_URL }} PRODUCT_EDITION=""
if [[ ${{ env.RELEASE_VERSION }} == v99.* ]]; then ;;
REPO_URL=${{ secrets.UNSTABLE_REPO_URL }} enterprise)
DEVELOP_BUILD=true PRODUCT_EDITION="-ee"
fi ;;
PACKAGE_URL_CHECK=${REPO_URL}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb developer)
STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "${PACKAGE_URL_CHECK}") PRODUCT_EDITION="-de"
if [[ "$STATUS" = "200" ]]; then ;;
echo "✔ ${ARCH} is avalivable >> set like one of build platforms" esac
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. ### [ ${{ github.event.inputs.amd64 }} = true ] && PLATFORMS+=("amd64")
if [[ -z ${BUILD_PLATFORMS} ]]; then [ ${{ github.event.inputs.arm64 }} = true ] && PLATFORMS+=("arm64")
echo "Have no access to any platform >> exit with 1" PLATFORM=$(echo ${PLATFORMS[*]/#/linux/} | tr ' ' ',')
exit 1
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [ $BRANCH_NAME = develop ]; then
RELEASE_BRANCH=unstable
PRODUCT_VERSION=99.99.99
elif [[ $BRANCH_NAME =~ hotfix || $BRANCH_NAME =~ release ]]; then
RELEASE_BRANCH=testing
PRODUCT_VERSION=${BRANCH_NAME#*/v}
fi fi
echo "DONE: Check passed >> Build for platforms: ${BUILD_PLATFORMS}" BUILD_NUMBER=${{ github.event.inputs.build }}
echo "Build is starting ... >>"
### == >> Set exit code for action export PRODUCT_EDITION
if [ ${BUILD_PLATFORMS} == ${EXPECTED_PLATFORMS} ]; then export PACKAGE_VERSION=${PRODUCT_VERSION}-${BUILD_NUMBER}
EXIT_CODE=0 export PACKAGE_BASEURL=${{ secrets.REPO_BASEURL }}/${RELEASE_BRANCH}/ubuntu
echo "OK: Build platforms is expected" export RELEASE_BRANCH
else export PLATFORM
EXIT_CODE=1 export DOCKERFILE=Dockerfile
echo "WARNING: Build platforms is unexpected action is gonna be marked as Failed" export PREFIX_NAME=4testing-
fi export TAG=${PRODUCT_VERSION}.${BUILD_NUMBER}
### ==>> Build and push images at this step ### ### ==>> Build and push images at this step ###
PRODUCT_EDITION=${{ matrix.edition }} \
PACKAGE_URL=$PACKAGE_URL_BUILD \ docker buildx bake -f docker-bake.hcl ${{ matrix.image }} --push
PRODUCT_NAME=${{ env.PRODUCT_NAME }} \ echo "DONE: Build success"
DOCKERFILE=Dockerfile \
PREFIX_NAME=4testing- \
TAG=$DOCKER_TAG \
PLATFORM=$BUILD_PLATFORMS \
COMPANY_NAME=${{ env.COMPANY_NAME }} \
DEVELOP_BUILD=$DEVELOP_BUILD \
docker buildx bake \
-f docker-bake.hcl ${{ matrix.images }} \
--push
echo "DONE: Build success >> exit with ${EXIT_CODE}"
exit ${EXIT_CODE}
shell: bash shell: bash

@ -71,25 +71,26 @@ COPY run-document-server.sh /app/ds/run-document-server.sh
EXPOSE 80 443 EXPOSE 80 443
ARG TARGETARCH
ARG PRODUCT_EDITION=
ARG COMPANY_NAME=onlyoffice ARG COMPANY_NAME=onlyoffice
ARG PRODUCT_NAME=documentserver ARG PRODUCT_NAME=documentserver
ARG PACKAGE_URL="http://download.onlyoffice.com/install/documentserver/linux/${COMPANY_NAME}-${PRODUCT_NAME}${PRODUCT_EDITION}_$TARGETARCH.deb" ARG PRODUCT_EDITION=
ARG PACKAGE_VERSION=0.0.0-0
ARG TARGETARCH
ARG PACKAGE_BASEURL="http://download.onlyoffice.com/install/documentserver/linux"
ARG PACKAGE_FILE="${COMPANY_NAME}-${PRODUCT_NAME}${PRODUCT_EDITION}_${PACKAGE_VERSION}_${TARGETARCH}.deb"
ENV COMPANY_NAME=$COMPANY_NAME \ ENV COMPANY_NAME=$COMPANY_NAME \
PRODUCT_NAME=$PRODUCT_NAME \ PRODUCT_NAME=$PRODUCT_NAME \
PRODUCT_EDITION=$PRODUCT_EDITION PRODUCT_EDITION=$PRODUCT_EDITION
RUN PACKAGE_URL=$( echo ${PACKAGE_URL} | sed "s/TARGETARCH/"${TARGETARCH}"/g") && \ RUN wget -q -P /tmp "$PACKAGE_BASEURL/$PACKAGE_FILE" && \
wget -q -P /tmp "$PACKAGE_URL" && \
apt-get -y update && \ apt-get -y update && \
service postgresql start && \ service postgresql start && \
apt-get -yq install /tmp/$(basename "$PACKAGE_URL") && \ apt-get -yq install /tmp/$PACKAGE_FILE && \
service postgresql stop && \ service postgresql stop && \
service supervisor stop && \ service supervisor stop && \
chmod 755 /app/ds/*.sh && \ chmod 755 /app/ds/*.sh && \
rm -f /tmp/$(basename "$PACKAGE_URL") && \ rm -f /tmp/$PACKAGE_FILE && \
rm -rf /var/log/$COMPANY_NAME && \ rm -rf /var/log/$COMPANY_NAME && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*

@ -26,6 +26,10 @@ variable "PRODUCT_NAME" {
default = "" default = ""
} }
variable "PACKAGE_VERSION" {
default = ""
}
variable "DOCKERFILE" { variable "DOCKERFILE" {
default = "" default = ""
} }
@ -34,11 +38,15 @@ variable "PLATFORM" {
default = "" default = ""
} }
variable "PACKAGE_URL" { variable "PACKAGE_BASEURL" {
default = "" default = ""
} }
variable "DEVELOP_BUILD" { variable "PACKAGE_FILE" {
default = ""
}
variable "RELEASE_BRANCH" {
default = "" default = ""
} }
@ -47,14 +55,15 @@ target "documentserver" {
dockerfile = "${DOCKERFILE}" dockerfile = "${DOCKERFILE}"
tags = [ tags = [
"docker.io/${COMPANY_NAME}/${PREFIX_NAME}${PRODUCT_NAME}${PRODUCT_EDITION}:${TAG}", "docker.io/${COMPANY_NAME}/${PREFIX_NAME}${PRODUCT_NAME}${PRODUCT_EDITION}:${TAG}",
notequal("",DEVELOP_BUILD) ? "docker.io/${COMPANY_NAME}/${PREFIX_NAME}${PRODUCT_NAME}${PRODUCT_EDITION}:latest": "", equal("testing",RELEASE_BRANCH) ? "docker.io/${COMPANY_NAME}/${PREFIX_NAME}${PRODUCT_NAME}${PRODUCT_EDITION}:latest": "",
] ]
platforms = ["${PLATFORM}"] platforms = ["${PLATFORM}"]
args = { args = {
"PRODUCT_EDITION": "${PRODUCT_EDITION}"
"PRODUCT_NAME": "${PRODUCT_NAME}"
"COMPANY_NAME": "${COMPANY_NAME}" "COMPANY_NAME": "${COMPANY_NAME}"
"PACKAGE_URL": "${PACKAGE_URL}" "PRODUCT_NAME": "${PRODUCT_NAME}"
"PRODUCT_EDITION": "${PRODUCT_EDITION}"
"PACKAGE_VERSION": "${PACKAGE_VERSION}"
"PACKAGE_BASEURL": "${PACKAGE_BASEURL}"
"PLATFORM": "${PLATFORM}" "PLATFORM": "${PLATFORM}"
} }
} }