|
| 1 | +name: Allure Docker Service Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "*" |
| 7 | + |
| 8 | + tags: |
| 9 | + - v* |
| 10 | + |
| 11 | + pull_request: |
| 12 | + |
| 13 | +env: |
| 14 | + DOCKER_IMAGE: frankescobar/allure-docker-service |
| 15 | + ALLURE_RELEASE: 2.13.8 |
| 16 | + QEMU_VERSION: v4.0.0 |
| 17 | + DOCKER_CLI_EXPERIMENTAL: enabled |
| 18 | + |
| 19 | +jobs: |
| 20 | + build_release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + ARCH: [amd64, arm32v7, arm64v8] |
| 25 | + include: |
| 26 | + - ARCH: amd64 |
| 27 | + DOCKER_FILE: Dockerfile.bionic |
| 28 | + JDK: adoptopenjdk:11-jre-openj9-bionic |
| 29 | + QEMU_ARCH: x86_64 |
| 30 | + |
| 31 | + - ARCH: arm32v7 |
| 32 | + DOCKER_FILE: Dockerfile.bionic |
| 33 | + JDK: adoptopenjdk:11-jdk-hotspot-bionic |
| 34 | + QEMU_ARCH: arm |
| 35 | + |
| 36 | + - ARCH: arm64v8 |
| 37 | + DOCKER_FILE: Dockerfile.bionic |
| 38 | + JDK: adoptopenjdk:11-jre-hotspot-bionic |
| 39 | + QEMU_ARCH: aarch64 |
| 40 | + |
| 41 | + if: github.event_name == 'push' |
| 42 | + outputs: |
| 43 | + build_version: ${{ steps.prepare.outputs.build_version }} |
| 44 | + steps: |
| 45 | + - name: Pulling code |
| 46 | + uses: actions/checkout@v2 |
| 47 | + |
| 48 | + - name: Preparing |
| 49 | + id: prepare |
| 50 | + run: | |
| 51 | + echo "DOCKER BUILD: Build Docker image." |
| 52 | + echo "DOCKER BUILD: arch - ${{matrix.ARCH}}." |
| 53 | + echo "DOCKER BUILD: jdk -> ${{matrix.JDK}}." |
| 54 | + echo "DOCKER BUILD: build version -> ${VERSION}." |
| 55 | + echo "DOCKER BUILD: allure version -> ${ALLURE_RELEASE}." |
| 56 | + echo "DOCKER BUILD: qemu arch - ${{matrix.QEMU_ARCH}}." |
| 57 | + echo "DOCKER BUILD: docker file - ${{matrix.DOCKER_FILE}}." |
| 58 | +
|
| 59 | + VERSION=na |
| 60 | + TAGS="--tag ${DOCKER_IMAGE}:build" |
| 61 | +
|
| 62 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 63 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 64 | + if [[ $GITHUB_REF == *"beta"* ]]; then |
| 65 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:${VERSION}-${{matrix.ARCH}} --tag ${DOCKER_IMAGE}:beta --tag ${DOCKER_IMAGE}:build" |
| 66 | + else |
| 67 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:${VERSION}-${{matrix.ARCH}} --tag ${DOCKER_IMAGE}:latest --tag ${DOCKER_IMAGE}:build" |
| 68 | + fi |
| 69 | + fi |
| 70 | +
|
| 71 | + echo ::set-output name=docker_image::${DOCKER_IMAGE} |
| 72 | + echo ::set-output name=build_version::${VERSION} |
| 73 | + echo ::set-output name=docker_args::--build-arg ARCH=${{matrix.ARCH}} \ |
| 74 | + --build-arg JDK=${{matrix.JDK}} \ |
| 75 | + --build-arg QEMU_ARCH=${{matrix.QEMU_ARCH}} \ |
| 76 | + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ |
| 77 | + --build-arg BUILD_VERSION=${VERSION} \ |
| 78 | + --build-arg BUILD_REF=${GITHUB_SHA::8} \ |
| 79 | + --build-arg ALLURE_RELEASE=${ALLURE_RELEASE} \ |
| 80 | + ${TAGS} --file docker/Dockerfile.bionic . |
| 81 | +
|
| 82 | + - name: Setting up QEMU |
| 83 | + run: | |
| 84 | + # Prepare qemu to build non amd64 / x86_64 images |
| 85 | + docker run --rm --privileged multiarch/qemu-user-static:register --reset |
| 86 | + mkdir tmp |
| 87 | + pushd tmp && |
| 88 | + curl -L -o qemu-x86_64-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-x86_64-static.tar.gz && tar xzf qemu-x86_64-static.tar.gz && |
| 89 | + curl -L -o qemu-arm-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-arm-static.tar.gz && tar xzf qemu-arm-static.tar.gz && |
| 90 | + curl -L -o qemu-aarch64-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-aarch64-static.tar.gz && tar xzf qemu-aarch64-static.tar.gz && |
| 91 | + popd |
| 92 | +
|
| 93 | + - name: Docker Building |
| 94 | + run: | |
| 95 | + docker build --no-cache ${{ steps.prepare.outputs.docker_args }} |
| 96 | +
|
| 97 | + - name: Docker Testing |
| 98 | + run: | |
| 99 | + echo "DOCKER TEST: Test Docker image." |
| 100 | + echo "DOCKER TEST: testing image -> ${DOCKER_IMAGE}:build" |
| 101 | +
|
| 102 | + docker run -d --rm --name=testing ${DOCKER_IMAGE}:build |
| 103 | + if [ $? -ne 0 ]; then |
| 104 | + echo "DOCKER TEST: FAILED - Docker container testing failed to start." |
| 105 | + exit 1 |
| 106 | + else |
| 107 | + echo "DOCKER TEST: PASSED - Docker container testing succeeded to start." |
| 108 | + fi |
| 109 | +
|
| 110 | + - name: DockerHub Login |
| 111 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 112 | + env: |
| 113 | + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} |
| 114 | + DOCKER_HUB_PASS: ${{ secrets.DOCKER_HUB_PASS }} |
| 115 | + run: | |
| 116 | + echo "${DOCKER_HUB_PASS}" | docker login -u "${DOCKER_HUB_USER}" --password-stdin |
| 117 | +
|
| 118 | + - name: Docker Publishing |
| 119 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 120 | + run: | |
| 121 | + echo "DOCKER PUSH: pushing - ${DOCKER_IMAGE}:${{ steps.prepare.outputs.build_version }}-${{matrix.ARCH}}." |
| 122 | + docker push ${DOCKER_IMAGE}:${{ steps.prepare.outputs.build_version }}-${{matrix.ARCH}} |
| 123 | +
|
| 124 | + - name: Docker Logout |
| 125 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 126 | + run: | |
| 127 | + docker logout |
| 128 | +
|
| 129 | + manifest_release: |
| 130 | + runs-on: ubuntu-latest |
| 131 | + needs: build_release |
| 132 | + steps: |
| 133 | + - name: DockerHub Login |
| 134 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 135 | + env: |
| 136 | + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} |
| 137 | + DOCKER_HUB_PASS: ${{ secrets.DOCKER_HUB_PASS }} |
| 138 | + run: | |
| 139 | + echo "${DOCKER_HUB_PASS}" | docker login -u "${DOCKER_HUB_USER}" --password-stdin |
| 140 | +
|
| 141 | + - name: Docker Publishing Manifest |
| 142 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 143 | + run: | |
| 144 | + BUILD_VERSION=${{ needs.build_release.outputs.build_version }} |
| 145 | + docker manifest create ${DOCKER_IMAGE}:${BUILD_VERSION} \ |
| 146 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-amd64 \ |
| 147 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-arm32v7 \ |
| 148 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-arm64v8 |
| 149 | +
|
| 150 | + docker manifest annotate ${DOCKER_IMAGE}:${BUILD_VERSION} ${DOCKER_IMAGE}:${BUILD_VERSION}-arm32v7 --os=linux --arch=arm --variant=v7 |
| 151 | + docker manifest annotate ${DOCKER_IMAGE}:${BUILD_VERSION} ${DOCKER_IMAGE}:${BUILD_VERSION}-arm64v8 --os=linux --arch=arm64 --variant=v8 |
| 152 | +
|
| 153 | + docker manifest push ${DOCKER_IMAGE}:${BUILD_VERSION} |
| 154 | +
|
| 155 | + TAG=beta |
| 156 | + if [[ ${BUILD_VERSION} != *"beta"* ]]; then |
| 157 | + TAG=latest |
| 158 | + fi |
| 159 | +
|
| 160 | + docker manifest create ${DOCKER_IMAGE}:${TAG} \ |
| 161 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-amd64 \ |
| 162 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-arm32v7 \ |
| 163 | + ${DOCKER_IMAGE}:${BUILD_VERSION}-arm64v8 |
| 164 | +
|
| 165 | + docker manifest annotate ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGE}:${BUILD_VERSION}-arm32v7 --os=linux --arch=arm --variant=v7 |
| 166 | + docker manifest annotate ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGE}:${BUILD_VERSION}-arm64v8 --os=linux --arch=arm64 --variant=v8 |
| 167 | +
|
| 168 | + docker manifest push ${DOCKER_IMAGE}:${TAG} |
| 169 | +
|
| 170 | + - name: Docker Logout |
| 171 | + if: success() && startsWith(github.ref, 'refs/tags/v') |
| 172 | + run: | |
| 173 | + docker logout |
0 commit comments