From 8278950bf7400023e67d6a8dc9c9b24fbd79bd1c Mon Sep 17 00:00:00 2001 From: Sciocatti Date: Sat, 7 Jan 2023 18:10:43 +0200 Subject: [PATCH] Bootstrapped from template. --- {template => cicd}/Jenkinsfile | 4 +- cicd/main/Dockerfile | 3 + cicd/main/deployment.yaml | 51 ++++++++++++ cicd/prod/Dockerfile | 3 + {template => cicd/prod}/deployment.yaml | 20 ++--- cicd/stage/Dockerfile | 3 + cicd/stage/deployment.yaml | 51 ++++++++++++ template/start.sh => start.sh | 2 +- template/Dockerfile | 3 - template/setup.sh | 105 ------------------------ 10 files changed, 124 insertions(+), 121 deletions(-) rename {template => cicd}/Jenkinsfile (95%) create mode 100644 cicd/main/Dockerfile create mode 100644 cicd/main/deployment.yaml create mode 100644 cicd/prod/Dockerfile rename {template => cicd/prod}/deployment.yaml (67%) create mode 100644 cicd/stage/Dockerfile create mode 100644 cicd/stage/deployment.yaml rename template/start.sh => start.sh (51%) mode change 100644 => 100755 delete mode 100644 template/Dockerfile delete mode 100755 template/setup.sh diff --git a/template/Jenkinsfile b/cicd/Jenkinsfile similarity index 95% rename from template/Jenkinsfile rename to cicd/Jenkinsfile index 66602ef..a9f0008 100644 --- a/template/Jenkinsfile +++ b/cicd/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { apiVersion: v1 kind: Pod metadata: - name: {{k3sApp}}-env.BRANCH_NAME-build + name: wedding-fe-env.BRANCH_NAME-build spec: serviceAccountName: jenkins-admin containers: @@ -49,7 +49,7 @@ spec: steps { container("kaniko") { sh ''' - /kaniko/executor --dockerfile `pwd`/cicd/env.BRANCH_NAME/Dockerfile --context `pwd` --destination 192.168.195.195:30000/{{k3sApp}}:env.BRANCH_NAME + /kaniko/executor --dockerfile `pwd`/cicd/env.BRANCH_NAME/Dockerfile --context `pwd` --destination 192.168.195.195:30000/wedding-fe:env.BRANCH_NAME ''' } } diff --git a/cicd/main/Dockerfile b/cicd/main/Dockerfile new file mode 100644 index 0000000..3a7e7af --- /dev/null +++ b/cicd/main/Dockerfile @@ -0,0 +1,3 @@ +FROM 192.168.195.195:30001/nginx:latest + +COPY html /usr/share/nginx/html \ No newline at end of file diff --git a/cicd/main/deployment.yaml b/cicd/main/deployment.yaml new file mode 100644 index 0000000..02c0940 --- /dev/null +++ b/cicd/main/deployment.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: Service +metadata: + name: wedding-fe-main-svc + namespace: apps +spec: + type: NodePort + selector: + app: wedding-fe-main + ports: + - name: http + nodePort: 31011 + port: 80 + targetPort: 80 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wedding-fe-main + namespace: apps +spec: + replicas: 1 + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + selector: + matchLabels: + app: wedding-fe-main + template: + metadata: + labels: + app: wedding-fe-main + delpoymentDate: "{{replaceMe}}" + spec: + containers: + - name: wedding-fe-main + image: 192.168.195.195:30000/wedding-fe:main + imagePullPolicy: Always + ports: + - name: http + containerPort: 80 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 5 + successThreshold: 1 \ No newline at end of file diff --git a/cicd/prod/Dockerfile b/cicd/prod/Dockerfile new file mode 100644 index 0000000..3a7e7af --- /dev/null +++ b/cicd/prod/Dockerfile @@ -0,0 +1,3 @@ +FROM 192.168.195.195:30001/nginx:latest + +COPY html /usr/share/nginx/html \ No newline at end of file diff --git a/template/deployment.yaml b/cicd/prod/deployment.yaml similarity index 67% rename from template/deployment.yaml rename to cicd/prod/deployment.yaml index 73dfbcb..3cfbf3b 100644 --- a/template/deployment.yaml +++ b/cicd/prod/deployment.yaml @@ -1,15 +1,15 @@ apiVersion: v1 kind: Service metadata: - name: {{k3sApp}}-{{k3sEnv}}-svc - namespace: {{k3sNamespace}} + name: wedding-fe-prod-svc + namespace: apps spec: type: NodePort selector: - app: {{k3sApp}}-{{k3sEnv}} + app: wedding-fe-prod ports: - name: http - nodePort: {{k3sport}} + nodePort: 31010 port: 80 targetPort: 80 @@ -17,8 +17,8 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: - name: {{k3sApp}}-{{k3sEnv}} - namespace: {{k3sNamespace}} + name: wedding-fe-prod + namespace: apps spec: replicas: 2 strategy: @@ -28,16 +28,16 @@ spec: type: RollingUpdate selector: matchLabels: - app: {{k3sApp}}-{{k3sEnv}} + app: wedding-fe-prod template: metadata: labels: - app: {{k3sApp}}-{{k3sEnv}} + app: wedding-fe-prod delpoymentDate: "{{replaceMe}}" spec: containers: - - name: {{k3sApp}}-{{k3sEnv}} - image: 192.168.195.195:30000/{{k3sApp}}:{{k3sEnv}} + - name: wedding-fe-prod + image: 192.168.195.195:30000/wedding-fe:prod imagePullPolicy: Always ports: - name: http diff --git a/cicd/stage/Dockerfile b/cicd/stage/Dockerfile new file mode 100644 index 0000000..3a7e7af --- /dev/null +++ b/cicd/stage/Dockerfile @@ -0,0 +1,3 @@ +FROM 192.168.195.195:30001/nginx:latest + +COPY html /usr/share/nginx/html \ No newline at end of file diff --git a/cicd/stage/deployment.yaml b/cicd/stage/deployment.yaml new file mode 100644 index 0000000..81c2163 --- /dev/null +++ b/cicd/stage/deployment.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: Service +metadata: + name: wedding-fe-stage-svc + namespace: apps +spec: + type: NodePort + selector: + app: wedding-fe-stage + ports: + - name: http + nodePort: 31012 + port: 80 + targetPort: 80 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wedding-fe-stage + namespace: apps +spec: + replicas: 1 + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + selector: + matchLabels: + app: wedding-fe-stage + template: + metadata: + labels: + app: wedding-fe-stage + delpoymentDate: "{{replaceMe}}" + spec: + containers: + - name: wedding-fe-stage + image: 192.168.195.195:30000/wedding-fe:stage + imagePullPolicy: Always + ports: + - name: http + containerPort: 80 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 5 + successThreshold: 1 \ No newline at end of file diff --git a/template/start.sh b/start.sh old mode 100644 new mode 100755 similarity index 51% rename from template/start.sh rename to start.sh index a3fb74e..9aef9ad --- a/template/start.sh +++ b/start.sh @@ -3,4 +3,4 @@ echo "" echo "Starting an Nginx container listening on http://localhost:3000" echo "" echo "" -docker run --rm -v $(pwd)/html/:/usr/share/nginx/html/ -p {{localPort}}:80 {{localContainer}} \ No newline at end of file +docker run --rm -v $(pwd)/html/:/usr/share/nginx/html/ -p 3030:80 192.168.195.195:30001/nginx:latest \ No newline at end of file diff --git a/template/Dockerfile b/template/Dockerfile deleted file mode 100644 index a0cee5e..0000000 --- a/template/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM {{k3sContainerBase}} - -COPY html /usr/share/nginx/html \ No newline at end of file diff --git a/template/setup.sh b/template/setup.sh deleted file mode 100755 index cecb710..0000000 --- a/template/setup.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash - -#./setup.sh 3000 192.168.195.195:30000/nginx:latest cicd/Jenkinsfile - -folderName=${PWD##*/} -folderName=${folderName:-/} - -echo "Hello, lets get your project set up. Please follow the prompts attentively." - -read -p "Do you want to run this project locally? [Yn] " localProject - -if [ $localProject == 'Y' ] || [ $localProject == 'y' ] -then - echo "Configuring local settings" - read -p " Local port to expose server on? [eg 3000] " localPort - read -p " NGINX container to use? [eg nginx/nginx:latest] " localContainer - - echo " Creating start script" - cp template/start.sh start.sh - sed -ie "s|{{localPort}}|$localPort|g" start.sh - sed -ie "s|{{localContainer}}|$localContainer|g" start.sh - chmod +x start.sh - rm start.she -fi - -read -p "Are you deploying this with the Sciocatti Jenkins pipeline? [Yn] " useJenkins - -if [ $useJenkins == 'Y' ] || [ $useJenkins == 'y' ] -then - echo "Configuring deployment settings. See the Readme for info on deployable branches." - read -p " K3S App name: " k3sApp - read -p " K3S namespace: [eg apps] " k3sNamespace - read -p " K3S base container: [eg nginx:nginx:latest] " k3sContainerBase - read -p " K3S prod NodePort: " k3sport - - k3sportMain=$((k3sport+1)) - k3sportStage=$((k3sport+2)) - - echo "Creating Folders" - echo " Creating cicd/" - mkdir cicd - echo " Creating cicd/prod" - mkdir cicd/prod - echo " Creating cicd/main" - mkdir cicd/main - echo " Creating cicd/stage" - mkdir cicd/stage - - echo "Loading files" - echo " Loading cicd/Jenkinsfile" - cp template/Jenkinsfile cicd/Jenkinsfile - sed -ie "s|{{k3sApp}}|$k3sApp|g" cicd/Jenkinsfile - rm cicd/Jenkinsfilee - - echo " Loading main" - k3sEnv=main - echo " Loading cicd/main/Dockerfile" - cp template/Dockerfile cicd/main/Dockerfile - sed -ie "s|{{k3sContainerBase}}|$k3sContainerBase|g" cicd/main/Dockerfile - rm cicd/main/Dockerfilee - - echo " Loading cicd/main/deployment.yaml" - cp template/deployment.yaml cicd/main/deployment.yaml - sed -ie "s|{{k3sApp}}|$k3sApp|g" cicd/main/deployment.yaml - sed -ie "s|{{k3sport}}|$k3sportMain|g" cicd/main/deployment.yaml - sed -ie "s|{{k3sNamespace}}|$k3sNamespace|g" cicd/main/deployment.yaml - sed -ie "s|{{k3sEnv}}|$k3sEnv|g" cicd/main/deployment.yaml - rm cicd/main/deployment.yamle - - echo " Loading stage" - k3sEnv=stage - echo " Loading cicd/stage/Dockerfile" - cp template/Dockerfile cicd/stage/Dockerfile - sed -ie "s|{{k3sContainerBase}}|$k3sContainerBase|g" cicd/stage/Dockerfile - rm cicd/stage/Dockerfilee - - echo " Loading cicd/stage/deployment.yaml" - cp template/deployment.yaml cicd/stage/deployment.yaml - sed -ie "s|{{k3sApp}}|$k3sApp|g" cicd/stage/deployment.yaml - sed -ie "s|{{k3sport}}|$k3sportStage|g" cicd/stage/deployment.yaml - sed -ie "s|{{k3sNamespace}}|$k3sNamespace|g" cicd/stage/deployment.yaml - sed -ie "s|{{k3sEnv}}|$k3sEnv|g" cicd/stage/deployment.yaml - rm cicd/stage/deployment.yamle - - echo " Loading prod" - k3sEnv=prod - echo " Loading cicd/prod/Dockerfile" - cp template/Dockerfile cicd/prod/Dockerfile - sed -ie "s|{{k3sContainerBase}}|$k3sContainerBase|g" cicd/prod/Dockerfile - rm cicd/prod/Dockerfilee - - echo " Loading cicd/prod/deployment.yaml" - cp template/deployment.yaml cicd/prod/deployment.yaml - sed -ie "s|{{k3sApp}}|$k3sApp|g" cicd/prod/deployment.yaml - sed -ie "s|{{k3sport}}|$k3sport|g" cicd/prod/deployment.yaml - sed -ie "s|{{k3sNamespace}}|$k3sNamespace|g" cicd/prod/deployment.yaml - sed -ie "s|{{k3sEnv}}|$k3sEnv|g" cicd/prod/deployment.yaml - rm cicd/prod/deployment.yamle - -fi - -echo "Removing template folder" -rm -rf template - -echo "Thank you! Happy building..." \ No newline at end of file