Skip to content

Commit

Permalink
initial working version of move2kube
Browse files Browse the repository at this point in the history
Signed-off-by: Ashok Pon Kumar <[email protected]>
  • Loading branch information
ashokponkumar committed Sep 18, 2020
1 parent c0da215 commit 6b90cbd
Show file tree
Hide file tree
Showing 273 changed files with 24,233 additions and 4 deletions.
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build image
FROM registry.access.redhat.com/ubi8/ubi:latest AS build_base
ARG APPNAME=move2kube
# Get Dependencies
WORKDIR /temp
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl -o go.tar.gz https://dl.google.com/go/go1.15.linux-amd64.tar.gz
RUN tar -xzf go.tar.gz && mv go /usr/local/
RUN yum install git make -y
RUN mkdir -p $GOPATH/src $GOPATH/bin && chmod -R 777 $GOPATH
ENV WORKDIR=${GOPATH}/src/${APPNAME}
WORKDIR ${WORKDIR}
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY scripts/installdeps.sh scripts/installdeps.sh
RUN cd / && source ${WORKDIR}/scripts/installdeps.sh && cd -
COPY . .
# Build
RUN make build
RUN cp bin/${APPNAME} /bin/${APPNAME}

# Run image
FROM registry.access.redhat.com/ubi8/ubi:latest
COPY misc/centos.repo /etc/yum.repos.d/centos.repo
RUN yum update -y && yum install -y podman && yum clean all
COPY --from=build_base /bin/${APPNAME} /bin/${APPNAME}
COPY --from=build_base /bin/pack /bin/pack
COPY --from=build_base /bin/kubectl /bin/kubectl
COPY --from=build_base /bin/operator-sdk /bin/operator-sdk
VOLUME ["/wksps"]
#"/var/run/docker.sock" needs to be mounted for CNB containerization to be used.
# Start app
WORKDIR /wksps
CMD [${APPNAME}]
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -186,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright IBM Corporation [yyyy]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +199,4 @@
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.
limitations under the License.
154 changes: 154 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# 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.

BINNAME ?= move2kube
BINDIR := $(CURDIR)/bin
DISTDIR := $(CURDIR)/_dist
TARGETS := darwin/amd64 linux/amd64

GOPATH = $(shell go env GOPATH)
GOX = $(GOPATH)/bin/gox
GOLINT = $(GOPATH)/bin/golint
GOTEST = ${GOPATH}/bin/gotest
GOLANGCILINT = $(GOPATH)/bin/golangci-lint
GOLANGCOVER = $(GOPATH)/bin/goveralls

PKG := ./...
LDFLAGS := -w -s

SRC = $(shell find . -type f -name '*.go' -print)
ARCH = $(shell uname -p)
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")

GOGET := cd / && GO111MODULE=on go get -u

ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
BINARY_VERSION ?= ${GIT_TAG}
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.version=${BINARY_VERSION}
VERSION = $(BINARY_VERSION)
endif

VERSION_METADATA = unreleased
ifneq ($(GIT_TAG),)
VERSION_METADATA =
endif
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.metadata=${VERSION_METADATA}

LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.gitCommit=${GIT_COMMIT}
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.gitTreeState=${GIT_DIRTY}
LDFLAGS += -extldflags "-static"

# HELP
# This will output the help for each task
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

# -- Build --

.PHONY: build
build: get $(BINDIR)/$(BINNAME) ## Build go code

$(BINDIR)/$(BINNAME): $(SRC)
@go build -tags excludecodegen -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) ./cmd/${BINNAME}
@cp $(BINDIR)/$(BINNAME) $(GOPATH)/bin/

.PHONY: get
get: go.mod
@go mod download

.PHONY: generate
generate:
@go generate ${PKG}

.PHONY: deps
deps:
@source scripts/installdeps.sh

# -- Test --

.PHONY: test
test: ## Run tests
@go test -run . $(PKG) -race

${GOTEST}:
${GOGET} github.com/rakyll/gotest

.PHONY: test-verbose
test-verbose: ${GOTEST}
@gotest -run . $(PKG) -race -v

${GOLANGCOVER}:
${GOGET} github.com/mattn/[email protected]

.PHONY: test-coverage
test-coverage: ${GOLANGCOVER} ## Run tests with coverage
@go test -run . $(PKG) -covermode=atomic

${GOLANGCILINT}:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.30.0

${GOLINT}:
${GOGET} golang.org/x/lint/golint

.PHONY: test-style
test-style: ${GOLANGCILINT} ${GOLINT}
${GOLANGCILINT} run
${GOLINT} ${PKG}
scripts/licensecheck.sh

# -- Release --

$(GOX):
${GOGET} github.com/mitchellh/[email protected]

.PHONY: build-cross
build-cross: $(GOX) clean
CGO_ENABLED=0 $(GOX) -parallel=3 -output="$(DISTDIR)/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' -ldflags '$(LDFLAGS)' ./cmd/${BINNAME}

.PHONY: dist
dist: clean build-cross ## Build Distribution
@mkdir -p $(DISTDIR)/files
@cp -r ./{LICENSE,scripts/installdeps.sh,USAGE.md,samples} $(DISTDIR)/files/
@cd $(DISTDIR) && \
find * -maxdepth 1 -name "*-*" -type d \
-exec cp -r $(DISTDIR)/files/* {} \; \
-exec tar -zcf ${BINNAME}-${VERSION}-{}.tar.gz {} \; \
-exec sh -c 'shasum -a 256 ${BINNAME}-${VERSION}-{}.tar.gz > ${BINNAME}-${VERSION}-{}.tar.gz.sha256sum' \; \
-exec zip -r ${BINNAME}-${VERSION}-{}.zip {} \; \
-exec sh -c 'shasum -a 256 ${BINNAME}-${VERSION}-{}.zip > ${BINNAME}-${VERSION}-{}.zip.sha256sum' \;

.PHONY: clean
clean:
@rm -rf $(BINDIR) $(DISTDIR)
@go clean -cache

.PHONY: info
info: ## Get version info
@echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}"
@echo "Git Tree State: ${GIT_DIRTY}"

# -- Docker --

.PHONY: cbuild
cbuild: ## Build docker image
@docker build -t ${BINNAME}:latest .
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# move2kube
Move2Kube is a command-line tool that accelerates the process of re-platforming to Kubernetes/Openshift.

# Move2Kube

Move2Kube is a command-line tool that accelerates the process of re-platforming to Kubernetes/Openshift. It does so by analysing the environment and source artifacts, and asking guidance from the user when required.

![Pipeline](imgs/arch.png?raw=true "Pipeline")

## Usage

![Usage](./imgs/usage.png)

Instructions can be found [here](./USAGE.md)

## Setup

1. Obtain a recent version of `golang`. Known to work with `1.15`.
1. Ensure `$GOPATH` is set. If it's not set:
1. `mkdir ~/go`
1. `export GOPATH=~/go`
1. Obtain this repo:
1. `mkdir -p $GOPATH/src/`
1. Clone this repo into the above directory.
1. `cd $GOPATH/src/move2kube`
1. Build: `make build`
1. Run unit tests: `make test`

## Artifacts Required

| Source | Artifact available | Features supported |
|:-------|:-------------------|:-------------------|
| Cloud Foundry | Manifest files | Containerization options from buildpacks, Deployment artifacts |
| Cloud Foundry | Manifest files, Source code | Containerization options based on buildpack/source code, Deployment artifacts |
| Cloud Foundry | Manifest files, Source code, Access to running instance | Containerization options based on buildpack/source code, Deployment artifacts, Metadata from runtime |
| Cloud Foundry | Access to running instance | Metadata from runtime, Containerization options based on buildpack, Deployment artifacts |
| Docker Compose/Swarm | Docker compose files | Deployment artifacts |
| Docker Compose/Swarm | Docker compose files, Docker images | Deployment artifacts, Ability to enhance images to run in secure environments like Openshift. |
| Source Directories | Source code with no source metadata | Containerization options based on source code, Deployment artifacts |
| Any source | Access to target cluster | Ability to create artifacts customized for that particular cluster with the most preferred GroupVersion for the kind. |

## Output

* Containerization scripts
* Dockerfile
* Source 2 Image (S2I)
* Cloud Native Buildpack
* Deployment artifacts
* Kubernetes/Openshift Yamls
* Helm charts
* Operator
* Docker compose
21 changes: 21 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Move2Kube

Move2Kube is a command-line tool that accelerates the process of re-platforming to Kubernetes/Openshift. It does so by analysing the environment and source artifacts, and asking guidance from the user when required.

## Setup

1. Ensure that the move2kube executable is in path. `export PATH=$PATH:$PWD`
1. To install dependencies such as `pack`, `kubectl` and `operator-sdk`, invoke `source installdeps.sh`.

## Usage

1. _Plan_ : Place source code in a directory say `src` and generate a plan. For example, you can use the `samples` directory.
`move2kube plan -s src`
1. _Translate_ : In the same directory, invoke the below command.
`move2kube translate`

Note: If information about any runtime instance say cloud foundry or kubernetes cluster needs to be collected use `move2kube collect`. You can place the collected data in the `src` directory used in the plan.

## Contact

For more information, please contact Amith Singhee ([[email protected]](mailto:[email protected])) or Ashok Pon Kumar ([[email protected]](mailto:[email protected]))
72 changes: 72 additions & 0 deletions cmd/move2kube/collect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
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.
*/

package main

import (
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/konveyor/move2kube/internal/move2kube"
"github.com/konveyor/move2kube/types"
)

var (
annotations string
)

const (
annotationsFlag = "annotations"
)

var collectCmd = &cobra.Command{
Use: "collect",
Short: "Collect and process metadata from multiple sources.",
Long: "Collect metadata from multiple sources (cluster, image repo etc.), filter and summarize it into a yaml.",
Run: func(cmd *cobra.Command, args []string) {
if srcpath != "" {
fi, err := os.Stat(srcpath)
if os.IsNotExist(err) {
log.Fatalf("Source directory does not exist: %s.", err)
} else if err != nil {
log.Fatalf("Error while accessing directory: %s. ", srcpath)
} else if !fi.IsDir() {
log.Fatalf("Source path is a file, expected directory: %s.", srcpath)
}
}
outpath = filepath.Join(filepath.Clean(outpath), types.AppNameShort+"_collect")
if annotations == "" {
move2kube.Collect(srcpath, outpath, []string{})
} else {
move2kube.Collect(srcpath, outpath, strings.Split(annotations, ","))
}
log.Infof("Collect Output in [%s]. Copy this directory into the source directory to be used for planning.", outpath)
},
}

func init() {
viper.AutomaticEnv()

collectCmd.Flags().StringVarP(&annotations, annotationsFlag, "a", "", "Specify annotations to select collector subset.")
collectCmd.Flags().StringVarP(&outpath, outpathFlag, "o", ".", "Specify output directory for collect.")
collectCmd.Flags().StringVarP(&srcpath, sourceFlag, "s", "", "Specify source directory for the artifacts to be considered while collecting.")
rootCmd.AddCommand(collectCmd)
}
Loading

0 comments on commit 6b90cbd

Please sign in to comment.