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

dotnet publish: AfterTargets="AfterPublish" triggers before publish is complete #46999

Open
catmanjan opened this issue Feb 21, 2025 · 4 comments
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@catmanjan
Copy link

catmanjan commented Feb 21, 2025

Hello we have a project like many others publishing docker images to kubernetes.

To try to make developers life easier I added the following to my pubxml:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    ...snip...
  <Target Name="CustomActionsBeforePublish" BeforeTargets="BeforePublish">
    <Exec Command="az acr login -n icognitionhydra" />
  </Target>
  <Target Name="RestartPod" AfterTargets="AfterPublish">
	<Exec Command="az aks get-credentials -g hydraKubernetes -n hydra" />
    <Exec Command="kubectl rollout restart deployment hydra" />
  </Target>
</Project>

However, I notice the RestartPods target occurs before the image is fully published to my ACR, resulting in a race condition that sometimes Kubernetes beats, meaning the old image is deployed instead of the new...

What should my AfterTargets be set to if I want it to only run the rollout commands after the container is fully published to ACR?

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Feb 21, 2025
@baronfel
Copy link
Member

I'd need to take a look at a binlog to double-check, but my first recommendation would be the PublishContainer target - that's the target that actually creates + pushes container images to the desired destination, whether that's local daemon, tarball, or remote registry.

@catmanjan
Copy link
Author

@baronfel Thanks I'll try that now - out of interest where can someone read about all the different "AfterTargets" options?

I promise I did try searching myself!

@catmanjan
Copy link
Author

@baronfel I just tried this, but the commands never executed

  <Target Name="RestartPod" AfterTargets="PublishContainer">
	<Exec Command="az aks get-credentials -g hydraKubernetes -n hydra" />
    <Exec Command="kubectl rollout restart deployment hydra" />
  </Target>

@baronfel
Copy link
Member

Is there any way you can get an https://aka.ms/binlog and use the viewer to take a look? I added a target just like yours to a sample project I had, and then published that project with dotnet publish -t:PublishContainer and see the target firing as I expect:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants