You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/05/28 14:04:52 UTC
[camel-k] branch master updated: Fix #644: remove predefined images
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new 9a1999c Fix #644: remove predefined images
9a1999c is described below
commit 9a1999c3286da3e31cf9bc65adbee8df836dceb7
Author: nferraro <ni...@gmail.com>
AuthorDate: Tue May 28 12:52:15 2019 +0200
Fix #644: remove predefined images
---
.gitignore | 1 -
cmd/util/publisher/publisher.go | 204 -------------------------------------
pkg/platform/images/doc.go | 19 ----
pkg/platform/images/images.go | 89 ----------------
pkg/platform/images/images_test.go | 86 ----------------
pkg/trait/images.go | 63 ------------
pkg/trait/trait_catalog.go | 6 --
script/Makefile | 11 +-
8 files changed, 2 insertions(+), 477 deletions(-)
diff --git a/.gitignore b/.gitignore
index 48e5116..2513a32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,6 @@
# Binary files
/camel-k
/kamel
-/publisher
/builder
# Released Packages
diff --git a/cmd/util/publisher/publisher.go b/cmd/util/publisher/publisher.go
deleted file mode 100644
index 2789274..0000000
--- a/cmd/util/publisher/publisher.go
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 main
-
-import (
- "fmt"
- "io/ioutil"
- "os"
- "os/exec"
- "path"
- "path/filepath"
- "sort"
- "strings"
- "time"
-
- clientscheme "k8s.io/client-go/kubernetes/scheme"
-
- "github.com/apache/camel-k/pkg/apis"
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/builder"
- "github.com/apache/camel-k/pkg/platform/images"
- "github.com/apache/camel-k/pkg/util/camel"
- "github.com/apache/camel-k/pkg/util/defaults"
- "github.com/apache/camel-k/pkg/util/test"
-
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-// PublisherOptions --
-type PublisherOptions struct {
- StartWith string
- EndWith string
- RuntimeVersion string
- BuildAttempts int
-}
-
-// Publishes predefined images for all Camel components
-func main() {
- options := PublisherOptions{}
-
- var cmd = cobra.Command{
- Use: "publisher",
- Short: "Publisher allows to publish base images before a release",
- Run: options.run,
- }
-
- cmd.Flags().StringVar(&options.StartWith, "start-with", "", "The component to start with")
- cmd.Flags().StringVar(&options.EndWith, "end-with", "", "The component to end with")
- cmd.Flags().StringVar(&options.RuntimeVersion, "runtime-version", defaults.RuntimeVersion, "The runtime version to use")
- cmd.Flags().IntVar(&options.BuildAttempts, "attempts", 5, "The maximum number of build attempts for each image")
-
- panicIfErr(cmd.Execute())
-}
-
-func (options *PublisherOptions) run(_ *cobra.Command, _ []string) {
- scheme := clientscheme.Scheme
- panicIfErr(apis.AddToScheme(scheme))
-
- started := options.StartWith == ""
-
- catalog, err := test.DefaultCatalog()
- if err != nil {
- fmt.Printf("Error retrieveing default catalog: %s", err.Error())
- return
- }
-
- keys := make([]string, 0, len(catalog.Artifacts))
- for k := range catalog.Artifacts {
- keys = append(keys, k)
- }
- sort.Strings(keys)
-
- for _, k := range keys {
- a := catalog.Artifacts[k]
- if a.GroupID == "org.apache.camel" {
- component := strings.TrimPrefix(a.ArtifactID, "camel-")
- if options.StartWith == component {
- started = true
- }
-
- if started {
- fmt.Printf("building component %s\n", component)
- options.buildWithAttempts(component, options.RuntimeVersion, catalog)
- } else {
- fmt.Printf("skipping component %s\n", component)
- }
-
- if options.EndWith == component {
- fmt.Println("reached final component")
- break
- }
- }
- }
-}
-
-func (options *PublisherOptions) buildWithAttempts(component string, runtimeVersion string, catalog *camel.RuntimeCatalog) {
- var err error
- for i := 0; i < options.BuildAttempts; i++ {
- err = options.build(component, runtimeVersion, catalog)
- if err != nil {
- sleepTime := 5 * (i + 1)
- fmt.Printf("waiting %d seconds to recover from error %v\n", sleepTime, err)
- time.Sleep(time.Duration(sleepTime) * time.Second)
- } else {
- return
- }
- }
- panicIfErr(errors.Wrap(err, "build failed after maximum number of attempts"))
-}
-
-func (options *PublisherOptions) build(component string, runtimeVersion string, catalog *camel.RuntimeCatalog) error {
- dir, err := ioutil.TempDir(os.TempDir(), "camel-k-build-")
- if err != nil {
- return err
- }
- defer os.RemoveAll(dir)
-
- dependencies := make([]string, 0)
- for d := range images.StandardDependencies {
- dependencies = append(dependencies, d)
- }
- dependencies = append(dependencies, images.BaseDependency)
- dependencies = append(dependencies, "camel:"+component)
-
- ctx := builder.Context{
- Catalog: catalog,
- Path: dir,
- Build: v1alpha1.BuildSpec{
- RuntimeVersion: runtimeVersion,
- Platform: v1alpha1.IntegrationPlatformSpec{
- Build: v1alpha1.IntegrationPlatformBuildSpec{
- CamelVersion: catalog.Version,
- },
- },
- Dependencies: dependencies,
- },
- }
-
- err = builder.Steps.GenerateProject.Execute(&ctx)
- if err != nil {
- return err
- }
- err = builder.Steps.ComputeDependencies.Execute(&ctx)
- if err != nil {
- return err
- }
- err = builder.Steps.StandardPackager.Execute(&ctx)
- if err != nil {
- return err
- }
-
- archiveDir, archiveName := filepath.Split(ctx.Archive)
- // nolint: gosec
- dockerfile := `
- FROM fabric8/s2i-java:3.0-java8
- ADD ` + archiveName + ` /deployments/
- `
-
- err = ioutil.WriteFile(path.Join(archiveDir, "Dockerfile"), []byte(dockerfile), 0777)
- if err != nil {
- return err
- }
-
- image := images.PredefinedImageNameFor(component)
- buildCmd := exec.Command("docker", "build", "-t", image, archiveDir)
- buildCmd.Stdout = os.Stdout
- buildCmd.Stderr = os.Stderr
- err = buildCmd.Run()
- if err != nil {
- return err
- }
-
- pushCmd := exec.Command("docker", "push", image)
- pushCmd.Stdout = os.Stdout
- pushCmd.Stderr = os.Stderr
- err = pushCmd.Run()
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func panicIfErr(err error) {
- if err != nil {
- panic(err)
- }
-}
diff --git a/pkg/platform/images/doc.go b/pkg/platform/images/doc.go
deleted file mode 100644
index cdf53c0..0000000
--- a/pkg/platform/images/doc.go
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 images contains information for retrieval of platform predefined images
-package images
diff --git a/pkg/platform/images/images.go b/pkg/platform/images/images.go
deleted file mode 100644
index e40eb84..0000000
--- a/pkg/platform/images/images.go
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 images
-
-import (
- "fmt"
- "strings"
-
- "github.com/apache/camel-k/pkg/util/camel"
- "github.com/apache/camel-k/pkg/util/defaults"
-)
-
-// BaseRepository is the docker repository that contains images
-const (
- BaseRepository = "camelk"
- ImagePrefix = "camel-base-knative-"
-)
-
-// BaseDependency is a required dependency that must be found in the list
-var BaseDependency = "camel-k:knative"
-
-// StandardDependencies are common dependencies included in the image
-var StandardDependencies = map[string]bool{
- "camel:core": true,
- "runtime:jvm": true,
- "runtime:yaml": true,
- "mvn:org.apache.camel.k:camel-k-adapter-camel-2:" + defaults.RuntimeVersion: true,
- "camel:camel-netty4-http": true,
-}
-
-// LookupPredefinedImage is used to find a suitable predefined image if available
-func LookupPredefinedImage(catalog *camel.RuntimeCatalog, dependencies []string) string {
-
- realDependencies := make([]string, 0)
- baseDependencyFound := false
- for _, d := range dependencies {
- if _, std := StandardDependencies[d]; std {
- continue
- }
- if d == BaseDependency {
- baseDependencyFound = true
- continue
- }
- realDependencies = append(realDependencies, d)
- }
-
- if !baseDependencyFound {
- return ""
- }
- if len(realDependencies) == 0 {
- return PredefinedImageNameFor("core")
- }
- if len(realDependencies) != 1 {
- return ""
- }
-
- otherDep := realDependencies[0]
- camelPrefix := "camel:"
- if !strings.HasPrefix(otherDep, camelPrefix) {
- return ""
- }
-
- comp := strings.TrimPrefix(otherDep, camelPrefix)
- if !catalog.HasArtifact(comp) {
- return ""
- }
-
- return PredefinedImageNameFor(comp)
-}
-
-// PredefinedImageNameFor --
-func PredefinedImageNameFor(comp string) string {
- return fmt.Sprintf("%s/%s%s:%s", BaseRepository, ImagePrefix, comp, defaults.Version)
-}
diff --git a/pkg/platform/images/images_test.go b/pkg/platform/images/images_test.go
deleted file mode 100644
index 85a4337..0000000
--- a/pkg/platform/images/images_test.go
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 images
-
-import (
- "strconv"
- "testing"
-
- "github.com/apache/camel-k/pkg/util/defaults"
- "github.com/apache/camel-k/pkg/util/test"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestImageLookup(t *testing.T) {
- cases := []struct {
- dependencies []string
- image string
- }{
- {
- dependencies: []string{"camel:telegram"},
- },
- {
- dependencies: []string{"camel:telegram", "camel:core"},
- },
- {
- dependencies: []string{"camel:telegram", "camel:core", "camel-k:knative"},
- image: BaseRepository + "/" + ImagePrefix + "telegram:" + defaults.Version,
- },
- {
- dependencies: []string{"camel:telegram", "camel-k:knative"},
- image: BaseRepository + "/" + ImagePrefix + "telegram:" + defaults.Version,
- },
- {
- dependencies: []string{"camel:telegram", "camel:core", "camel-k:knative", "camel:dropbox"},
- },
- {
- dependencies: []string{"camel:core", "camel-k:knative"},
- image: BaseRepository + "/" + ImagePrefix + "core:" + defaults.Version,
- },
- {
- dependencies: []string{"camel:dropbox", "camel:core", "camel-k:knative", "runtime:jvm"},
- image: BaseRepository + "/" + ImagePrefix + "dropbox:" + defaults.Version,
- },
- {
- dependencies: []string{"camel:dropbox", "camel:core", "camel-k:knative", "runtime:jvm", "runtime:yaml"},
- image: BaseRepository + "/" + ImagePrefix + "dropbox:" + defaults.Version,
- },
- {
- dependencies: []string{"camel:dropbox", "camel:core", "runtime:jvm", "runtime:yaml"},
- },
- {
- dependencies: []string{"camel:dropbox", "camel:core", "camel-k:knative", "runtime:jvm", "runtime:groovy"},
- },
- {
- dependencies: []string{"camel:cippalippa", "camel:core", "camel-k:knative"},
- },
- }
-
- for i, tc := range cases {
- testcase := tc
-
- catalog, err := test.DefaultCatalog()
- assert.Nil(t, err)
-
- t.Run("case-"+strconv.Itoa(i), func(t *testing.T) {
- assert.Equal(t, testcase.image, LookupPredefinedImage(catalog, testcase.dependencies))
- })
- }
-
-}
diff --git a/pkg/trait/images.go b/pkg/trait/images.go
deleted file mode 100644
index 9a73cad..0000000
--- a/pkg/trait/images.go
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 trait
-
-import (
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/platform/images"
-)
-
-type imagesTrait struct {
- BaseTrait `property:",squash"`
-}
-
-func newImagesTrait() *imagesTrait {
- return &imagesTrait{
- BaseTrait: newBaseTrait("images"),
- }
-}
-
-func (t *imagesTrait) Configure(e *Environment) (bool, error) {
- if t.Enabled == nil || !*t.Enabled {
- // Disabled by default
- return false, nil
- }
-
- if e.IntegrationContextInPhase("") {
- return true, nil
- }
-
- return false, nil
-}
-
-func (t *imagesTrait) Apply(e *Environment) error {
- // Try to lookup a image from predefined images
- image := images.LookupPredefinedImage(e.CamelCatalog, e.IntegrationContext.Spec.Dependencies)
- if image == "" {
- return nil
- }
-
- // Change the context type to external
- if e.IntegrationContext.Labels == nil {
- e.IntegrationContext.Labels = make(map[string]string)
- }
- e.IntegrationContext.Labels["camel.apache.org/context.type"] = v1alpha1.IntegrationContextTypeExternal
-
- e.IntegrationContext.Spec.Image = image
- return nil
-}
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index ca36acb..bea399a 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -46,7 +46,6 @@ type Catalog struct {
tJolokia Trait
tPrometheus Trait
tOwner Trait
- tImages Trait
tBuilder Trait
tIstio Trait
tEnvironment Trait
@@ -76,7 +75,6 @@ func NewCatalog(ctx context.Context, c client.Client) *Catalog {
tJolokia: newJolokiaTrait(),
tPrometheus: newPrometheusTrait(),
tOwner: newOwnerTrait(),
- tImages: newImagesTrait(),
tBuilder: newBuilderTrait(),
tIstio: newIstioTrait(),
tEnvironment: newEnvironmentTrait(),
@@ -114,7 +112,6 @@ func (c *Catalog) allTraits() []Trait {
c.tJolokia,
c.tPrometheus,
c.tOwner,
- c.tImages,
c.tBuilder,
c.tIstio,
c.tEnvironment,
@@ -135,7 +132,6 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
c.tDebug,
c.tRestDsl,
c.tDependencies,
- c.tImages,
c.tBuilder,
c.tEnvironment,
c.tJolokia,
@@ -157,7 +153,6 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
c.tDebug,
c.tRestDsl,
c.tDependencies,
- c.tImages,
c.tBuilder,
c.tEnvironment,
c.tJolokia,
@@ -180,7 +175,6 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
c.tRestDsl,
c.tKnative,
c.tDependencies,
- c.tImages,
c.tBuilder,
c.tEnvironment,
c.tDeployer,
diff --git a/script/Makefile b/script/Makefile
index ba625fa..433147c 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -49,7 +49,7 @@ codegen:
generate:
operator-sdk generate k8s
-build: build-operator build-kamel build-publisher build-builder build-compile-integration-tests
+build: build-operator build-kamel build-builder build-compile-integration-tests
test: build
go test ./...
@@ -63,9 +63,6 @@ build-operator:
build-kamel:
go build -o kamel ./cmd/kamel/*.go
-build-publisher:
- go build -o publisher ./cmd/util/publisher/*.go
-
build-builder:
env GOOS=linux go build -o builder ./cmd/builder/*.go
@@ -92,7 +89,6 @@ clean:
GO111MODULE=off go clean
rm -f camel-k
rm -f kamel
- rm -f publisher
rm -f builder
rm -rf build/_maven_output
rm -rf build/_output
@@ -142,9 +138,6 @@ package-examples:
package-artifacts:
./script/package_maven_artifacts.sh $(RUNTIME_VERSION)
-publish-base-images:
- go run cmd/util/publisher/publisher.go --runtime-version=$(RUNTIME_VERSION)
-
release: clean codegen set-version build-resources build images images-push cross-compile package-examples git-tag
install-minishift:
@@ -152,4 +145,4 @@ install-minishift:
install-minikube:
./script/install_minikube.sh
-.PHONY: build build-operator build-kamel build-resources build-builder dep codegen images images-dec images-push test check test-integration clean release cross-compile package-examples set-version git-tag publish-base-images
+.PHONY: build build-operator build-kamel build-resources build-builder dep codegen images images-dec images-push test check test-integration clean release cross-compile package-examples set-version git-tag