Skip to content

Commit

Permalink
Merge pull request #4 from CybercentreCanada/use-pipeline-template
Browse files Browse the repository at this point in the history
(DEV) change pipeline to use template
  • Loading branch information
cccs-shellyw authored Sep 19, 2024
2 parents f6299ac + 75f7e51 commit eefb06e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 66 deletions.
21 changes: 21 additions & 0 deletions pipelines/.cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"template": "[email protected]:CybercentreCanada/assemblyline-service-pipeline-generator.git",
"commit": "eb41868283c10b1a31746ebfd29b2c0e32c26025",
"checkout": null,
"context": {
"cookiecutter": {
"__directory_name": "pipelines",
"classification": "UNCLASSIFIED",
"is_public": true,
"test_in_container": true,
"test_versions": "default",
"timeout": "default",
"__setupscript": "setup.bash",
"_extensions": [
"local_extensions.extract_versions"
],
"_template": "[email protected]:CybercentreCanada/assemblyline-service-pipeline-generator.git"
}
},
"directory": null
}
1 change: 1 addition & 0 deletions pipelines/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setup.bash
87 changes: 22 additions & 65 deletions pipelines/azure-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ 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:
Expand All @@ -28,52 +11,26 @@ pr: none
pool:
vmImage: "ubuntu-20.04"

stages:
- stage: deploy
jobs:
- job: deploy
displayName: Deploy containers to dockerhub
variables:
- group: deployment-information
steps:
- task: Docker@2
displayName: Login to docker hub
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: |
export TAG=${BUILD_SOURCEBRANCH#"refs/tags/v"}
if [[ "$TAG" == *stable* ]]; then export BUILD_TYPE=stable; else export BUILD_TYPE=latest; fi
resources:
repositories:
- repository: PipelineTemplates
type: github
name: CybercentreCanada/assemblyline-pipeline-templates
ref: refs/heads/main
endpoint: github-repo-sa
trigger: none
- repository: unittest-samples
type: github
name: $(unittest_samples_repository)
ref: main
endpoint: github-repo-sa
trigger: none

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
extends:
template: stages/deploy-service.yaml@PipelineTemplates
parameters:
is_public: "true"
samples_repo: unittest-samples
labels:
classification: "UNCLASSIFIED"

32 changes: 32 additions & 0 deletions pipelines/azure-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: tests

variables:
- group: unittest-samples

trigger: ["*"]
pr: ["*"]

pool:
vmImage: "ubuntu-20.04"

resources:
repositories:
- repository: PipelineTemplates
type: github
name: CybercentreCanada/assemblyline-pipeline-templates
ref: refs/heads/main
endpoint: github-repo-sa
trigger: none
- repository: unittest-samples
type: github
name: $(unittest_samples_repository)
ref: main
endpoint: github-repo-sa
trigger: none

extends:
template: stages/test-service.yaml@PipelineTemplates
parameters:
samples_repo: unittest-samples
test_container: "true"

3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
pytest
pyonenote
1 change: 1 addition & 0 deletions tests/test_onenote.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_make_header_result(header, section_body_data):
[],
)
],
)
def test_make_file_result(files, extracted, supplementary):
"""Test _make_file_result on dummy data extracted by OnenoteDocument."""
Expand Down

0 comments on commit eefb06e

Please sign in to comment.