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

Commit

Permalink
Merge pull request #1318 from docker/resolve-image-digests
Browse files Browse the repository at this point in the history
introduce --resolve-image-digests on config command
  • Loading branch information
ndeloof authored Feb 18, 2021
2 parents 4a5df4f + 0e862ee commit 28092e0
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 80 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/aci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
needs: check-optional-tests
if: github.ref == 'refs/heads/main' || needs.check-optional-tests.outputs.trigger-aci == 'true'
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Setup docker CLI
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Checkout code into the Go module directory
Expand All @@ -41,10 +41,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go
run: |
go get -u gotest.tools/gotestsum
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ecs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
needs: check-optional-tests
if: github.ref == 'refs/heads/main' || needs.check-optional-tests.outputs.trigger-ecs == 'true'
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Setup docker CLI
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/kube-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
needs: check-optional-tests
if: github.ref == 'refs/heads/main' || needs.check-optional-tests.outputs.trigger-kube == 'true'
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Setup docker CLI
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
upload-release:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Setup docker CLI
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
needs: check-optional-tests
if: github.ref == 'refs/heads/main' || needs.check-optional-tests.outputs.trigger-windows == 'true'
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Setup docker CLI
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG GO_VERSION=1.15.6-alpine
ARG GO_VERSION=1.16-alpine
ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine
ARG PROTOC_GEN_GO_VERSION=v1.4.3

Expand Down
2 changes: 1 addition & 1 deletion aci/e2e/aci_secrets_resources/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.15-alpine AS build
FROM golang:1.16-alpine AS build
COPY main.go .
RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o server main.go
Expand Down
2 changes: 1 addition & 1 deletion aci/etchosts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.15 AS builder
FROM golang:1.16 AS builder
WORKDIR $GOPATH/src/github.com/docker/compose-cli/aci/etchosts
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/hosts main/main.go
Expand Down
32 changes: 27 additions & 5 deletions cli/cmd/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ import (
"io"
"os"

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

"github.com/cnabio/cnab-to-oci/remotes"
"github.com/distribution/distribution/v3/reference"
cliconfig "github.com/docker/cli/cli/config"
"github.com/opencontainers/go-digest"
"github.com/spf13/cobra"

"github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config"
)

type convertOptions struct {
*projectOptions
Format string
Output string
quiet bool
Format string
Output string
quiet bool
resolve bool
}

var addFlagsFuncs []func(cmd *cobra.Command, opts *convertOptions)
Expand All @@ -60,6 +65,7 @@ func convertCommand(p *projectOptions) *cobra.Command {
}
flags := cmd.Flags()
flags.StringVar(&opts.Format, "format", "yaml", "Format the output. Values: [yaml | json]")
flags.BoolVar(&opts.resolve, "resolve-image-digests", false, "Pin image tags to digests.")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only validate the configuration, don't print anything.")

// add flags for hidden backends
Expand All @@ -81,6 +87,22 @@ func runConvert(ctx context.Context, opts convertOptions, services []string) err
return err
}

if opts.resolve {
configFile, err := cliconfig.Load(config.Dir(ctx))
if err != nil {
return err
}

resolver := remotes.CreateResolver(configFile)
err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) {
_, desc, err := resolver.Resolve(ctx, named.String())
return desc.Digest, err
})
if err != nil {
return err
}
}

json, err = c.ComposeService().Convert(ctx, project, compose.ConvertOptions{
Format: opts.Format,
Output: opts.Output,
Expand Down
35 changes: 6 additions & 29 deletions ecs/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
cloudmap "github.com/awslabs/goformation/v4/cloudformation/servicediscovery"
"github.com/cnabio/cnab-to-oci/remotes"
"github.com/compose-spec/compose-go/types"
"github.com/distribution/distribution/v3/reference"
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/distribution/reference"
"golang.org/x/sync/errgroup"
"github.com/opencontainers/go-digest"
"sigs.k8s.io/kustomize/kyaml/yaml"
"sigs.k8s.io/kustomize/kyaml/yaml/merge2"
)
Expand Down Expand Up @@ -110,33 +110,10 @@ func (b *ecsAPIService) resolveServiceImagesDigests(ctx context.Context, project
}

resolver := remotes.CreateResolver(configFile)
eg := errgroup.Group{}
for i, s := range project.Services {
idx := i
service := s
eg.Go(func() error {
named, err := reference.ParseDockerRef(service.Image)
if err != nil {
return err
}

_, desc, err := resolver.Resolve(ctx, named.String())
if err != nil {
return err
}

digested, err := reference.WithDigest(named, desc.Digest)
if err != nil {
return err
}

fmt.Printf("%s resolved to %s\n", service.Image, digested)
service.Image = digested.String()
project.Services[idx] = service
return nil
})
}
return eg.Wait()
return project.ResolveImages(func(named reference.Named) (digest.Digest, error) {
_, desc, err := resolver.Resolve(ctx, named.String())
return desc.Digest, err
})
}

func (b *ecsAPIService) convert(ctx context.Context, project *types.Project) (*cloudformation.Template, error) {
Expand Down
2 changes: 1 addition & 1 deletion ecs/resolv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.15 AS builder
FROM golang:1.16 AS builder
WORKDIR $GOPATH/src/github.com/docker/compose-cli/ecs/resolv
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/resolv main/main.go
Expand Down
2 changes: 1 addition & 1 deletion ecs/secrets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.15 AS builder
FROM golang:1.16 AS builder
WORKDIR $GOPATH/src/github.com/docker/compose-cli/ecs/secrets
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/secrets main/main.go
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/docker/compose-cli

go 1.15
go 1.16

require (
github.com/AlecAivazis/survey/v2 v2.2.3
Expand All @@ -17,10 +17,11 @@ require (
github.com/awslabs/goformation/v4 v4.15.6
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129
github.com/cnabio/cnab-to-oci v0.3.1-beta1
github.com/compose-spec/compose-go v0.0.0-20210202093933-d648aac758f9
github.com/compose-spec/compose-go v0.0.0-20210217144939-9f2c61fe6b14
github.com/containerd/console v1.0.1
github.com/containerd/containerd v1.4.3
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect
github.com/distribution/distribution/v3 v3.0.0-20210209042832-22c074842eaa
github.com/docker/buildx v0.5.1
github.com/docker/cli v20.10.1+incompatible
github.com/docker/distribution v2.7.1+incompatible
Expand Down
Loading

0 comments on commit 28092e0

Please sign in to comment.