diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..43b7a5b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: python + +python: +- "3.9" + +env: + - VERSION=10.0.1 + +services: + - docker + +before_install: + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - curl -LO https://dist.xebialabs.com/public/xl-cli/$VERSION/linux-amd64/xl + - chmod +x xl + +script: + - make all \ No newline at end of file diff --git a/docker/Dockerfile b/Dockerfile similarity index 79% rename from docker/Dockerfile rename to Dockerfile index ce620c2..96ce93a 100644 --- a/docker/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3.7 -RUN mkdir /app +#RUN mkdir /app WORKDIR /app -ADD . /app/ +ADD /app/ . RUN pip install -r requirements.txt EXPOSE 5000 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b0c8b3f --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +REPO ?= danberg/hello-py +TAG ?= $(shell git rev-parse --short HEAD) +IMAGE := $(REPO):$(TAG) +LATEST_IMAGE := $(REPO):latest + +all: docker-build docker-push timestamp + +docker-build: + docker build -t $(IMAGE) -f Dockerfile . + docker tag $(IMAGE) $(LATEST_IMAGE) +docker-push: + docker push $(IMAGE) + docker push $(LATEST_IMAGE) +timestamp: + date diff --git a/app/main.py b/app/main.py index 5aff7f2..bd4a91e 100644 --- a/app/main.py +++ b/app/main.py @@ -3,7 +3,7 @@ @app.route("/") def hello(): - return "Hello from Python!" + return "Hello Friends from Python!" if __name__ == "__main__": app.run(host='0.0.0.0') diff --git a/build_spec.yaml b/build_spec.yaml new file mode 100644 index 0000000..a19f85f --- /dev/null +++ b/build_spec.yaml @@ -0,0 +1,62 @@ +version: 0.1 +component: build +timeoutInSeconds: 6000 +shell: bash + +# Variables +env: + exportedVariables: + - TAG_VERSION + - COMMIT + vaultVariables: + docker_registry_password : ocid1.vaultsecret.oc1.phx.amaaaaaayat6pyaacvggvlf6hmbgqguquempfl73xfo7fce5r4tiqh5ulgjq + +inputArtifacts: + +steps: + - type: Command + name: "Export image tag" + timeoutInSeconds: 400 + command: | + export TAG_VERSION=`echo ${OCI_BUILD_RUN_ID} | tail -c 8` + - type: Command + name: "Export commit tag" + timeoutInSeconds: 200 + command: | + export COMMIT=`git rev-parse --short HEAD` + - type: Command + name: "Echo Variables" + command: | + echo "TAG_VERSION = " $TAG_VERSION + echo "COMMIT = " $COMMIT + - type: Command + timeoutInSeconds: 400 + name: "Docker Build" + command: | + docker build -t danberg/hello-py -f Dockerfile . + docker tag danberg/hello-py:latest danberg/hello-py:$TAG_VERSION + onFailure: + - type: Command + command: | + echo "Handling image build failure" + build_result=FAILURE + echo "Image build failure successfully handled" + timeoutInSeconds: 400 + - type: Command + timeoutInSeconds: 600 + name: "Log into Dockerhub" + command: | + docker login -u "danberg" -p ${docker_registry_password} + - type: Command + timeoutInSeconds: 400 + name: "Push image to Dockerhub with proper tag" + command: | + docker push danberg/hello-py:$TAG_VERSION + +outputArtifacts: + - name: deployment-manifest + type: BINARY + location: ${OCI_PRIMARY_SOURCE_DIR}/kubernetes/deployment_oke.yaml + - name: hello-image + type: DOCKER_IMAGE + location: danberg/hello-py \ No newline at end of file diff --git a/build_spec_mirror.yaml b/build_spec_mirror.yaml new file mode 100644 index 0000000..9d1e099 --- /dev/null +++ b/build_spec_mirror.yaml @@ -0,0 +1,29 @@ +version: 0.1 +component: build +timeoutInSeconds: 6000 +shell: bash + +steps: + - type: Command + name: "Download OCI" + timeoutInSeconds: 400 + command: | + oci -v + curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh --output ${OCI_WORKSPACE_DIR}/install_oci.sh + - type: Command + name: "Remove existing OCI install dir" + timeoutInSeconds: 60 + command: | + rm -r /root/lib/oracle-cli + - type: Command + name: "Update OCI CLI" + timeoutInSeconds: 400 + command: | + chmod +x ${OCI_WORKSPACE_DIR}/install_oci.sh + ${OCI_WORKSPACE_DIR}/install_oci.sh --accept-all-defaults + - type: Command + name: "Mirror remote repo" + timeoutInSeconds: 400 + command: | + oci -v + oci devops repository mirror --repository-id ocid1.devopsrepository.oc1.phx.amaaaaaayat6pyaah6x6oynezgenfvpj4qwcb4fdpy2jzvjkmr6rizuoovrq \ No newline at end of file diff --git a/dai-deploy/hello-python-deploy.yaml b/dai-deploy/hello-python-deploy.yaml new file mode 100644 index 0000000..3365daa --- /dev/null +++ b/dai-deploy/hello-python-deploy.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: xl-deploy/v1 +kind: Applications +spec: +- name: Applications/HelloPy + type: udm.Application + children: + - name: d120bb2 + type: udm.DeploymentPackage + deployables: + - name: hello-py-deploy.yaml + type: k8s.ResourcesFile + placeholders: + - image_tag + - ingress_host + fileEncodings: + ".+\\.properties": ISO-8859-1 + mergePatchType: strategic + propagationPolicy: Foreground + updateMethod: apply + createOrder: "60" + modifyOrder: "50" + destroyOrder: "40" + displayResourceOnLogs: "false" + showContainerLogs: "false" + bytesToReadFromContainerLogs: "4000" + file: !file "../kubernetes/deployment.yaml" \ No newline at end of file diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml index fdaeb8e..b23c76b 100644 --- a/kubernetes/deployment.yaml +++ b/kubernetes/deployment.yaml @@ -1,32 +1,58 @@ apiVersion: v1 kind: Service metadata: - name: hello-python-service + name: hello-py-svc spec: selector: - app: hello-python + app: hello-py ports: - protocol: "TCP" port: 6000 targetPort: 5000 - type: LoadBalancer - - + type: ClusterIP --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: - name: hello-python + labels: + app: hello-py + name: hello-py spec: - replicas: 4 + replicas: 3 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + selector: + matchLabels: + app: hello-py template: metadata: labels: - app: hello-python + app: hello-py spec: containers: - - name: hello-python - image: hello-python:latest - imagePullPolicy: Never + - image: "danberg/hello-py:{{image_tag}}" + name: hello-py ports: - - containerPort: 5000 + - containerPort: 5000 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: hello-py-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: /$2 +spec: + rules: + - host: "{{ingress_host}}" + http: + paths: + - path: /hellopy(/|$)(.*) + pathType: Prefix + backend: + service: + name: hello-py-svc + port: + number: 6000 diff --git a/kubernetes/deployment_oke.yaml b/kubernetes/deployment_oke.yaml new file mode 100644 index 0000000..d074667 --- /dev/null +++ b/kubernetes/deployment_oke.yaml @@ -0,0 +1,58 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-py-svc +spec: + selector: + app: hello-py + ports: + - protocol: "TCP" + port: 6000 + targetPort: 5000 + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: hello-py + name: hello-py +spec: + replicas: 3 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + selector: + matchLabels: + app: hello-py + template: + metadata: + labels: + app: hello-py + spec: + containers: + - image: "danberg/hello-py:${TAG_VERSION}" + name: hello-py + ports: + - containerPort: 5000 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: hello-py-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: /$2 +spec: + rules: + - host: "${ingress_host}" + http: + paths: + - path: /hellopy(/|$)(.*) + pathType: Prefix + backend: + service: + name: hello-py-svc + port: + number: 6000