diff --git a/README.md b/README.md index 1c5df93..eb7dcfc 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# cicdTest \ No newline at end of file +# cicdTest + + +## teamcity + +voor teamcity was het opstellen van de server heel simpel aangezien dit via een docker container kan. +Er moet wel een aparte agent opgesteld worden, maar dit kan ook via een docker container. + +server: + +docker run -it --name teamcity-server-instance \ +-v /Users/beppe/teamcity/data:/data/teamcity_server/datadir \ +-v /Users/beppe/teamcity/logs:/opt/teamcity/logs \ +-p 8080:8111 \ +jetbrains/teamcity-server + +agent: + +docker run -it -e SERVER_URL="localhost:8080" -v /Users/beppe/teamcity/agent/:/data/teamcity_agent/conf jetbrains/teamcity-agent + +de reden dat we een agent nodig hebben is om docker images te builden en pushen. + + + + +## tekton + +https://developer.ibm.com/tutorials/deploy-a-hello-world-application-on-kubernetes-using-tekton-pipelines/ + +https://github.com/tektoncd/pipeline/blob/master/docs/tutorial.md + +install tekton + +kubectl apply --filename https://storage.googleapis.com/tekton-releases/latest/release.yaml + + diff --git a/deploy.yaml b/deploy.yaml index e69de29..d97e01e 100644 --- a/deploy.yaml +++ b/deploy.yaml @@ -0,0 +1,54 @@ +--- +kind: service +apiVersion: v1 +metadata: + name: server-check +spec: + selector: + server: http + ports: + - name: http + protocol: TCP + port: 5000 +--- +kind: service +apiVersion: v1 +metadata: + name: expose-server +spec: + selector: + expose: true + ports: + - name: http + protocol: TCP + targetPort: 5000 + port: 5000 + nodePort: 30036 +--- +apiVersion: v1 +kind: Pod +metadata: + name: server-a + labels: + server: http + expose: true +spec: + containers: + - name: front-end + image: IMAGE-A + ports: + - containerPort: 5000 +--- +apiVersion: v1 +kind: Pod +metadata: + name: server-b + labels: + server: http +spec: + containers: + - name: front-end + image: IMAGE-B + ports: + - containerPort: 5000 + diff --git a/manifests/pipeline/pipeline.yaml b/manifests/pipeline/pipeline.yaml new file mode 100644 index 0000000..c66b20d --- /dev/null +++ b/manifests/pipeline/pipeline.yaml @@ -0,0 +1,86 @@ +apiVersion: tekton.dev/v1alpha1 +kind: Pipeline +metadata: + name: application-pipeline +spec: + resources: + - name: git-source + type: git + params: + - name: pathToYamlFile + description: path to deploy.yaml for final application deploy + default: config.yaml + - name: pathToContext + description: The path to the build context, used by Kaniko - within the workspace + default: . + - name: imageUrl-a + description: Url of image repository a + default: deploy_target + - name: imageTag-a + description: Tag to apply to the built image a + default: latest + - name: pathToContext-a + description: The path to the build context, used by Kaniko - within the workspace + default: . + - name: imageUrl-b + description: Url of image repository + default: deploy_target + - name: imageTag-b + description: Tag to apply to the built image + default: latest + - name: pathToContext-b + description: The path to the build context, used by Kaniko - within the workspace + default: . + tasks: + - name: build-and-push-a + taskRef: + name: build-and-push + params: + - name: pathToContext + value: "$(params.pathToContext-a)" + - name: imageUrl + value: "$(params.imageUrl-a)" + - name: imageTag + value: "$(params.imageTag-a)" + resources: + inputs: + - name: git-source + resource: git-source + - name: build-and-push-b + taskRef: + name: build-and-push + runAfter: + - build-and-push-a + params: + - name: pathToContext + value: "$(params.pathToContext-b)" + - name: imageUrl + value: "$(params.imageUrl-b)" + - name: imageTag + value: "$(params.imageTag-b)" + resources: + inputs: + - name: git-source + resource: git-source + - name: deploy-application + taskRef: + name: deploy-application + runAfter: + - build-and-push-b + params: + - name: pathToContext + value: "$(params.pathToContext)" + - name: pathToYamlFile + value: "$(params.pathToYamlFile)" + - name: imageUrl-a + value: "$(params.imageUrl-a)" + - name: imageTag-a + value: "$(params.imageTag-a)" + - name: imageUrl-b + value: "$(params.imageUrl-b)" + - name: imageTag-b + value: "$(params.imageTag-b)" + resources: + inputs: + - name: git-source + resource: git-source \ No newline at end of file diff --git a/manifests/pipeline/pipelineRun.yaml b/manifests/pipeline/pipelineRun.yaml new file mode 100644 index 0000000..998feda --- /dev/null +++ b/manifests/pipeline/pipelineRun.yaml @@ -0,0 +1,29 @@ +apiVersion: tekton.dev/v1alpha1 +kind: PipelineRun +metadata: + name: application-pipeline-run +spec: + serviceAccountName: tutorial-service + pipelineRef: + name: application-pipeline + resources: + - name: git-source + resourceRef: + name: git + params: + - name: pathToYamlFile + value: "deploy.yaml" + - name: pathToContext + value: "." + - name: imageUrl-a + value: "beppeserver-a" + - name: imageTag-a + value: "beppeserver-a-tag" + - name: pathToContext-a + value: "./serverA" + - name: imageUrl-b + value: "beppeserver-b" + - name: imageTag-b + value: "beppeserver-b-tag" + - name: pathToContext-b + value: "./serverB" \ No newline at end of file diff --git a/manifests/pipeline/serviceAcc.yaml b/manifests/pipeline/serviceAcc.yaml new file mode 100644 index 0000000..dbd47e0 --- /dev/null +++ b/manifests/pipeline/serviceAcc.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tutorial-service +secrets: + - name: regcred \ No newline at end of file diff --git a/manifests/resources/git.yaml b/manifests/resources/git.yaml new file mode 100644 index 0000000..106c6f4 --- /dev/null +++ b/manifests/resources/git.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: tekton.dev/v1alpha1 +kind: PipelineResource +metadata: + name: git +spec: + type: git + params: + - name: revision + value: master + - name: url + value: https://github.com/beppevanrolleghem/cicdTest \ No newline at end of file diff --git a/manifests/tasks/build-and-push.yaml b/manifests/tasks/build-and-push.yaml new file mode 100644 index 0000000..15d8aff --- /dev/null +++ b/manifests/tasks/build-and-push.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: tekton.dev/v1alpha1 +kind: Task +metadata: + name: build-and-push +spec: + inputs: + resources: + - name: git-source + type: git + params: + - name: pathToContext + description: The path to the build context, used by Kaniko - within the workspace + default: . + - name: pathToDockerfile + description: The path to the dockerfile to build + default: Dockerfile + - name: imageUrl + description: value should be like - us.icr.io/test_namespace/builtImageApp + - name: imageTag + description: Tag to apply to the built image + steps: + - name: build-and-push + image: gcr.io/kaniko-project/executor + command: + - /kaniko/executor + args: + - "--dockerfile=$(inputs.params.pathToContext)/dockerfile" + - "--destination=$(inputs.params.imageUrl):$(inputs.params.imageTag)" + - "--context=$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/" \ No newline at end of file diff --git a/manifests/tasks/deploy-application.yaml b/manifests/tasks/deploy-application.yaml new file mode 100644 index 0000000..c8bbc90 --- /dev/null +++ b/manifests/tasks/deploy-application.yaml @@ -0,0 +1,53 @@ +--- +apiVersion: tekton.dev/v1alpha1 +kind: Task +metadata: + name: deploy-application +spec: + inputs: + resources: + - name: git-source + type: git + params: + - name: pathToContext + description: The path to the build context, used by Kaniko - within the workspace + default: . + - name: pathToYamlFile + description: The path to the yaml file to deploy within the git source + default: deploy.yaml + - name: imageUrl-a + description: Url of image repository + default: url + - name: imageTag-a + description: Tag of the images to be used. + default: "latest" + - name: imageUrl-b + description: Url of image repository + default: url + - name: imageTag-b + description: Tag of the images to be used. + default: "latest" + steps: + - name: replace-imagea + image: alpine + command: ["sed"] + args: + - "-i" + - "-e" + - "s;IMAGE-A;$(inputs.params.imageUrl-a):$(inputs.params.imageTag-a);g" + - "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)" + - name: replace-imageb + image: alpine + command: ["sed"] + args: + - "-i" + - "-e" + - "s;IMAGE-b;$(inputs.params.imageUrl-b):$(inputs.params.imageTag-b);g" + - "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)" + - name: deploy-app + image: lachlanevenson/k8s-kubectl + command: ["kubectl"] + args: + - "apply" + - "-f" + - "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)" diff --git a/serverA/__init__.py b/serverA/__init__.py index 9e7a3ed..ab9997a 100644 --- a/serverA/__init__.py +++ b/serverA/__init__.py @@ -3,7 +3,7 @@ import requests app = Flask(__name__) -URL = "http://service" +URL = "http://service:5000" @app.route('/') diff --git a/serverA/dockerfile b/serverA/dockerfile index 5709ecc..10c5891 100644 --- a/serverA/dockerfile +++ b/serverA/dockerfile @@ -7,4 +7,4 @@ run pip install -r requirements.txt expose 5000 entrypoint [ "python" ] -cmd [ "app.py" ] \ No newline at end of file +cmd [ "__init__.py" ] \ No newline at end of file diff --git a/serverB/dockerfile b/serverB/dockerfile index 5709ecc..10c5891 100644 --- a/serverB/dockerfile +++ b/serverB/dockerfile @@ -7,4 +7,4 @@ run pip install -r requirements.txt expose 5000 entrypoint [ "python" ] -cmd [ "app.py" ] \ No newline at end of file +cmd [ "__init__.py" ] \ No newline at end of file