Refactoring action code

This commit is contained in:
danilapog 2022-07-19 16:41:47 +03:00
parent 475d6d56bf
commit 31817c37e4
2 changed files with 43 additions and 61 deletions

View file

@ -29,6 +29,7 @@ jobs:
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub - name: Login to Docker Hub
@ -43,71 +44,51 @@ jobs:
- name: Build 4testing - name: Build 4testing
run: | run: |
DOCKER_TAG=$(echo ${{ env.RELEASE_VERSION }} | sed 's/^.//' ) ### At this step build variable declaration ###
DOCKER_TAG=$( echo ${{ env.RELEASE_VERSION }} | sed 's/^.//' )
PACKAGE_VERSION=$( echo $DOCKER_TAG | sed -E 's/(.*)\./\1-/' ) PACKAGE_VERSION=$( echo $DOCKER_TAG | sed -E 's/(.*)\./\1-/' )
if [[ ${{ env.RELEASE_VERSION }} == v99.99* ]]; then NODE_PLATFORMS=$( echo ${{ steps.buildx.outputs.platforms }} | sed 's/linux\///g' | sed 's/,/ /g' )
PACKAGE_URL=${{ secrets.UNSTABLE_REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_amd64.deb echo "Start check avalivable build platforms >>"
URL_ARG=${{ secrets.UNSTABLE_REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_TARGETARCH.deb ### In this loop we will check all avalivable documentserver architectures. After that all accessed arch will be added to build-platforms. ###
else for ARCH in ${NODE_PLATFORMS}; do
PACKAGE_URL=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_amd64.deb if [[ ${{ env.RELEASE_VERSION }} == v7.* ]] || [[ ${{ env.RELEASE_VERSION }} == v8.* ]] || [[ ${{ env.RELEASE_VERSION }} == v9.* ]] || [[ ${{ env.RELEASE_VERSION }} == v10.* ]]; then
URL_ARG=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_TARGETARCH.deb PACKAGE_URL_CHECK=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb
fi PACKAGE_URL_BUILD=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_TARGETARCH.deb
STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "$PACKAGE_URL") fi
if [[ "$STATUS" = "200" ]]; then if [[ ${{ env.RELEASE_VERSION }} == v99.* ]]; then
echo "Have access to documentserver${{ matrix.edition }} amd64 arch >> check arm64 access" PACKAGE_URL_CHECK=${{ secrets.UNSTABLE_REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb
AMD64=present PACKAGE_URL_BUILD=${{ secrets.UNSTABLE_REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_TARGETARCH.deb
else fi
echo "ALARM: Have no access to documentserver${{ matrix.edition }} amd64" STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "${PACKAGE_URL_CHECK}")
AMD64= if [[ "$STATUS" = "200" ]]; then
fi echo "${ARCH} is avalivable >> set like one of build platforms"
if [[ ${{ env.RELEASE_VERSION }} == v99.99* ]]; then PLATFORMS+=(linux/${ARCH},)
PACKAGE_URL=${{ secrets.UNSTABLE_REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_arm64.deb BUILD_PLATFORMS=$( echo ${PLATFORMS[@]} | sed 's/ //g' | sed 's/\(.*\),/\1/' )
else else
PACKAGE_URL=${{ secrets.REPO_URL }}${{ matrix.edition }}_"$PACKAGE_VERSION"_arm64.deb echo "${ARCH} in not avalivable"
fi fi
STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "$PACKAGE_URL") done
if [[ "$STATUS" = "200" ]]; then ### At this step if there is no access to any platform and platform list is empty, build will exit with 1. ###
echo "Have access to documentserver${{ matrix.edition }} arm64 arch" if [[ -z ${BUILD_PLATFORMS} ]]; then
ARM64=present echo "Have no access to any platform >> exit with 1"
else
echo "ALARM: Have no access to documentserver${{ matrix.edition }} arm64"
ARM64=
fi
##### this setting up build platform ####
if [[ "$AMD64" = "present" ]] && [[ "$ARM64" = "present" ]]; then
PLATFORM="linux/amd64,linux/arm64"
echo "Present arm64/amd64, build miltiarch"
fi
if [[ "$AMD64" != "present" ]] && [[ "$ARM64" = "present" ]]; then
PLATFORM="linux/arm64"
echo "Present only arm64, build arm image"
fi
if [[ "$AMD64" = "present" ]] && [[ "$ARM64" != "present" ]]; then
PLATFORM="linux/amd64"
echo "Present only amd64, build amd image"
fi
if [[ "$AMD64" != "present" ]] && [[ "$ARM64" != "present" ]]; then
echo "FAILED: Build will not started requested architectures does not present"
exit 1 exit 1
fi fi
PRODUCT_EDITION=${{ matrix.edition }} COMPANY_NAME=${{ env.COMPANY_NAME }} \ echo "DONE: Check passed >> Build for platforms: ${BUILD_PLATFORMS}"
PRODUCT_NAME=${{ env.PRODUCT_NAME }} DOCKERFILE=Dockerfile \ ### Preconfiguration for debugging with --print key ###
PREFIX_NAME=4testing- TAG=$DOCKER_TAG PLATFORM=$PLATFORM \ PRODUCT_EDITION=${{ matrix.edition }} PACKAGE_URL=$PACKAGE_URL_BUILD \
PACKAGE_URL=${URL_ARG} docker buildx bake \ PRODUCT_NAME=${{ env.PRODUCT_NAME }} DOCKERFILE=Dockerfile \
PREFIX_NAME=4testing- TAG=$DOCKER_TAG PLATFORM=$BUILD_PLATFORMS \
docker buildx bake \
-f docker-bake.hcl ${{ matrix.images }} \ -f docker-bake.hcl ${{ matrix.images }} \
--print --print
echo "Build is starting ... >>"
echo "Start build >>" ### Build and push images at this step ###
PRODUCT_EDITION=${{ matrix.edition }} PACKAGE_URL=$PACKAGE_URL_BUILD \
PRODUCT_EDITION=${{ matrix.edition }} COMPANY_NAME=${{ env.COMPANY_NAME }} \ PRODUCT_NAME=${{ env.PRODUCT_NAME }} DOCKERFILE=Dockerfile \
PRODUCT_NAME=${{ env.PRODUCT_NAME }} DOCKERFILE=Dockerfile \ PREFIX_NAME=4testing- TAG=$DOCKER_TAG PLATFORM=$BUILD_PLATFORMS \
PREFIX_NAME=4testing- TAG=$DOCKER_TAG PLATFORM=$PLATFORM \ docker buildx bake \
PACKAGE_URL=${URL_ARG} docker buildx bake \
-f docker-bake.hcl ${{ matrix.images }} \ -f docker-bake.hcl ${{ matrix.images }} \
--push --push
echo "DONE: Build success >> exit with 0" echo "DONE: Build success >> exit with 0"
exit 0 exit 0
shell: bash shell: bash

View file

@ -81,8 +81,9 @@ ENV COMPANY_NAME=$COMPANY_NAME \
PRODUCT_NAME=$PRODUCT_NAME \ PRODUCT_NAME=$PRODUCT_NAME \
PRODUCT_EDITION=$PRODUCT_EDITION PRODUCT_EDITION=$PRODUCT_EDITION
RUN if [ $(uname -m) = "x86_64" ] ; then ARCH=amd64 ; else ARCH=arm64 ; fi && \ RUN if [ $(uname -m) = "x86_64" ] || [ $(uname -m) = "amd64" ]; then TARGETARCH=amd64; fi && \
PACKAGE_URL=$( echo $PACKAGE_URL | sed "s/TARGETARCH/"${ARCH}"/g") && \ if [ $(uname -m) = "aarch64" ] || [ $(uname -m) = "arm64" ]; then TARGETARCH=arm64; fi && \
PACKAGE_URL=$( echo ${PACKAGE_URL} | sed "s/TARGETARCH/"${TARGETARCH}"/g") && \
wget -q -P /tmp "$PACKAGE_URL" && \ wget -q -P /tmp "$PACKAGE_URL" && \
apt-get -y update && \ apt-get -y update && \
service postgresql start && \ service postgresql start && \