diff --git a/pipelines/azure-build.yaml b/pipelines/azure-build.yaml index 8bf05fd..2713bed 100644 --- a/pipelines/azure-build.yaml +++ b/pipelines/azure-build.yaml @@ -1,5 +1,25 @@ name: build +variables: + - group: unittest-samples + - name: self_location + value: "self_location" + - name: full_self_location + value: "$(Agent.BuildDirectory)/$(self_location)" + - name: samples_location + value: "samples_location" + - name: full_samples_location + value: "$(Agent.BuildDirectory)/$(samples_location)" + +resources: + repositories: + - repository: unittest-samples + type: github + name: $(unittest_samples_repository) + ref: main + endpoint: github-repo-sa + trigger: none + trigger: tags: include: ["v*"] @@ -21,10 +41,39 @@ stages: inputs: command: login containerRegistry: dockerhub + - task: Docker@2 + displayName: Login to chimera + inputs: + command: login + containerRegistry: CHIMERA-U-ACR + - checkout: self + fetchDepth: 1 + path: $(self_location) + - checkout: unittest-samples + fetchDepth: 1 + path: $(samples_location) + - script: | + export TAG=${BUILD_SOURCEBRANCH#"refs/tags/v"} + if [[ "$TAG" == *stable* ]]; then export BUILD_TYPE=stable; else export BUILD_TYPE=latest; fi + docker build --build-arg version=$TAG --build-arg branch=$BUILD_TYPE -t cccs/${BUILD_REPOSITORY_NAME##*/}:$TAG -t cccs/${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE -f ./Dockerfile . + workingDirectory: $(full_self_location) + displayName: Build containers + - script: | + [ ! -d "$(pwd)/tests" ] && echo "No tests found" && exit + export TAG=${BUILD_SOURCEBRANCH#"refs/tags/v"} + if [[ "$TAG" == *stable* ]]; then export BUILD_TYPE=stable; else export BUILD_TYPE=latest; fi + [ -f "$(pwd)/tests/requirements.txt" ] && docker run -e FULL_SELF_LOCATION=/opt/al_service -e FULL_SAMPLES_LOCATION=/opt/samples -v /usr/share/ca-certificates/mozilla:/usr/share/ca-certificates/mozilla -v $(pwd)/tests/:/opt/al_service/tests/ -v ${FULL_SAMPLES_LOCATION}:/opt/samples cccs/${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE bash -c 'pip install -U -r tests/requirements.txt; pytest -p no:cacheprovider -vv' && exit + docker run -e FULL_SELF_LOCATION=/opt/al_service -e FULL_SAMPLES_LOCATION=/opt/samples -v /usr/share/ca-certificates/mozilla:/usr/share/ca-certificates/mozilla -v $(pwd)/tests/:/opt/al_service/tests/ -v ${FULL_SAMPLES_LOCATION}:/opt/samples cccs/${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE bash -c 'pytest -p no:cacheprovider -vv' + workingDirectory: $(full_self_location) + displayName: Test containers - script: | - set -xv # Echo commands before they are run export TAG=${BUILD_SOURCEBRANCH#"refs/tags/v"} if [[ "$TAG" == *stable* ]]; then export BUILD_TYPE=stable; else export BUILD_TYPE=latest; fi - docker build --build-arg version=$TAG --build-arg branch=$BUILD_TYPE -t cccs/assemblyline-service-iparse:$TAG -t cccs/assemblyline-service-iparse:$BUILD_TYPE . - docker push cccs/assemblyline-service-iparse --all-tags - displayName: Deploy to Docker Hub + + for IMAGE in "cccs/" "uchimera.azurecr.io/cccs/" + do + docker tag cccs/${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE ${IMAGE}${BUILD_REPOSITORY_NAME##*/}:$TAG + docker tag cccs/${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE ${IMAGE}${BUILD_REPOSITORY_NAME##*/}:$BUILD_TYPE + docker push ${IMAGE}${BUILD_REPOSITORY_NAME##*/} --all-tags + done + displayName: Deploy to container repositories