Merge pull request #2 from Enflick/SRE-3594-set-token-expiration-env #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Allure Docker Service Workflow | |
on: | |
push: | |
branches: | |
- "*" | |
tags: | |
- v* | |
pull_request: | |
env: | |
DOCKER_IMAGE: frankescobar/allure-docker-service | |
ALLURE_RELEASE: 2.21.0 | |
QEMU_VERSION: v4.0.0 | |
DOCKER_CLI_EXPERIMENTAL: enabled | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build_release: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
outputs: | |
build_version: ${{ steps.prepare.outputs.build_version }} | |
steps: | |
- name: Pulling code | |
uses: actions/checkout@v2 | |
- name: Configure AWS | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: ${{ secrets.IAM_ROLE }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Preparing | |
id: prepare | |
env: | |
ARCH: amd64 | |
DOCKER_FILE: Dockerfile.bionic | |
JDK: adoptopenjdk:11-jre-openj9-bionic | |
QEMU_ARCH: x86_64 | |
run: | | |
echo "DOCKER BUILD: Build Docker image." | |
echo "DOCKER BUILD: arch - ${ARCH}." | |
echo "DOCKER BUILD: jdk -> ${JDK}." | |
echo "DOCKER BUILD: build version -> ${VERSION}." | |
echo "DOCKER BUILD: allure version -> ${ALLURE_RELEASE}." | |
echo "DOCKER BUILD: qemu arch - ${QEMU_ARCH}." | |
echo "DOCKER BUILD: docker file - ${DOCKER_FILE}." | |
VERSION=na | |
TAGS="--tag ${DOCKER_IMAGE}:build" | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
if [[ $GITHUB_REF == *"beta"* ]]; then | |
TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:${VERSION}-${ARCH} --tag ${DOCKER_IMAGE}:beta --tag ${DOCKER_IMAGE}:build" | |
else | |
TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:${VERSION}-${ARCH} --tag ${DOCKER_IMAGE}:latest --tag ${DOCKER_IMAGE}:build" | |
fi | |
fi | |
echo ::set-output name=docker_image::${DOCKER_IMAGE} | |
echo ::set-output name=build_version::${VERSION} | |
echo ::set-output name=docker_args::--build-arg ARCH=${ARCH} \ | |
--build-arg JDK=${JDK} \ | |
--build-arg QEMU_ARCH=${QEMU_ARCH} \ | |
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | |
--build-arg BUILD_VERSION=${VERSION} \ | |
--build-arg BUILD_REF=${GITHUB_SHA::8} \ | |
--build-arg ALLURE_RELEASE=${ALLURE_RELEASE} \ | |
${TAGS} --file docker/${DOCKER_FILE} . | |
- name: Setting up QEMU | |
run: | | |
# Prepare qemu to build non amd64 / x86_64 images | |
docker run --rm --privileged multiarch/qemu-user-static:register --reset | |
mkdir tmp | |
pushd tmp && | |
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 && | |
popd | |
- name: Docker Building | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: ${{ github.sha }} | |
REPO_PATH: allure-docker-service | |
run: | | |
docker build --no-cache -t $ECR_REGISTRY/$REPO_PATH:$IMAGE_TAG -t $ECR_REGISTRY/$REPO_PATH:latest ${{ steps.prepare.outputs.docker_args }} | |
- name: Docker Testing | |
run: | | |
echo "DOCKER TEST: Test Docker image." | |
echo "DOCKER TEST: testing image -> ${DOCKER_IMAGE}:build" | |
docker run -d --rm --name=testing ${DOCKER_IMAGE}:build | |
if [ $? -ne 0 ]; then | |
echo "DOCKER TEST: FAILED - Docker container testing failed to start." | |
exit 1 | |
else | |
echo "DOCKER TEST: PASSED - Docker container testing succeeded to start." | |
fi | |
- name: Docker Publishing | |
if: success() | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPO_PATH: allure-docker-service | |
run: | | |
echo "DOCKER PUSH: pushing - $ECR_REGISTRY/$REPO_PATH:latest" | |
docker push $ECR_REGISTRY/$REPO_PATH:latest |