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

detect replacement container is created and inform printer so it attach and don't stop [ENV-87] #10236

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Feb 3, 2023

change a bit the "recreate" logic:

  • create replacement container with a temporary name
  • stop obsolete container
  • remove obsolete container
  • rename replacement container to canonical name
  • start

this allows to set a "replace" label on replacement container, and to detect the replaced container should not trigger printer to stop printing logs on exit.

how to test:

  • run docker compose up
  • on a distinct terminal, force container to be recreated using docker compose up --force-recreate -d
$ docker compose up
[+] Running 1/0
 ⠿ Container truc-test-1  Created                                                                                                                                                                                        0.0s
Attaching to truc-test-1
truc-test-1  | hello docker
truc-test-1  | hello docker
truc-test-1  | hello docker
truc-test-1  | hello docker
truc-test-1  | hello docker
truc-test-1 exited with code 137
truc-test-1 has been recreated
truc-test-1  | hello docker
truc-test-1  | hello docker
truc-test-1  | hello docker

same applies to docker compose logs -f

image

@ndeloof ndeloof requested review from a team, nicksieger, StefanScherer, ulyssessouza, glours, milas and laurazard and removed request for a team February 3, 2023 13:41
@ndeloof ndeloof force-pushed the re-attach-recreated branch 2 times, most recently from bc46f17 to 0bb0f21 Compare February 3, 2023 13:42
@ndeloof ndeloof changed the title detect replacement container is createed and inform printer so it attach and don't stop detect replacement container is created and inform printer so it attach and don't stop Feb 3, 2023
@codecov
Copy link

codecov bot commented Feb 3, 2023

Codecov Report

Base: 73.89% // Head: 73.89% // No change to project coverage 👍

Coverage data is based on head (c71b256) compared to base (1640f15).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##               v2   #10236   +/-   ##
=======================================
  Coverage   73.89%   73.89%           
=======================================
  Files           2        2           
  Lines         272      272           
=======================================
  Hits          201      201           
  Misses         60       60           
  Partials       11       11           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ndeloof ndeloof force-pushed the re-attach-recreated branch from 0bb0f21 to 922f635 Compare February 3, 2023 13:51
…ch and don't stop

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof ndeloof force-pushed the re-attach-recreated branch from 922f635 to c71b256 Compare February 3, 2023 14:00
@ndeloof ndeloof changed the title detect replacement container is created and inform printer so it attach and don't stop detect replacement container is created and inform printer so it attach and don't stop [ENV-87] Feb 3, 2023
Copy link
Contributor

@milas milas left a comment

Choose a reason for hiding this comment

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

Nice! This is nifty

@@ -55,6 +55,8 @@ const (
VersionLabel = "com.docker.compose.version"
// ImageBuilderLabel stores the builder (classic or BuildKit) used to produce the image.
ImageBuilderLabel = "com.docker.compose.image.builder"
// ContainerReplaceLabel is set when container is created to replace another container (recreated)
ContainerReplaceLabel = "com.docker.compose.replace"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah this is clever and I like that it lets us reliably associate it with the old one by ID!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants