From 496851e8c5ab4a413eba60cbe2fd931350242368 Mon Sep 17 00:00:00 2001 From: Anze Date: Sun, 8 Nov 2020 19:37:19 +0100 Subject: [PATCH] Use multiplatform build --- .github/workflows/on_release.yml | 23 +++++++++++++++++------ Dockerfile | 18 +++++++++--------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index de37545..9bee22e 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -13,8 +13,18 @@ jobs: - name: Checkout source code uses: actions/checkout@v1 + - name: Set up QEMU for more platforms + uses: docker/setup-qemu-action@v1 + with: + platforms: amd64,arm - - name: Deploy to Docker Hub + - name: Set docker build as alias to buildx (multiarch build) + uses: docker/setup-buildx-action@v1 + id: buildx + # with: + # install: true + + - name: Deploy to Docker Hub - ARMv7 if: success() && startsWith(github.ref, 'refs/tags/v') env: GITHUB_REF_TAG: ${{ github.ref }} @@ -22,14 +32,15 @@ jobs: DOCKER_IMAGE: grafolean/grafolean-snmp-bot DOCKER_USER: grafolean DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + BUILD_PLATFORMS: linux/arm/v7 run: | + echo "Available plaftorms: ${{ steps.buildx.outputs.platforms }}" + echo "Building for plaftorms: $BUILD_PLATFORMS" export VERSION=${GITHUB_REF_TAG:10:50} echo "Version is $VERSION" export LAST_KNOWN_VERSION=`git tag -l --sort=-version:refname "v*.*.*" | grep -v rc | head -n 1 | tr -d '[:space:]'` echo "Last known version is $LAST_KNOWN_VERSION" docker login -u $DOCKER_USER -p $DOCKER_PASSWORD $DOCKER_REGISTRY - docker build -t "docker.io/$DOCKER_IMAGE:$VERSION" -t "docker.io/$DOCKER_IMAGE:latest" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . - [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker tag "docker.io/$DOCKER_IMAGE:$VERSION" "docker.io/$DOCKER_IMAGE:latest" || echo "NOT MARKING AS LATEST!" - docker images - docker push "docker.io/$DOCKER_IMAGE:$VERSION" - [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker push "docker.io/$DOCKER_IMAGE:latest" || echo "NOT LATEST!" + [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && echo "MARKING AS LATEST!" || echo "NOT MARKING AS LATEST!" + [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker buildx build --push --platform "$BUILD_PLATFORMS" -t "docker.io/$DOCKER_IMAGE:$VERSION" -t "docker.io/$DOCKER_IMAGE:latest" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . + [ "$LAST_KNOWN_VERSION" != "$VERSION" ] && docker buildx build --push --platform "$BUILD_PLATFORMS" -t "docker.io/$DOCKER_IMAGE:$VERSION" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . diff --git a/Dockerfile b/Dockerfile index 52d0745..54664ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,15 +29,15 @@ LABEL org.label-schema.vendor="Grafolean" \ org.label-schema.build-date=$BUILD_DATE \ org.label-schema.docker.schema-version="1.0" COPY --from=python-requirements /requirements.txt /requirements.txt -RUN \ - apt-get update && \ - apt-get install --no-install-recommends -q -y libsnmp-dev build-essential git && \ - pip install --no-cache-dir -r /requirements.txt && \ - apt-get purge -y build-essential && \ - apt-get clean autoclean && \ - apt-get autoremove --yes && \ - rm -rf /var/lib/{apt,dpkg,cache,log}/ && \ - echo "alias l='ls -altr'" >> /root/.bashrc +# RUN \ +# apt-get update && \ +# apt-get install --no-install-recommends -q -y libsnmp-dev build-essential libpq-dev python3-dev git && \ +# pip install --no-cache-dir -r /requirements.txt && \ +# apt-get purge -y build-essential libpq-dev python3-dev && \ +# apt-get clean autoclean && \ +# apt-get autoremove --yes && \ +# rm -rf /var/lib/{apt,dpkg,cache,log}/ && \ +# echo "alias l='ls -altr'" >> /root/.bashrc COPY --from=build-backend /snmpbot/ /snmpbot/ WORKDIR /snmpbot # check for "fail" file and if it exists, remove it and fail the check: