-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
150 lines (132 loc) · 4.8 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
trigger:
branches:
include:
- main
paths:
exclude:
- README.md
pr: none
variables:
buildConfiguration: "Release"
webRepository: "capstonefinal"
tag: "$(Build.BuildId)"
stages:
- stage: "Test"
displayName: "Testing"
jobs:
- job: "Test"
displayName: "Generic_Tests"
pool:
vmImage: "ubuntu-latest"
steps:
- task: CmdLine@2
displayName: hadolint
inputs:
script: "cat $(Build.SourcesDirectory)/Dockerfile | docker run --rm -i -v $(Build.SourcesDirectory)/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint > $(Build.ArtifactStagingDirectory)/output.txt && cat $(Build.SourcesDirectory)/Dockerfile | docker run --rm -i -v $(Build.SourcesDirectory)/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint"
workingDirectory: "$(Build.SourcesDirectory)"
continueOnError: true
- task: WhiteSource@21
inputs:
projectName: "CapstoneFinal"
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Build.ArtifactStagingDirectory)
artifactName: hadolintOutput
- job: "Python_Tests"
displayName: "Test Python"
pool:
vmImage: "ubuntu-latest"
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.6"
- script: |
pip install --upgrade bandit flake8
displayName: "Install Python Dependencies"
- script: |
flake8 . | tee $(Build.ArtifactStagingDirectory)/flake8output.txt
displayName: "Run Flake8 Test"
continueOnError: true
- script: |
bandit -r $(Build.SourcesDirectory)/app.py -f json | tee $(Build.ArtifactStagingDirectory)/bandit-output.json
displayName: "Bandit Test"
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Build.ArtifactStagingDirectory)
artifactName: pythonoutput
- job: "DAST"
displayName: "Test DAST"
pool:
vmImage: "ubuntu-latest"
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.6"
- script: |
docker build -f $(Build.SourcesDirectory)/Dockerfile -t thylaw/testcontainer:$(tag) .
docker run --name flasktest --rm -d -p 5000:5000 thylaw/testcontainer:$(tag)
displayName: Build&Run Container
- script: |
git clone https://github.com/sullo/nikto
cd nikto/program
./nikto.pl -h http://localhost:5000 -o $(Build.ArtifactStagingDirectory)/nikto.json
continueOnError: true
displayName: 'Nikto Scan'
- script: |
sudo apt-get install libcurl4-openssl-dev
displayName: "Install Linux Packages"
- script: |
pip install --upgrade pycurl pytest pytest-azurepipelines
displayName: "Install Python Dependencies"
- script: |
python -m pytest test_curl.py
displayName: "pytest"
continueOnError: true
- task: CmdLine@2
displayName: Get Curl Data
inputs:
script: "curl http://localhost:5000 > $(Build.ArtifactStagingDirectory)/curl.txt && curl http://localhost:5000 "
workingDirectory: "$(Build.SourcesDirectory)"
continueOnError: true
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Build.ArtifactStagingDirectory)
artifactName: DAST Output
- stage: "Build"
displayName: "Build and push"
dependsOn: Test
jobs:
- job: "Build"
displayName: "Build job"
pool:
vmImage: "ubuntu-20.04"
steps:
- task: Docker@2
displayName: "Build and push the image to container registry"
inputs:
command: buildAndPush
buildContext: $(Build.Repository.LocalPath)
repository: thylaw/$(webRepository)
dockerfile: "$(Build.SourcesDirectory)/Dockerfile"
containerRegistry: "DockerHub Registry Connection"
tags: |
$(tag)
- stage: "Deploy"
jobs:
- deployment: "Pull_Container"
displayName: "Deploy_to_Staging"
pool:
vmImage: "ubuntu-20.04"
variables:
- group: Release
environment: "Staging"
strategy:
runOnce:
deploy:
steps:
- download: none
- task: AzureWebAppContainer@1
inputs:
appName: $(WebAppNameStaging)
azureSubscription: "Resource Manager Capstone Final"
imageName: docker.io/thylaw/capstonefinal:$(build.buildId)