-
Notifications
You must be signed in to change notification settings - Fork 3
/
pipeline.sh
executable file
·96 lines (72 loc) · 2.46 KB
/
pipeline.sh
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
#!/bin/bash
#
# build.sh(1)
#
[[ -n $DEBUG ]] && set -x
set -eu -o pipefail
# build parameters
readonly REGION=${AWS_DEFAULT_REGION:-"eu-central-1"}
readonly IMAGE_NAME='k8s-janitor'
readonly BUILD_NUMBER=${1:-"N/A"}
readonly BUILD_SOURCES_DIRECTORY=${2:-${PWD}}
readonly SERVICE_NAME="K8sJanitor"
clean_output_folder() {
rm -Rf output
mkdir output
}
restore_dependencies() {
echo "Restoring dependencies"
dotnet restore ${SERVICE_NAME}.sln
}
run_tests() {
echo "Running tests..."
dotnet build -c Release ${SERVICE_NAME}.sln
# dotnet test --logger:"trx;LogFileName=testresults.trx" --results-directory ${BUILD_SOURCES_DIRECTORY}/output ${SERVICE_NAME}.WebApi.Tests/${SERVICE_NAME}.WebApi.Tests.csproj
MSYS_NO_PATHCONV=1 dotnet test \
--logger:"trx;LogFileName=testresults.trx" \
K8sJanitor.WebApi.Tests/K8sJanitor.WebApi.Tests.csproj \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=cobertura \
'/p:Include="[K8sJanitor.WebApi]*"'
echo "Exit code: $?"
mv ./K8sJanitor.WebApi.Tests/coverage.cobertura.xml "${BUILD_SOURCES_DIRECTORY}/output/"
mv ./K8sJanitor.WebApi.Tests/TestResults/testresults.trx "${BUILD_SOURCES_DIRECTORY}/output/"
}
publish_binaries() {
echo "Publishing binaries..."
dotnet publish -c Release -o ${BUILD_SOURCES_DIRECTORY}/output/app K8sJanitor.WebApi/K8sJanitor.WebApi.csproj
}
build_container_image() {
echo "Building container image..."
docker build -t ${IMAGE_NAME} .
}
push_container_image() {
echo "Login to docker..."
$(aws ecr get-login --no-include-email)
account_id=$(aws sts get-caller-identity --output text --query 'Account')
image_name="${account_id}.dkr.ecr.${REGION}.amazonaws.com/ded/${IMAGE_NAME}:${BUILD_NUMBER}"
echo "Tagging container image..."
docker tag ${IMAGE_NAME}:latest ${image_name}
echo "Pushing container image to ECR..."
docker push ${image_name}
}
push_container_image_dockercloud() {
echo "Login to docker..."
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
image_name="dfdsdk/rolemapper-service:${BUILD_NUMBER}"
echo "Tagging container image..."
docker tag ${IMAGE_NAME}:latest ${image_name}
echo "Pushing container image to ECR..."
docker push ${image_name}
}
clean_output_folder
cd ./src
restore_dependencies
run_tests
publish_binaries
cd ..
build_container_image
if [[ "${BUILD_NUMBER}" != "N/A" ]]; then
push_container_image
push_container_image_dockercloud
fi