diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..766ca6e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.7 +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +CMD python web.py diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b29ce04 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,18 @@ +pipeline { + agent any + stages { + stage('Docker Build') { + steps { + sh 'docker build -t conroy3644/sba2022.kube:latest .' + } + } + stage('Docker Push') { + steps { + withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) { + sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}" + sh 'docker push conroy3644/sba2022.kube:latest' + } + } + } + } +} diff --git a/check-cluster.sh b/check-cluster.sh new file mode 100755 index 0000000..dc9aa8b --- /dev/null +++ b/check-cluster.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +kubectl get pods >> /home/osboxes/sba2022.kubernetes-cluster/submission/check-cluster-output.txt +kubectl get nodes >> /home/osboxes/sba2022.kubernetes-cluster/submission/check-cluster-output.txt +kubectl get deployments >> /home/osboxes/sba2022.kubernetes-cluster/submission/check-cluster-output.txt diff --git a/kubernetes.yml b/kubernetes.yml new file mode 100644 index 0000000..fffff60 --- /dev/null +++ b/kubernetes.yml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Pod +metadata: + name: sba2022pod +spec: + containers: + - name: sba2022container + image: conroy3644/sba2022.kube:latest + ports: + - containerPort: 8080 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8fc2f61 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +flask_restful diff --git a/submission/SBA2022-Flask-on-Kubernetes.png b/submission/SBA2022-Flask-on-Kubernetes.png new file mode 100644 index 0000000..9511bf2 Binary files /dev/null and b/submission/SBA2022-Flask-on-Kubernetes.png differ diff --git a/submission/check-cluster-output.txt b/submission/check-cluster-output.txt new file mode 100644 index 0000000..25a85cc --- /dev/null +++ b/submission/check-cluster-output.txt @@ -0,0 +1,13 @@ +NAME READY UP-TO-DATE AVAILABLE AGE +balanced 1/1 1 1 6d3h +hello-minikube 1/1 1 1 6d3h +NAME READY STATUS RESTARTS AGE +balanced-5744b548b4-jq7x6 1/1 Running 2 (30h ago) 6d3h +hello-minikube-6ddfcc9757-lzwcw 1/1 Running 2 (30h ago) 6d3h +mysql-client 1/1 Running 0 24h +sba2022pod 1/1 Running 0 8m10s +NAME STATUS ROLES AGE VERSION +minikube Ready control-plane,master 6d4h v1.22.3 +NAME READY UP-TO-DATE AVAILABLE AGE +balanced 1/1 1 1 6d3h +hello-minikube 1/1 1 1 6d3h diff --git a/submission/dockerhub-repo.txt b/submission/dockerhub-repo.txt new file mode 100644 index 0000000..00c3023 --- /dev/null +++ b/submission/dockerhub-repo.txt @@ -0,0 +1 @@ +https://hub.docker.com/repository/docker/conroy3644/sba2022.kube diff --git a/submission/jenkins-output.txt b/submission/jenkins-output.txt new file mode 100644 index 0000000..77c5a21 --- /dev/null +++ b/submission/jenkins-output.txt @@ -0,0 +1,143 @@ +This is Jenkins console output after successfully building image from local Dockerfile and pushing it to Dockerhub + + +Started by user Max C +Obtained Jenkinsfile from git https://github.com/max-conroy/sba2022.kubernetes-cluster.git +[Pipeline] Start of Pipeline +[Pipeline] node +Running on Jenkins in /var/lib/jenkins/workspace/sba2022-job +[Pipeline] { +[Pipeline] stage +[Pipeline] { (Declarative: Checkout SCM) +[Pipeline] checkout +Selected Git installation does not exist. Using Default +The recommended git tool is: NONE +No credentials specified + > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/sba2022-job/.git # timeout=10 +Fetching changes from the remote Git repository + > git config remote.origin.url https://github.com/max-conroy/sba2022.kubernetes-cluster.git # timeout=10 +Fetching upstream changes from https://github.com/max-conroy/sba2022.kubernetes-cluster.git + > git --version # timeout=10 + > git --version # 'git version 2.25.1' + > git fetch --tags --force --progress -- https://github.com/max-conroy/sba2022.kubernetes-cluster.git +refs/heads/*:refs/remotes/origin/* # timeout=10 + > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 +Checking out Revision 905eb53be8d4516acafaafb3d6555193c0ce8521 (refs/remotes/origin/master) + > git config core.sparsecheckout # timeout=10 + > git checkout -f 905eb53be8d4516acafaafb3d6555193c0ce8521 # timeout=10 +Commit message: "Updated Jenkinsfile" + > git rev-list --no-walk 418493be5d1513ef240f648b5549fb9a58ef35e0 # timeout=10 +[Pipeline] } +[Pipeline] // stage +[Pipeline] withEnv +[Pipeline] { +[Pipeline] stage +[Pipeline] { (Docker Build) +[Pipeline] sh ++ docker build -t conroy3644/sba2022.kube:latest . +Sending build context to Docker daemon 7.495MB + +Step 1/4 : FROM python:3.7 + ---> ad37de9b03ef +Step 2/4 : COPY . /app + ---> 811e49bb0c8c +Step 3/4 : WORKDIR /app + ---> Running in 9dfdcde94a35 +Removing intermediate container 9dfdcde94a35 + ---> 88aedf98a729 +Step 4/4 : RUN pip install -r requirements.txt + ---> Running in 2d03125b577e +Collecting flask + Downloading Flask-2.0.2-py3-none-any.whl (95 kB) +Collecting flask_restful + Downloading Flask_RESTful-0.3.9-py2.py3-none-any.whl (25 kB) +Collecting Jinja2>=3.0 + Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB) +Collecting Werkzeug>=2.0 + Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB) +Collecting click>=7.1.2 + Downloading click-8.0.3-py3-none-any.whl (97 kB) +Collecting itsdangerous>=2.0 + Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB) +Collecting pytz + Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB) +Collecting six>=1.3.0 + Downloading six-1.16.0-py2.py3-none-any.whl (11 kB) +Collecting aniso8601>=0.82 + Downloading aniso8601-9.0.1-py2.py3-none-any.whl (52 kB) +Collecting importlib-metadata + Downloading importlib_metadata-4.10.0-py3-none-any.whl (17 kB) +Collecting MarkupSafe>=2.0 + Downloading MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (31 kB) +Collecting typing-extensions>=3.6.4 + Downloading typing_extensions-4.0.1-py3-none-any.whl (22 kB) +Collecting zipp>=0.5 + Downloading zipp-3.7.0-py3-none-any.whl (5.3 kB) +Installing collected packages: zipp, typing-extensions, MarkupSafe, importlib-metadata, Werkzeug, Jinja2, itsdangerous, click, six, pytz, flask, aniso8601, flask-restful +Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 aniso8601-9.0.1 click-8.0.3 flask-2.0.2 flask-restful-0.3.9 importlib-metadata-4.10.0 itsdangerous-2.0.1 pytz-2021.3 six-1.16.0 typing-extensions-4.0.1 zipp-3.7.0 +1mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv +1mWARNING: You are using pip version 21.2.4; however, version 21.3.1 is available. +You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command. +Removing intermediate container 2d03125b577e + ---> f9776816f2e9 +Successfully built f9776816f2e9 +Successfully tagged conroy3644/sba2022.kube:latest +[Pipeline] } +[Pipeline] // stage +[Pipeline] stage +[Pipeline] { (Docker Push) +[Pipeline] withCredentials +Masking supported pattern matches of $dockerHubPassword +[Pipeline] { +[Pipeline] sh +Warning: A secret was passed to "sh" using Groovy String interpolation, which is insecure. + Affected argument(s) used the following variable(s): [dockerHubPassword] + See https://jenkins.io/redirect/groovy-string-interpolation for details. ++ docker login -u conroy3644 -p **** +WARNING! Using --password via the CLI is insecure. Use --password-stdin. +WARNING! Your password will be stored unencrypted in /var/lib/jenkins/.docker/config.json. +Configure a credential helper to remove this warning. See +https://docs.docker.com/engine/reference/commandline/login/#credentials-store + +Login Succeeded +[Pipeline] sh ++ docker push conroy3644/sba2022.kube:latest +The push refers to repository [docker.io/conroy3644/sba2022.kube] +d835b42882d7: Preparing +b75b9ca6595f: Preparing +11088eb5307c: Preparing +d86f8b9fa813: Preparing +86c81640d929: Preparing +aedcb370b058: Preparing +c3a0d593ed24: Preparing +26a504e63be4: Preparing +8bf42db0de72: Preparing +31892cc314cb: Preparing +11936051f93b: Preparing +aedcb370b058: Waiting +c3a0d593ed24: Waiting +26a504e63be4: Waiting +8bf42db0de72: Waiting +31892cc314cb: Waiting +11936051f93b: Waiting +86c81640d929: Layer already exists +d86f8b9fa813: Layer already exists +11088eb5307c: Layer already exists +aedcb370b058: Layer already exists +c3a0d593ed24: Layer already exists +26a504e63be4: Layer already exists +8bf42db0de72: Layer already exists +31892cc314cb: Layer already exists +11936051f93b: Layer already exists +b75b9ca6595f: Pushed +d835b42882d7: Pushed +latest: digest: sha256:49499265e3a1885f674f569622687937c4e5838e8068f1b8cf7aa3470078549e size: 2640 +[Pipeline] } +[Pipeline] // withCredentials +[Pipeline] } +[Pipeline] // stage +[Pipeline] } +[Pipeline] // withEnv +[Pipeline] } +[Pipeline] // node +[Pipeline] End of Pipeline +Finished: SUCCESS