Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
cli: allow suppressing deprecation warning
Browse files Browse the repository at this point in the history
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
  • Loading branch information
milas committed May 18, 2023
1 parent 9b21f9a commit 5593ef3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
5 changes: 3 additions & 2 deletions aci/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package aci

import (
"fmt"
"os"
"strings"

"github.com/docker/compose-cli/utils"

"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2019-12-01/containerinstance"
"github.com/Azure/go-autorest/autorest/to"
"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -69,7 +70,7 @@ func init() {
}

func service() (backend.Service, error) {
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
utils.ShowDeprecationWarning(os.Stderr)
contextStore := store.Instance()
currentContext := apicontext.Current()
var aciContext store.AciContext
Expand Down
5 changes: 3 additions & 2 deletions aci/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package aci

import (
"context"
"fmt"
"os"

"github.com/docker/compose-cli/utils"

"github.com/pkg/errors"

"github.com/docker/compose-cli/aci/login"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (cs *aciCloudService) Logout(ctx context.Context) error {
}

func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
utils.ShowDeprecationWarning(os.Stderr)
contextHelper := newContextCreateHelper()
createOpts := params.(ContextParams)
return contextHelper.createContextData(ctx, createOpts)
Expand Down
6 changes: 4 additions & 2 deletions ecs/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"os"

"github.com/docker/compose-cli/utils"

"github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/containers"
Expand Down Expand Up @@ -63,7 +65,7 @@ func init() {
}

func service() (backend.Service, error) {
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
utils.ShowDeprecationWarning(os.Stderr)
contextStore := store.Instance()
currentContext := apicontext.Current()
var ecsContext store.EcsContext
Expand Down Expand Up @@ -157,7 +159,7 @@ func (a ecsCloudService) Logout(ctx context.Context) error {
}

func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
utils.ShowDeprecationWarning(os.Stderr)
contextHelper := newContextCreateHelper()
createOpts := params.(ContextParams)
return contextHelper.createContextData(ctx, createOpts)
Expand Down
38 changes: 38 additions & 0 deletions utils/deprecation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2020 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 utils

import (
"fmt"
"io"
"os"
"strconv"
"sync"
)

const deprecationMessage = "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/"

var warnOnce sync.Once

func ShowDeprecationWarning(w io.Writer) {
warnOnce.Do(func() {
if quiet, _ := strconv.ParseBool(os.Getenv("COMPOSE_CLOUD_EOL_SILENT")); quiet {
return
}
_, _ = fmt.Fprintln(w, deprecationMessage)
})
}

0 comments on commit 5593ef3

Please sign in to comment.