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

feat: Detecting Golang services and creating plan file #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright IBM Corporation 2021
*
* 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 assets

import "embed"

//go:generate go run ../scripts/generator/persistpermissions.go built-in/ filepermissions.yaml

// AssetsDir is the embedded built-in assets directory
//
//go:embed built-in/*
var AssetsDir embed.FS

// AssetFilePermissions is embedded file having permissions information for the assets
//
//go:embed filepermissions.yaml
var AssetFilePermissions string
18 changes: 18 additions & 0 deletions assets/built-in/presets/analyze-docker-compose-only.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
move2kube:
transformers:
types:
- ComposeGenerator
- ComposeAnalyser
- Knative
- ContainerImagesPushScriptGenerator
- DockerfileParser
- DockerfileImageBuildScript
- Kubernetes
- ArgoCD
- Tekton
- Buildconfig
- ClusterSelector
- Parameterizer
- ReadMeGenerator
- DockerfileDetector
transformerselector: ""
2 changes: 2 additions & 0 deletions assets/built-in/presets/containerize-only.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
move2kube:
transformerselector: "move2kube.konveyor.io/task in (containerization,containerizationscript)"
16 changes: 16 additions & 0 deletions assets/built-in/presets/docker-file-only.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
move2kube:
transformers:
types:
- Knative
- ContainerImagesPushScriptGenerator
- DockerfileParser
- DockerfileImageBuildScript
- Kubernetes
- ArgoCD
- Tekton
- Buildconfig
- ClusterSelector
- Parameterizer
- ReadMeGenerator
- DockerfileDetector
transformerselector: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
move2kube:
spawncontainers: true
2 changes: 2 additions & 0 deletions assets/built-in/presets/use-podman-in-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
move2kube:
containerruntime: podman
18 changes: 18 additions & 0 deletions assets/built-in/transformers/cloudfoundry/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: CloudFoundry
labels:
move2kube.konveyor.io/built-in: true
spec:
class: "CloudFoundry"
directoryDetect:
levels: 1
consumes:
Service:
disabled: false
produces:
IR:
disabled: false
Service:
disabled: false
23 changes: 23 additions & 0 deletions assets/built-in/transformers/cnb/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: CNBContainerizer
labels:
move2kube.konveyor.io/task: containerization
move2kube.konveyor.io/built-in: true
move2kube.konveyor.io/container-based: true
spec:
mode: "Container"
class: "CNBContainerizer"
directoryDetect:
levels: -1
consumes:
Service:
disabled: false
produces:
CNBDetectedService:
disabled: false
config:
container:
image: "paketobuildpacks/builder:full"
keepAliveCommand: ["tail", "-f", "/dev/null"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: ComposeAnalyser
labels:
move2kube.konveyor.io/built-in: true
spec:
class: "ComposeAnalyser"
directoryDetect:
levels: 1
consumes:
Service:
disabled: false
produces:
IR:
disabled: false
Dockerfile:
disabled: false
config:
enableNetworkParsing: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: ComposeGenerator
labels:
move2kube.konveyor.io/built-in: true
spec:
class: "ComposeGenerator"
directoryDetect:
levels: 0
consumes:
IR:
merge: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
:: Copyright IBM Corporation 2021
::
:: 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.

:: Invoke as pushimages.bat <registry_url> <registry_namespace> <container_runtime>
:: Examples:
:: 1) pushimages.bat
:: 2) pushimages.bat quay.io your_quay_username
:: 3) pushimages.bat index.docker.io your_registry_namespace podman

@echo off
IF "%3"=="" GOTO DEFAULT_CONTAINER_RUNTIME
SET CONTAINER_RUNTIME=%3%
GOTO REGISTRY

:DEFAULT_CONTAINER_RUNTIME
SET CONTAINER_RUNTIME=docker
GOTO REGISTRY

:REGISTRY
IF "%2"=="" GOTO DEFAULT_REGISTRY
IF "%1"=="" GOTO DEFAULT_REGISTRY
SET REGISTRY_URL=%1
SET REGISTRY_NAMESPACE=%2
GOTO DOCKER_CONTAINER_RUNTIME

:DEFAULT_REGISTRY
SET REGISTRY_URL={{ .RegistryURL }}
SET REGISTRY_NAMESPACE={{ .RegistryNamespace }}
GOTO DOCKER_CONTAINER_RUNTIME

:DOCKER_CONTAINER_RUNTIME
IF NOT "%CONTAINER_RUNTIME%" == "docker" GOTO PODMAN_CONTAINER_RUNTIME
GOTO MAIN

:PODMAN_CONTAINER_RUNTIME
IF NOT "%CONTAINER_RUNTIME%" == "podman" GOTO UNSUPPORTED_BUILD_SYSTEM
GOTO MAIN

:UNSUPPORTED_BUILD_SYSTEM
echo 'Unsupported build system passed as an argument for pushing the images.'
GOTO SKIP

:MAIN
:: Uncomment the below line if you want to enable login before pushing
:: %CONTAINER_RUNTIME% login %REGISTRY_URL%
{{- range $image := .Images }}

echo "pushing image {{ $image }}"
%CONTAINER_RUNTIME% tag {{ $image }} %REGISTRY_URL%/%REGISTRY_NAMESPACE%/{{ $image }}
%CONTAINER_RUNTIME% push %REGISTRY_URL%/%REGISTRY_NAMESPACE%/{{ $image }}
{{- end }}

echo "done"

:SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Copyright IBM Corporation 2020
#
# 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.

# Invoke as ./pushimages.sh <registry_url> <registry_namespace> <container_runtime>
# Examples:
# 1) ./pushimages.sh
# 2) ./pushimages.sh quay.io your_quay_username
# 3) ./pushimages.sh index.docker.io your_registry_namespace podman

REGISTRY_URL={{ .RegistryURL }}
REGISTRY_NAMESPACE={{ .RegistryNamespace }}
CONTAINER_RUNTIME=docker
if [ "$#" -gt 1 ]; then
REGISTRY_URL=$1
REGISTRY_NAMESPACE=$2
fi
if [ "$#" -eq 3 ]; then
CONTAINER_RUNTIME=$3
fi
if [ "${CONTAINER_RUNTIME}" != "docker" ] && [ "${CONTAINER_RUNTIME}" != "podman" ]; then
echo 'Unsupported container runtime passed as an argument for pushing the images: '"${CONTAINER_RUNTIME}"
exit 1
fi
# Uncomment the below line if you want to enable login before pushing
# ${CONTAINER_RUNTIME} login ${REGISTRY_URL}
{{- range $image := .Images }}

echo 'pushing image {{ $image }}'
${CONTAINER_RUNTIME} tag {{ $image }} ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/{{ $image }}
${CONTAINER_RUNTIME} push ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/{{ $image }}
{{- end }}

echo 'done'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: ContainerImagesPushScriptGenerator
labels:
move2kube.konveyor.io/task: containerizationscript
move2kube.konveyor.io/built-in: true
spec:
class: "ContainerImagesPushScript"
directoryDetect:
levels: 0
consumes:
NewImages:
merge: true
produces:
ContainerImagesPushScript:
disabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: DockerfileDetector
labels:
move2kube.konveyor.io/built-in: true
spec:
class: "DockerfileDetector"
directoryDetect:
levels: 1
consumes:
Service:
disabled: false
produces:
Dockerfile:
disabled: false
DockerfileForService:
disabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: move2kube.konveyor.io/v1alpha1
kind: Transformer
metadata:
name: DockerfileParser
labels:
move2kube.konveyor.io/built-in: true
spec:
class: "DockerfileParser"
directoryDetect:
levels: 0
consumes:
DockerfileForService:
merge: false
produces:
IR:
disabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
:: Copyright IBM Corporation 2021
::
:: 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.

:: Invoke as buildandpush_multiarchimages.bat <registry_url> <registry_namespace> <comma_separated_platforms>
:: Examples:
:: 1) buildandpush_multiarchimages.bat
:: 2) buildandpush_multiarchimages.bat index.docker.io your_registry_namespace
:: 3) buildandpush_multiarchimages.bat quay.io your_quay_username linux/amd64,linux/arm64,linux/s390x

@echo off
for /F "delims=" %%i in ("%cd%") do set basename="%%~ni"

if not %basename% == "scripts" (
echo "please run this script from the 'scripts' directory"
exit 1
)

REM go to the parent directory so that all the relative paths will be correct
cd {{ .RelParentOfSourceDir }}

IF "%3"=="" GOTO DEFAULT_PLATFORMS
SET PLATFORMS=%3%
GOTO REGISTRY

:DEFAULT_PLATFORMS
SET PLATFORMS=linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
GOTO REGISTRY

:REGISTRY
IF "%2"=="" GOTO DEFAULT_REGISTRY
IF "%1"=="" GOTO DEFAULT_REGISTRY
SET REGISTRY_URL=%1
SET REGISTRY_NAMESPACE=%2
GOTO MAIN

:DEFAULT_REGISTRY
SET REGISTRY_URL={{ .RegistryURL }}
SET REGISTRY_NAMESPACE={{ .RegistryNamespace }}
GOTO MAIN

:MAIN
:: Uncomment the below line if you want to enable login before pushing
:: docker login %REGISTRY_URL%
{{- range $dockerfile := .DockerfilesConfig }}

echo "building and pushing image {{ $dockerfile.ImageName }}"
pushd {{ $dockerfile.ContextWindows }}
docker buildx build --platform ${PLATFORMS} -f {{ $dockerfile.DockerfileName }} --push --tag ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/{{ $dockerfile.ImageName }} .
popd
{{- end }}

echo "done"
Loading