Debian package and publish changes

- Use parameters instead of env vars to create debian packages.
- Target to publish the deb package to the debian repo.
This commit is contained in:
Sridhar Periyasamy 2016-03-08 23:33:18 +00:00
parent ae041c8f61
commit 015bda2137
6 changed files with 134 additions and 276 deletions

View file

@ -40,9 +40,14 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult GenerateDeb(BuildTargetContext c)
{
var env = PackageTargets.GetCommonEnvVars(c);
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"))
.Environment(env)
var channel = c.BuildContext.Get<string>("Channel").ToLower();
var packageName = Monikers.GetDebianPackageName(c);
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var debFile = c.BuildContext.Get<string>("InstallerFile");
var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages");
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
"-v", version, "-i", Dirs.Stage2, "-o", debFile, "-p", packageName, "-m", manPagesDir, "-c", channel)
.Execute()
.EnsureSuccessful();
return c.Success();

View file

@ -102,6 +102,44 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
[Target(nameof(PublishInstallerFile))]
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult PublishDebFileToDebianRepo(BuildTargetContext c)
{
var packageName = Monikers.GetDebianPackageName(c);
var installerFile = c.BuildContext.Get<string>("InstallerFile");
var uploadUrl = $"https://dotnetcli.blob.core.windows.net/dotnet/{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
var uploadJson = GenerateUploadJsonFile(packageName, Version, uploadUrl);
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "publish", "repoapi_client.sh"), "-addpkg", uploadJson)
.Execute()
.EnsureSuccessful();
return c.Success();
}
private static string GenerateUploadJsonFile(string packageName, string version, string uploadUrl)
{
var repoID = Environment.GetEnvironmentVariable("REPO_ID");
var uploadJson = Path.Combine(Dirs.Packages, "package_upload.json");
File.Delete(uploadJson);
using (var fileStream = File.Create(uploadJson))
{
using (StreamWriter sw = new StreamWriter(fileStream))
{
sw.WriteLine("{");
sw.WriteLine($" \"name\":\"{packageName}\",");
sw.WriteLine($" \"version\":\"{version}\",");
sw.WriteLine($" \"repositoryId\":\"{repoID}\",");
sw.WriteLine($" \"sourceUrl\":\"{uploadUrl}\"");
sw.WriteLine("}");
}
}
return uploadJson;
}
private static BuildTargetResult PublishFile(BuildTargetContext c, string file)
{
var env = PackageTargets.GetCommonEnvVars(c);

View file

@ -16,6 +16,29 @@ namespace Microsoft.DotNet.Cli.Build
return $"dotnet-{osname}-{arch}.{version}";
}
public static string GetDebianPackageName(BuildTargetContext c)
{
var channel = c.BuildContext.Get<string>("Channel").ToLower();
var packageName = "";
switch (channel)
{
case "dev":
packageName = "dotnet-nightly";
break;
case "beta":
case "rc1":
case "rc2":
case "rtm":
packageName = "dotnet";
break;
default:
throw new Exception($"Unknown channel - {channel}");
break;
}
return packageName;
}
public static string GetOSShortName()
{
string osname = "";

View file

@ -17,46 +17,73 @@ done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "$DIR/../common/_common.sh"
REPOROOT="$DIR/../.."
if [ "$OSNAME" != "ubuntu" ]; then
error "Debian Package build only supported on Ubuntu"
help(){
echo "Usage: $0"
echo ""
echo "Options:"
echo " --version <version> Specify a version for the package."
echo " --input <input directory> Package the entire contents of the directory tree."
echo " --manpages <man pages directory> Directory containing man pages for the package."
echo " --output <output debfile> The full path to which the package will be written."
echo " --package-name <package name> Package to identify during installation. Example - 'dotnet-nightly', 'dotnet'"
echo " --channel <channel> Channel against which to run the upgrade tests. Example - 'dev', 'beta'"
exit 1
fi
}
while [[ $# > 0 ]]; do
lowerI="$(echo $1 | awk '{print tolower($0)}')"
echo "$lowerI"
case $lowerI in
-m|--manpages)
MANPAGE_DIR=$2
shift
;;
-o|--output)
OUTPUT_DEBIAN_FILE=$2
shift
;;
-i|--input)
REPO_BINARIES_DIR=$2
shift
;;
-p|--package-name)
DOTNET_DEB_PACKAGE_NAME=$2
shift
;;
-v|--version)
DOTNET_CLI_VERSION=$2
shift
;;
-c|--channel)
CHANNEL=$2
shift
;;
--help)
help
;;
*)
echo $lowerI
break
;;
esac
shift
done
PACKAGING_ROOT="$REPOROOT/packaging/debian"
PACKAGING_TOOL_DIR="$REPOROOT/tools/DebianPackageTool"
OUTPUT_DIR="$REPOROOT/artifacts"
PACKAGE_LAYOUT_DIR="$OUTPUT_DIR/deb_intermediate"
PACKAGE_OUTPUT_DIR="$OUTPUT_DIR/packages/debian"
TEST_STAGE_DIR="$PACKAGE_OUTPUT_DIR/test"
REPO_BINARIES_DIR="$REPOROOT/artifacts/ubuntu.14.04-x64/stage2"
MANPAGE_DIR="$REPOROOT/Documentation/manpages"
NIGHTLY_PACKAGE_NAME="dotnet-nightly"
RELEASE_PACKAGE_NAME="dotnet"
[ -z "$CHANNEL" ] && CHANNEL="dev"
PACKAGE_OUTPUT_DIR=$(dirname "${OUTPUT_DEBIAN_FILE}")
PACKAGE_LAYOUT_DIR="$PACKAGE_OUTPUT_DIR/deb_intermediate"
TEST_STAGE_DIR="$PACKAGE_OUTPUT_DIR/debian_tests"
execute_build(){
determine_package_name
create_empty_debian_layout
copy_files_to_debian_layout
create_debian_package
}
determine_package_name(){
if [[ "$RELEASE_SUFFIX" == "dev" ]]; then
DOTNET_DEB_PACKAGE_NAME=$NIGHTLY_PACKAGE_NAME
elif [[ "beta rc1 rc2 rtm" =~ (^| )"$RELEASE_SUFFIX"($| ) ]]; then
DOTNET_DEB_PACKAGE_NAME=$RELEASE_PACKAGE_NAME
elif [[ "$RELEASE_SUFFIX" == "" ]]; then
DOTNET_DEB_PACKAGE_NAME=$RELEASE_PACKAGE_NAME
else
DOTNET_DEB_PACKAGE_NAME=$NIGHTLY_PACKAGE_NAME
fi
}
execute_test(){
test_debian_package
}
@ -138,6 +165,8 @@ run_e2e_test(){
execute_build
rm -f "$OUTPUT_DEBIAN_FILE"
DEBIAN_FILE=$(find $PACKAGE_OUTPUT_DIR -iname "*.deb")
mv -f "$DEBIAN_FILE" "$OUTPUT_DEBIAN_FILE"
execute_test

View file

@ -1,246 +0,0 @@
#!/bin/bash
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
# Usage: publish.sh [file to be uploaded]
#
# Environment Dependencies:
# $STORAGE_CONTAINER
# $STORAGE_ACCOUNT
# $SASTOKEN
# $REPO_ID
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "$DIR/../common/_common.sh"
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
UPLOAD_FILE=$1
UPLOAD_JSON_FILE="package_upload.json"
header "Publishing package"
execute(){
if ! validate_env_variables; then
# fail silently if the required variables are not available for publishing the file.
exit 0
fi
if [[ ! -f "$UPLOAD_FILE" ]]; then
error "\"$UPLOAD_FILE\" file does not exist"
exit 1
fi
if [[ $UPLOAD_FILE == *.deb || $UPLOAD_FILE == *.pkg ]]; then
upload_installers_to_blob_storage $UPLOAD_FILE
result=$?
elif [[ $UPLOAD_FILE == *.tar.gz ]]; then
upload_binaries_to_blob_storage $UPLOAD_FILE
result=$?
elif [[ $UPLOAD_FILE == *.svg ]]; then
upload_version_badge $UPLOAD_FILE
result=$?
fi
exit $result
}
validate_env_variables(){
local ret=0
if [[ -z "$DOTNET_CLI_VERSION" ]]; then
warning "DOTNET_CLI_VERSION environment variable not set"
ret=1
fi
if [[ -z "$SASTOKEN" ]]; then
warning "SASTOKEN environment variable not set"
ret=1
fi
if [[ -z "$STORAGE_ACCOUNT" ]]; then
warning "STORAGE_ACCOUNT environment variable not set"
ret=1
fi
if [[ -z "$STORAGE_CONTAINER" ]]; then
warning "STORAGE_CONTAINER environment variable not set"
ret=1
fi
if [[ -z "$CHANNEL" ]]; then
warning "CHANNEL environment variable not set"
ret=1
fi
if [[ -z "$CONNECTION_STRING" ]]; then
warning "CONNECTION_STRING environment variable not set"
ret=1
fi
return $ret
}
upload_file_to_blob_storage_azure_cli(){
local blob=$1
local file=$2
local preventCaching=${3:false}
header "Uploading $file to blob storage"
local properties=""
if $preventCaching ; then
properties="--properties cacheControl=no-cache"
fi
# use azure cli to upload to blob storage. We cannot use curl to do this becuase azure has a max limit of 64mb that can be uploaded using REST
# statusCode=$(curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $upload_URL -T $file)
azure storage blob upload --quiet $properties --container $STORAGE_CONTAINER --blob $blob --blobtype block --connection-string "$CONNECTION_STRING" --file $file
result=$?
if [ "$result" -eq "0" ]; then
info "successfully uploaded $filename to blob storage."
return 0
else
error "uploading the $filename to blob storage - $statusCode"
return 1
fi
}
update_file_in_blob_storage(){
local update_URL=$1
local file=$2
local filecontent=$3
header "Updating $file in blob storage"
statusCode=$(curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" -H "Content-Type: text/plain" $update_URL --data-binary $filecontent --request PUT )
if [ "$statusCode" -eq "201" ]; then
info "successfully updated $file in blob storage."
return 0
else
error "updating the $file in blob storage - $statusCode"
return 1
fi
}
upload_binaries_to_blob_storage(){
local tarfile=$1
local filename=$(basename $tarfile)
local blob="$CHANNEL/Binaries/$DOTNET_CLI_VERSION/$filename"
if ! upload_file_to_blob_storage_azure_cli $blob $tarfile; then
return 1
fi
# create the latest blob
echo "Updating the latest dotnet binaries.."
local latestblob="$CHANNEL/Binaries/Latest/dotnet-$OSNAME-x64.latest.tar.gz"
if ! upload_file_to_blob_storage_azure_cli $latestblob $tarfile true; then
return 1
fi
# update the index file
local indexContent="Binaries/$DOTNET_CLI_VERSION/$filename"
local indexfile="latest.$OSNAME.index"
local index_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/dnvm/$indexfile$SASTOKEN"
update_file_in_blob_storage $index_URL $indexfile $indexContent true
# update the version file
# the "@" prefix tells curl to upload the content of the file
local versionContent="@$REPOROOT/artifacts/$RID/stage2/.version"
local versionfile="latest.$OSNAME.version"
local version_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/dnvm/$versionfile$SASTOKEN"
update_file_in_blob_storage $version_URL $versionfile $versionContent true
return $?
}
upload_installers_to_blob_storage(){
local installfile=$1
local filename=$(basename $installfile)
local blob="$CHANNEL/Installers/$DOTNET_CLI_VERSION/$filename"
if ! upload_file_to_blob_storage_azure_cli $blob $installfile; then
return 1
fi
# create the latest blob
echo "Updating the latest dotnet installer.."
local extension="${filename##*.}"
local latestblob="$CHANNEL/Installers/Latest/dotnet-$OSNAME-x64.latest.$extension"
if ! upload_file_to_blob_storage_azure_cli $latestblob $installfile true; then
return 1
fi
# debain packages need to be uploaded to the PPA feed too
if [[ $installfile == *.deb ]]; then
DEB_FILE=$installfile
UPLOAD_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$blob"
generate_repoclient_json
call_repo_client
fi
return 0
}
upload_version_badge(){
local badgefile=$1
local filename="${OSNAME}_${CONFIGURATION}_$(basename $badgefile)"
echo "Uploading the version badge to Latest"
upload_file_to_blob_storage_azure_cli "$CHANNEL/Binaries/Latest/$filename" $badgefile true
echo "Uploading the version badge to $DOTNET_CLI_VERSION"
upload_file_to_blob_storage_azure_cli "$CHANNEL/Binaries/$DOTNET_CLI_VERSION/$filename" $badgefile
return 0
}
generate_repoclient_json(){
# Clean any existing json file
rm -f $SCRIPT_DIR/$UPLOAD_JSON_FILE
echo "{" >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
echo " \"name\":\"$(_get_package_name)\"," >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
echo " \"version\":\"$(_get_package_version)\"," >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
echo " \"repositoryId\":\"$REPO_ID\"," >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
echo " \"sourceUrl\":\"$UPLOAD_URL\"" >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
echo "}" >> "$SCRIPT_DIR/$UPLOAD_JSON_FILE"
}
call_repo_client(){
$SCRIPT_DIR/repoapi_client.sh -addpkg $SCRIPT_DIR/$UPLOAD_JSON_FILE
}
# Extract the package name from the .deb filename
_get_package_name(){
local deb_filename=$(basename $DEB_FILE)
local package_name=${deb_filename%%_*}
echo $package_name
}
# Extract the package version from the .deb filename
_get_package_version(){
local deb_filename=$(basename $DEB_FILE)
local package_version=${deb_filename#*_}
package_version=${package_version%-*}
echo $package_version
}
execute

View file

@ -47,6 +47,14 @@ download_and_install_last_version(){
install_last_version
}
delete_last_version(){
rm -f "$DIR/last_version.deb"
}
cleanup(){
delete_last_version
}
@test "package install + removal test" {
install_package
remove_package
@ -68,5 +76,6 @@ download_and_install_last_version(){
remove_package
install_package
purge_package
cleanup
fi
}