Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dotnet package pipeline #139

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions scripts/pipelines/azure-devops/templates/package/dotnet-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
################################ Description ############################################
# This script is used to build and push an image to a container registry
################################# Arguments #############################################
# -f : Path to the dockerfile
# -c : The context of the build (in our case, the repository cloned and the build application are not in the same directory, we need to execute the docker build knowing that)
# -u : Username to connect to the registry
# -p : Password to connect to the registry
# -r : Registry used to store the image
# -i : Name of the image (containing the name of the registry and the path to the image)
# -b : Name of the branch from where the version is coming
# -t : Path to the docker-file
#########################################################################################
set -e

while getopts f:c:u:p:r:i:b:t:a:s:l: flag
do
case "${flag}" in
f) dockerFile=${OPTARG};;
c) context=${OPTARG};;
u) username=${OPTARG};;
p) password=${OPTARG};;
r) registry=${OPTARG};;
i) imageName=${OPTARG};;
b) branch=${OPTARG};;
t) projectFile=${OPTARG};;
a) aws_access_key=${OPTARG};;
s) aws_secret_access_key=${OPTARG};;
l) region=${OPTARG};;
*) echo "Error: Unexpected flag." >&2
exit 1 ;;
esac
done

# We define the tag using the version set in the cs.proj
# So far the project-file is only used, to query for the version
version=$(echo 'cat //Project/ItemGroup/PackageReference[@Include="Devon4Net.Infrastructure.Common"]/@Version' | xmllint --shell $projectFile | awk -F'[="]' '!/>/{print $(NF-1)}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2086: Double quote to prevent globbing and word splitting.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]


echo "Publishing version ${version}"

# We get what is located after the last '/' in the branch name, so it removes /ref/head or /ref/head/<folder> if your branche is named correctly"
branch_short=$(echo "$branch" | awk -F '/' '{ print $NF }')

# We change the name of the tag depending if it is a release or another branch
echo "$branch" | grep release && tag_completed="${tag}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2154: tag is referenced but not assigned.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

echo "$branch" | grep release || tag_completed="${tag}_${branch_short}"

# We build the image
echo "docker build -f $dockerFile -t $imageName:$tag_completed $context"
docker build -f "$dockerFile" -t "$imageName:$tag_completed" "$context"

# We connect to the registry
if test -z "$aws_access_key"
then
echo "docker login -u=**** -p=**** $registry"
docker login -u="$username" -p="$password" "$registry"
else
aws configure set aws_access_key_id "$aws_access_key"
aws configure set aws_secret_access_key "$aws_secret_access_key"
echo "aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $registry"
aws ecr get-login-password --region "$region" | docker login --username AWS --password-stdin "$registry"
fi

# We push the image previously built
echo "docker push $imageName:$tag_completed"
docker push "$imageName:$tag_completed"

# If this is a release we push it a second time with "latest" tag
if echo "$branch" | grep release
then
echo "Also pushing the image as 'latest' if this is a release"
docker tag "$imageName:$tag_completed" "$imageName:latest"
echo "docker push $imageName:latest"
docker push "$imageName":latest
fi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ scriptFilePath=".pipelines/scripts"
# Source branch.
sourceBranch="feature/package-pipeline"
#Dockerfile Paths depending on the langage
dockerfilePaths="quarkus:src/main/docker/Dockerfile.jvm quarkus-native:src/main/docker/Dockerfile.native"
dockerfilePaths="quarkus:src/main/docker/Dockerfile.jvm quarkus-native:src/main/docker/Dockerfile.native dotnet:/source/Templates/WebAPI/Devon4Net.Application.WebAPI/Dockerfile"

function copyScript {

Expand Down