diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..ef9a421832c3eb57aa6998f6cc66d465bd3068a4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,79 @@ +# +# Gitlab CI/CD : Build archive and Docker images and deploy on Openshift +# + +variables: + TRIGRAMME: test #arb @TODO : Change after when the right namespace is available + REPLICA_ENV: 1 + +################################################################################ +# Anchors +################################################################################ +# Build and push anchor +.build_and_push_docker_image: &build_and_push_docker_image + - docker build --pull --tag "$CI_REGISTRY_IMAGE/$IMAGE_NAME:latest" . + - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:latest" + +# Docker Authentification anchor +.docker_login: &docker_login + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + +# Deployment preparation anchor +.prepare_deployment: &prepare_deployment + - export NO_PROXY=grandlyon.fr + - export KUBECONFIG=$KUBECONFIG_DEV + - echo Preparing Deployment on $NAMESPACE + - sed -i "s/__NAMESPACE_ENV__/$NAMESPACE_ENV/g" deployment/job-calqul.yml + +# Applying openshift conf anchor +.apply_confs: &apply_confs + - oc delete jobs --selector job-name=calqul-$NAMESPACE_ENV + - oc create -f deployment/job-calqul.yml + +################################################################################ +# CI/CD Stages +################################################################################ +stages: + - Build Calqul + - Deploy Calqul + +# ********************************************************************************************* +# * BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD * +# ********************************************************************************************* + +Build Calqul: + stage: Build Calqul + variables: + DOCKER_TLS_CERTDIR: "" + NAMESPACE_ENV: "d01" + IMAGE_NAME: calqul-$NAMESPACE_ENV + rules: + - if: $CI_COMMIT_BRANCH == "develop" + - changes: # build image only if sources have changed. + - Dockerfile # Image definition has changed + services: + - docker:dind + script: + - *docker_login + - *build_and_push_docker_image + tags: + - build-push-to-registry + +# ********************************************************************************************* +# * DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLOY DEPLO * +# ********************************************************************************************* + +Deploy Calqul: + stage: Deploy Calqul + rules: + - if: $CI_COMMIT_BRANCH == "develop" + variables: + NAMESPACE_ENV: 'd01' + NAMESPACE: "ns-$TRIGRAMME-$NAMESPACE_ENV" + before_script: + - *prepare_deployment + script: + - *apply_confs + tags: + #- ns-arb-d01 @TODO : Change after when the right namespace is available + - ns-test-d01 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..625448a17cfd8d3256b973ec23ac2226bf325412 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3 + +WORKDIR /usr/src/app + +COPY scripts/requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY ./scripts . + +CMD [ "python", "./hello-world.py" ] \ No newline at end of file diff --git a/README.md b/README.md index e7249a79e83c15cbf8052264c3df773bc623d2b6..007b39a866a92142a77730f97757d6422849f2be 100644 --- a/README.md +++ b/README.md @@ -131,4 +131,4 @@ Doc : - https://docs.openshift.com/container-platform/4.11/nodes/jobs/nodes-nodes-jobs.html ### Suppression d'un job - - https://access.redhat.com/documentation/en-us/openshift_container_platform/3.4/html/developer_guide/dev-guide-scheduled-jobs + - https://access.redhat.com/documentation/en-us/openshift_container_platform/3.4/html/developer_guide/dev-guide-scheduled-jobs \ No newline at end of file diff --git a/deployment/job-calqul.yml b/deployment/job-calqul.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd8edabf0f7a5f3457e18459ac7b34001b2e2855 --- /dev/null +++ b/deployment/job-calqul.yml @@ -0,0 +1,14 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: calqul-__NAMESPACE_ENV__ +spec: + activeDeadlineSeconds: 144000 # maximum duration the job can run => 40h + template: + metadata: + name: calqul-__NAMESPACE_ENV__ + spec: + containers: + - name: calqul-__NAMESPACE_ENV__ + image: registry.forge.grandlyon.com/erasme/script-recalcul-calque/calqul-__NAMESPACE_ENV__ + restartPolicy: Never #OnFailure \ No newline at end of file diff --git a/scripts/hello-world.py b/scripts/hello-world.py new file mode 100644 index 0000000000000000000000000000000000000000..868cb38b166f837940776dea66ab5644e2bced8b --- /dev/null +++ b/scripts/hello-world.py @@ -0,0 +1,6 @@ +# docker run -it --rm --name my-running-script -v /c/Users/ICG4702/Documents/developpements/arb/tests:/usr/src/myapp -w /usr/src/myapp python:3 python hello-world.py + +import time + +print('Hello, World from Docker on OpenShift !') +time.sleep(5) \ No newline at end of file diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391