Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kichalla committed Oct 14, 2019
1 parent 9abf703 commit f024e89
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 39 deletions.
1 change: 1 addition & 0 deletions build/__variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare -r __REPO_DIR=$( cd $( dirname "$0" ) && cd .. && pwd )
# VSTS environment variables
declare -r BUILD_NUMBER="$BUILD_BUILDNUMBER"
declare -r BUILD_CONFIGURATION="${BUILDCONFIGURATION:-Debug}"
declare -r RELEASE_TAG_NAME="${RELEASE_TAG_NAME:-$BUILD_NUMBER}"

declare -r BUILD_IMAGES_BUILD_CONTEXT_DIR="$__REPO_DIR/"
declare -r BUILD_IMAGES_DOCKERFILE="$__REPO_DIR/images/build/Dockerfile"
Expand Down
8 changes: 5 additions & 3 deletions build/buildBuildImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fi
# Avoid causing cache invalidation with the following check
if [ "$EMBED_BUILDCONTEXT_IN_IMAGES" == "true" ]
then
ctxArgs="--build-arg GIT_COMMIT=$GIT_COMMIT --build-arg BUILD_NUMBER=$BUILD_NUMBER"
ctxArgs="--build-arg GIT_COMMIT=$GIT_COMMIT --build-arg BUILD_NUMBER=$BUILD_NUMBER --build-arg RELEASE_TAG_NAME=$RELEASE_TAG_NAME"
echo "Build context args: $ctxArgs"
fi

Expand Down Expand Up @@ -80,7 +80,9 @@ function buildDockerImage() {
--build-arg AGENTBUILD=$BUILD_SIGNED \
$BASE_TAG_BUILD_ARGS \
--build-arg AI_KEY=$APPLICATION_INSIGHTS_INSTRUMENTATION_KEY \
$ctxArgs -f "$dockerFileToBuild" .
$ctxArgs \
-f "$dockerFileToBuild" \
.

echo
echo Building a base image for tests...
Expand All @@ -92,7 +94,7 @@ function buildDockerImage() {
# Retag build image with build number tags
if [ "$AGENT_BUILD" == "true" ]
then
uniqueTag="$BUILD_DEFINITIONNAME.$BUILD_NUMBER"
uniqueTag="$BUILD_DEFINITIONNAME.$RELEASE_TAG_NAME"

echo
echo "Retagging image '$builtImageTag' with ACR related tags..."
Expand Down
8 changes: 6 additions & 2 deletions build/buildBuildpacksImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ else
echo "Building buildpack runner image..."
fi

labels="--label com.microsoft.oryx.git-commit=$GIT_COMMIT"
labels="$labels --label com.microsoft.oryx.build-number=$BUILD_NUMBER"
labels="$labels --label com.microsoft.oryx.release-tag-name=$RELEASE_TAG_NAME"

# Build an image that runs `pack`
echo "-> Building pack runner image: $ACR_PACK_IMAGE_REPO"
echo
cd "$BUILD_IMAGES_BUILD_CONTEXT_DIR"
docker build -f "$PACK_IMAGE_DOCKERFILE" $noCacheFlag \
--build-arg BUILD_NUMBER="$BUILD_NUMBER" \
$labels \
-t $ACR_PACK_IMAGE_REPO:latest \
.

if [ "$AGENT_BUILD" == "true" ]; then
BUILD_SUFFIX="$BUILD_DEFINITIONNAME.$BUILD_NUMBER"
BUILD_SUFFIX="$BUILD_DEFINITIONNAME.$RELEASE_TAG_NAME"

docker tag "$ACR_PACK_IMAGE_REPO:latest" "$ACR_PACK_IMAGE_REPO:$BUILD_SUFFIX"
echo "$ACR_PACK_IMAGE_REPO:$BUILD_SUFFIX" >> $ACR_BUILD_IMAGES_ARTIFACTS_FILE
Expand Down
25 changes: 18 additions & 7 deletions build/buildRunTimeImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ declare -r REPO_DIR=$( cd $( dirname "$0" ) && cd .. && pwd )
source $REPO_DIR/build/__variables.sh
source $REPO_DIR/build/__functions.sh


runtimeImagesSourceDir="$RUNTIME_IMAGES_SRC_DIR"
runtimeSubDir="$1"
if [ ! -z "$runtimeSubDir" ]
Expand All @@ -24,12 +23,16 @@ then
fi
fi

labels="--label com.microsoft.oryx.git-commit=$GIT_COMMIT --label com.microsoft.oryx.build-number=$BUILD_NUMBER"
labels="--label com.microsoft.oryx.git-commit=$GIT_COMMIT"
labels="$labels --label com.microsoft.oryx.build-number=$BUILD_NUMBER"
labels="$labels --label com.microsoft.oryx.release-tag-name=$RELEASE_TAG_NAME"

# Avoid causing cache invalidation with the following check
if [ "$EMBED_BUILDCONTEXT_IN_IMAGES" == "true" ]
then
args="--build-arg GIT_COMMIT=$GIT_COMMIT --build-arg BUILD_NUMBER=$BUILD_NUMBER"
args="--build-arg GIT_COMMIT=$GIT_COMMIT"
args="$args --build-arg BUILD_NUMBER=$BUILD_NUMBER"
args="$args --build-arg RELEASE_TAG_NAME=$RELEASE_TAG_NAME"
fi

execAllGenerateDockerfiles "$runtimeImagesSourceDir"
Expand All @@ -46,7 +49,11 @@ fi
# We don't retrieve this image from a repository but rather build locally to make sure we get
# the latest version of its own base image.

docker build --pull -f "$RUNTIME_BASE_IMAGE_DOCKERFILE_PATH" -t "$RUNTIME_BASE_IMAGE_NAME" $REPO_DIR
docker build \
--pull \
-f "$RUNTIME_BASE_IMAGE_DOCKERFILE_PATH" \
-t "$RUNTIME_BASE_IMAGE_NAME" \
$REPO_DIR

# Write the list of images that were built to artifacts folder
mkdir -p "$ARTIFACTS_DIR/images"
Expand All @@ -63,16 +70,20 @@ for dockerFile in $dockerFiles; do
cd $REPO_DIR

echo
docker build -f $dockerFile -t $localImageTagName \
docker build \
-f $dockerFile \
-t $localImageTagName \
--build-arg AI_KEY=$APPLICATION_INSIGHTS_INSTRUMENTATION_KEY \
$args $labels .
$args \
$labels \
.

echo "$localImageTagName" >> $ACR_RUNTIME_IMAGES_ARTIFACTS_FILE

# Retag image with build number (for images built in oryxlinux buildAgent)
if [ "$AGENT_BUILD" == "true" ]
then
uniqueTag="$BUILD_DEFINITIONNAME.$BUILD_NUMBER"
uniqueTag="$BUILD_DEFINITIONNAME.$RELEASE_TAG_NAME"
acrRuntimeImageTagNameRepo="$ACR_PUBLIC_PREFIX/$getTagName_result"

docker tag "$localImageTagName" "$acrRuntimeImageTagNameRepo:$uniqueTag"
Expand Down
4 changes: 4 additions & 0 deletions images/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ COPY src/startupscriptgenerator/src .

ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}

RUN ./build.sh dotnetcore /opt/startupcmdgen/dotnet
RUN ./build.sh node /opt/startupcmdgen/nodejs
Expand Down Expand Up @@ -285,5 +287,7 @@ RUN rm -rf /tmp/scripts

ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
LABEL com.microsoft.oryx.git-commit=${GIT_COMMIT}
LABEL com.microsoft.oryx.build-number=${BUILD_NUMBER}
LABEL com.microsoft.oryx.release-tag-name=${RELEASE_TAG_NAME}
5 changes: 5 additions & 0 deletions images/build/slim.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ WORKDIR /usr/oryx/src
ARG GIT_COMMIT=unspecified
ARG AGENTBUILD=${AGENTBUILD}
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ARG AGENTBUILD=${AGENTBUILD}
RUN if [ -z "$AGENTBUILD" ]; then \
dotnet publish -r linux-x64 -o /opt/buildscriptgen/ -c Release BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj; \
fi
Expand Down Expand Up @@ -245,7 +248,9 @@ ENV ORYX_AI_INSTRUMENTATION_KEY=${AI_KEY}

ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
LABEL com.microsoft.oryx.git-commit=${GIT_COMMIT}
LABEL com.microsoft.oryx.build-number=${BUILD_NUMBER}
LABEL com.microsoft.oryx.release-tag-name=${RELEASE_TAG_NAME}

ENTRYPOINT [ "benv" ]
2 changes: 2 additions & 0 deletions images/runtime/dotnetcore/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
RUN ./build.sh dotnetcore /opt/startupcmdgen/startupcmdgen
Expand Down
2 changes: 2 additions & 0 deletions images/runtime/dotnetcore/DockerfileWithCurlUpdate.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
RUN ./build.sh dotnetcore /opt/startupcmdgen/startupcmdgen
Expand Down
2 changes: 2 additions & 0 deletions images/runtime/node/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
RUN ./build.sh node /opt/startupcmdgen/startupcmdgen
Expand Down
2 changes: 2 additions & 0 deletions images/runtime/php/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
RUN ./build.sh php /opt/startupcmdgen/startupcmdgen
Expand Down
2 changes: 2 additions & 0 deletions images/runtime/python/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}
ENV GIT_COMMIT=${GIT_COMMIT}
ENV BUILD_NUMBER=${BUILD_NUMBER}
RUN ./build.sh python /opt/startupcmdgen/startupcmdgen
Expand Down
3 changes: 2 additions & 1 deletion src/BuildScriptGeneratorCli/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ internal int Execute(
var buildEventProps = new Dictionary<string, string>()
{
{ "oryxVersion", Program.GetVersion() },
{ "oryxCommitId", Program.GetCommit() },
{ "oryxCommitId", Program.GetMetadataValue("GitCommit") },
{ "oryxReleaseTagName", Program.GetMetadataValue("RELEASE_TAG_NAME") },
{
"oryxCommandLine",
string.Join(
Expand Down
5 changes: 3 additions & 2 deletions src/BuildScriptGeneratorCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ internal int OnExecute(CommandLineApplication app, IConsole console)
if (Version)
{
var version = GetVersion();
var commit = GetCommit();
console.WriteLine($"Version: {version}, Commit: {commit}");
var commit = GetMetadataValue("GitCommit");
var releaseTagName = GetMetadataValue("RELEASE_TAG_NAME");
console.WriteLine($"Version: {version}, Commit: {commit}, ReleaseTagName: {releaseTagName}");

return ProcessConstants.ExitSuccess;
}
Expand Down
4 changes: 4 additions & 0 deletions src/CommonFiles/AssemblyVersion.proj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
<_Parameter1>GitCommit</_Parameter1>
<_Parameter2>$(GIT_COMMIT)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(RELEASE_TAG_NAME)' != ''">
<_Parameter1>RELEASE_TAG_NAME</_Parameter1>
<_Parameter2>$(RELEASE_TAG_NAME)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/startupscriptgenerator/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ echo
echo "Building package..."
cd "$PLATFORM_DIR"
go build \
-ldflags "-X common.BuildNumber=$BUILD_NUMBER -X common.Commit=$GIT_COMMIT" \
-ldflags "-X common.BuildNumber=$BUILD_NUMBER -X common.Commit=$GIT_COMMIT -X common.ReleaseTagName=$RELEASE_TAG_NAME" \
-v -o "$TARGET_OUTPUT" .
41 changes: 41 additions & 0 deletions vsts/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ variables:
- group: Oryx

stages:
- stage: CreateReleaseTag
jobs:
- job: CreateReleaseTag
pool:
name: OryxLinux
variables:
skipComponentGovernanceDetection: true
steps:
- task: ShellScript@2
inputs:
scriptPath: ./vsts/scripts/createReleaseTag.sh
displayName: 'Create release tag'
- script: |
set -ex
sourcesArtifactsDir="$(Build.SourcesDirectory)/artifacts"
mkdir -p "$sourcesArtifactsDir"
echo "$(RELEASE_TAG_NAME)" > "$sourcesArtifactsDir/releaseTag.txt"
displayName: 'Write release tag name to an artifact file'
- task: PublishPipelineArtifact@1
displayName: 'Publish artifact file having the release tag name'
inputs:
targetPath: $(Build.SourcesDirectory)/artifacts/releaseTag.txt
artifactName: releaseTag

- stage: Build
displayName: Build Stage
jobs:
Expand All @@ -27,6 +51,19 @@ stages:
SignType: 'test'
skipComponentGovernanceDetection: true
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download artifact file having release tag name'
inputs:
targetPath: $(Build.SourcesDirectory)/artifacts/releaseTag
artifactName: 'releaseTag'
- powershell: |
$file = "$env:BUILD_SOURCESDIRECTORY\artifacts\releaseTag\releaseTag.txt"
if (Test-Path $file) {
$tagName = [IO.File]::ReadAllText($file)
Write-Host "Content is $tagName"
echo "##vso[task.setvariable variable=RELEASE_TAG_NAME;]$tagName"
}
displayName: 'Set release tag name as environment variable'
- template: templates/_signBinary.yml

- job: Job_BuildImage
Expand All @@ -50,6 +87,8 @@ stages:
echo "##vso[task.setvariable variable=EmbedBuildContextInImages;]true"
displayName: 'Set variables'
- template: templates/_setReleaseTag.yml

- template: templates/_buildTemplate.yml

- job: Job_RuntimeImages
Expand All @@ -73,6 +112,8 @@ stages:
echo "##vso[task.setvariable variable=EmbedBuildContextInImages;]true"
displayName: 'Set variables'
- template: templates/_setReleaseTag.yml

- template: templates/_buildTemplate.yml

- template: templates/_integrationJobTemplate.yml
Expand Down
6 changes: 2 additions & 4 deletions vsts/pipelines/templates/_releaseJobTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ jobs:
inputs:
artifactName: drop

- task: ShellScript@2
inputs:
scriptPath: ./vsts/scripts/createReleaseTag.sh
- template: _setReleaseTag.yml

- task: GitHubRelease@0
displayName: 'GitHub release (create)'
inputs:
gitHubConnection: 'Oryx-GitHub'
repositoryName: Microsoft/Oryx
tagSource: manual
tag: '$(ReleaseTagName)'
tag: '$(RELEASE_TAG_NAME)'
2 changes: 2 additions & 0 deletions vsts/pipelines/templates/_releaseStepTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ steps:
SourceFolder: '$(System.ArtifactsDirectory)'
TargetFolder: '$(Build.ArtifactStagingDirectory)'

- template: _setReleaseTag.yml

- task: ms-devlabs.utilitytasks.task-Shellpp.Shell++@0
displayName: 'Pull and create release tags for build images'
inputs:
Expand Down
19 changes: 19 additions & 0 deletions vsts/pipelines/templates/_setReleaseTag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download artifact file having release tag name'
inputs:
targetPath: $(Build.SourcesDirectory)/artifacts/releaseTag
artifactName: 'releaseTag'

- script: |
set -e
file="$(Build.SourcesDirectory)/artifacts/releaseTag/releaseTag.txt"
echo "Release tag name is:"
cat "$file"
tagName=""
if [ -f "$file" ]; then
tagName=`cat $file`
fi
echo "##vso[task.setvariable variable=RELEASE_TAG_NAME;]$tagName"
displayName: 'Read release tag name from artifact file and set it as environment variable'
name: setReleaseTag
10 changes: 4 additions & 6 deletions vsts/pipelines/templates/_signBinary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ steps:
condition: and(succeeded(), eq(variables['setSignTypeVariable.SignType'], 'real'))

- powershell: |
Write-Host "Setting up git_commit and build_number as env variable"
$env:GIT_COMMIT=$(git rev-parse HEAD)
$env:BUILD_NUMBER=$env:BUILD_BUILDNUMBER
$env:GIT_COMMIT
$env:BUILD_NUMBER
dotnet publish -r linux-x64 -c Release src\BuildScriptGeneratorCLI\BuildScriptGeneratorCli.csproj
Write-Host "Setting up git_commit and build_number as env variable"
$env:GIT_COMMIT=$(git rev-parse HEAD)
$env:BUILD_NUMBER=$env:BUILD_BUILDNUMBER
dotnet publish -r linux-x64 -c Release src\BuildScriptGeneratorCLI\BuildScriptGeneratorCli.csproj
displayName: 'dotnet publish and after setting git_commit and build_number as env variable'
condition: and(succeeded(), eq(variables['setSignTypeVariable.SignType'], 'real'))

Expand Down
Loading

0 comments on commit f024e89

Please sign in to comment.