-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
up: do not stop dependency containers (#9701)
This keeps parity with v1, where only the containers explicitly passed to `up` are torn down when `Ctrl-C` is hit, so any dependencies that got launched (or orphan containers hanging around) should not be touched. Fixes #9696. Signed-off-by: Milas Bowman <milas.bowman@docker.com>
- Loading branch information
Showing
6 changed files
with
203 additions
and
3 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
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,46 @@ | ||
/* | ||
Copyright 2022 Docker Compose CLI authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// RequireServiceState ensures that the container is in the expected state | ||
// (running or exited). | ||
func RequireServiceState(t testing.TB, cli *CLI, service string, state string) { | ||
t.Helper() | ||
psRes := cli.RunDockerComposeCmd(t, "ps", "--format=json", service) | ||
var psOut []map[string]interface{} | ||
require.NoError(t, json.Unmarshal([]byte(psRes.Stdout()), &psOut), | ||
"Invalid `compose ps` JSON output") | ||
|
||
for _, svc := range psOut { | ||
require.Equal(t, service, svc["Service"], | ||
"Found ps output for unexpected service") | ||
require.Equalf(t, | ||
strings.ToLower(state), | ||
strings.ToLower(svc["State"].(string)), | ||
"Service %q (%s) not in expected state", | ||
service, svc["Name"], | ||
) | ||
} | ||
} |
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,66 @@ | ||
/* | ||
Copyright 2022 Docker Compose CLI authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type lockedBuffer struct { | ||
mu sync.Mutex | ||
buf bytes.Buffer | ||
} | ||
|
||
func (l *lockedBuffer) Read(p []byte) (n int, err error) { | ||
l.mu.Lock() | ||
defer l.mu.Unlock() | ||
return l.buf.Read(p) | ||
} | ||
|
||
func (l *lockedBuffer) Write(p []byte) (n int, err error) { | ||
l.mu.Lock() | ||
defer l.mu.Unlock() | ||
return l.buf.Write(p) | ||
} | ||
|
||
func (l *lockedBuffer) String() string { | ||
l.mu.Lock() | ||
defer l.mu.Unlock() | ||
return l.buf.String() | ||
} | ||
|
||
func (l *lockedBuffer) RequireEventuallyContains(t testing.TB, v string) { | ||
t.Helper() | ||
var bufContents strings.Builder | ||
require.Eventuallyf(t, func() bool { | ||
l.mu.Lock() | ||
defer l.mu.Unlock() | ||
if _, err := l.buf.WriteTo(&bufContents); err != nil { | ||
require.FailNowf(t, "Failed to copy from buffer", | ||
"Error: %v", err) | ||
} | ||
return strings.Contains(bufContents.String(), v) | ||
}, 2*time.Second, 20*time.Millisecond, | ||
"Buffer did not contain %q\n============\n%s\n============", | ||
v, &bufContents) | ||
} |
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,11 @@ | ||
services: | ||
dependency: | ||
image: alpine | ||
init: true | ||
command: /bin/sh -c 'while true; do echo "hello dependency"; sleep 1; done' | ||
|
||
app: | ||
depends_on: ['dependency'] | ||
image: alpine | ||
init: true | ||
command: /bin/sh -c 'while true; do echo "hello app"; sleep 1; done' |
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,5 @@ | ||
services: | ||
orphan: | ||
image: alpine | ||
init: true | ||
command: /bin/sh -c 'while true; do echo "hello orphan"; sleep 1; done' |
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