This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpipeline.sh
executable file
·91 lines (71 loc) · 2.03 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
#!/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='blaster'
readonly BUILD_NUMBER=${1:-"N/A"}
readonly BUILD_SOURCES_DIRECTORY=${2:-${PWD}}
clean_output_folder() {
rm -Rf output
mkdir output
}
restore_dependencies() {
echo "Restoring dependencies"
npm install
dotnet restore ../Blaster.sln
}
build_projects() {
echo "Building projects..."
NODE_ENV=production npm run build
dotnet build -c Release ../Blaster.sln
}
run_tests() {
echo "Running tests..."
MSYS_NO_PATHCONV=1 dotnet test \
-c Release \
--no-build \
--logger:"trx;LogFileName=testresults.trx" \
Blaster.Tests/Blaster.Tests.csproj \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=cobertura \
'/p:Include="[Blaster.WebApi]*"'
mv ./Blaster.Tests/coverage.cobertura.xml "${BUILD_SOURCES_DIRECTORY}/output/"
mv ./Blaster.Tests/TestResults/testresults.trx "${BUILD_SOURCES_DIRECTORY}/output/"
}
publish_binaries() {
echo "Publishing binaries..."
dotnet publish \
--no-build \
-c Release \
-o ${BUILD_SOURCES_DIRECTORY}/output/app \
Blaster.WebApi/Blaster.WebApi.csproj
}
build_container_image() {
echo "Building container image..."
docker build -t ${IMAGE_NAME} -f ./src/Blaster.WebApi/Dockerfile .
}
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}
}
clean_output_folder
cd ./src
restore_dependencies
build_projects
run_tests
publish_binaries
cd ..
build_container_image
if [[ "${BUILD_NUMBER}" != "N/A" ]]; then
push_container_image
fi