-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: How to use MSBuild packages to influence the tags of the image | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
env: | ||
GITHUB_USERNAME: baronfel | ||
APP_NAME: msbuild-versioning-sample | ||
|
||
jobs: | ||
create-multiarch-image: | ||
permissions: | ||
contents: read | ||
packages: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Get the code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get .NET | ||
uses: actions/setup-dotnet@v4 | ||
|
||
- name: build the image | ||
working-directory: src/msbuild-versioning-sample | ||
run: | | ||
dotnet publish -t:PublishContainer -p ContainerRepository=${{github.repository_owner}}/${{env.APP_NAME}} -p ContainerRegistry=ghcr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
src/msbuild-versioning-example/msbuild-versioning-example.sln
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Container Tag Versioning through MSBuild logic | ||
|
||
This directory contains a sample project that demonstrates how to use MSBuild to automatically version container images. | ||
|
||
We're using [Ionide.KeepAChangelog.Tasks](https://github.com/ionide/KeepAChangelog) to handle versioning the app. It reads the [`CHANGELOG.md`](./CHANGELOG.md) file and populates a few MSBuild properties that build/pack/etc use. | ||
|
||
These properties are set _during the build_, so we can't simply add | ||
|
||
```xml | ||
<ContainerImageTags>blah;foo</ContainerImageTags> | ||
``` | ||
|
||
to the `.csproj` file. This is because project file properties are read in as part of _evaluation_, but the versioning logic from Ionide.KeepAChangelog.Tasks (and similar tools like NerdBank.GitVersioning) runs during _execution_. | ||
|
||
To fix this, we need to set the property sometime _after_ Ionide.KeepAChangelog.Tasks has run and before the `ContainerImageTags` are computed by the SDK. We can do this by adding a target to the `.csproj` file that runs immediately before the SDK's `ComputeContainerConfig` Target. | ||
|
||
```xml | ||
<Target Name="SetContainerTags" BeforeTargets="ComputeContainerConfig"> | ||
<PropertyGroup> | ||
<ContainerImageTags>latest;$(Version)</ContainerImageTags> | ||
</PropertyGroup> | ||
</Target> | ||
``` | ||
|
||
Now, when we publish, we'll make containers with tags like `msbuild-versioning-sample:latest` and `msbuild-versioning-sample:0.1.0`. |
File renamed without changes.