From eabd4f4901d9f0d15b74a4143bfce36cc3f634b1 Mon Sep 17 00:00:00 2001 From: Julien Maupetit Date: Mon, 3 Sep 2018 17:09:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(richie)=20add=20ImageStream=20and=20B?= =?UTF-8?q?uildConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Service pods are now based on a locally built image instead of DockerHub's raw image. This allows us to add project-specific contrains or customization. --- apps/richie/templates/app/bc.yml.j2 | 38 +++++++++++++++++++ apps/richie/templates/app/dc.yml.j2 | 6 ++- apps/richie/templates/app/is.yml.j2 | 8 ++++ .../templates/app/job_collectstatic.yml.j2 | 4 +- .../templates/app/job_db_migrate.yml.j2 | 4 +- .../app/job_regenerate_indexes.yml.j2 | 4 +- 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 apps/richie/templates/app/bc.yml.j2 create mode 100644 apps/richie/templates/app/is.yml.j2 diff --git a/apps/richie/templates/app/bc.yml.j2 b/apps/richie/templates/app/bc.yml.j2 new file mode 100644 index 000000000..4e80b9128 --- /dev/null +++ b/apps/richie/templates/app/bc.yml.j2 @@ -0,0 +1,38 @@ +apiVersion: "v1" +kind: "BuildConfig" +metadata: + # FIXME + # + # As mentionned in the official documentation [1]: + # + # Configuration change triggers currently only work when creating a new + # BuildConfig. In a future release, configuration change triggers will also + # be able to launch a build whenever a BuildConfig is updated. + # + # Hence, we must force BuildConfig to always get created with a unique name. + # This is a temporary solution that needs to be improved as soon as OKD + # triggers a new build upon BC object update. + # + # References: + # + # 1. https://docs.okd.io/latest/dev_guide/builds/triggering_builds.html#config-change-triggers + name: "richie-{{ deployment_stamp }}" + namespace: "{{ project_name }}" + labels: + app: "richie" + service: "richie" + version: "{{ richie_image_tag }}" + deployment_stamp: "{{ deployment_stamp }}" +spec: + strategy: + type: Docker + source: + dockerfile: |- + FROM {{ richie_image_name }}:{{ richie_image_tag }} + # Add new statements here + triggers: + - type: "ConfigChange" + output: + to: + kind: "ImageStreamTag" + name: "richie:{{ richie_image_tag }}-live" diff --git a/apps/richie/templates/app/dc.yml.j2 b/apps/richie/templates/app/dc.yml.j2 index ac2ac7a63..974835e81 100644 --- a/apps/richie/templates/app/dc.yml.j2 +++ b/apps/richie/templates/app/dc.yml.j2 @@ -9,7 +9,7 @@ metadata: name: "richie-app-{{ deployment_stamp }}" namespace: "{{ project_name }}" spec: - replicas: 1 # number of pods we want + replicas: 1 # number of pods we want template: metadata: labels: @@ -21,7 +21,9 @@ spec: spec: containers: - name: richie - image: "{{ richie_image_name }}:{{ richie_image_tag }}" + # We point to a local registry image build for this "live" image (see + # ImageStream and BuildConfig templates) + image: "{{ internal_docker_registry }}/{{ project_name }}/richie:{{ richie_image_tag }}-live" imagePullPolicy: IfNotPresent env: - name: DJANGO_SETTINGS_MODULE diff --git a/apps/richie/templates/app/is.yml.j2 b/apps/richie/templates/app/is.yml.j2 new file mode 100644 index 000000000..d3c737e09 --- /dev/null +++ b/apps/richie/templates/app/is.yml.j2 @@ -0,0 +1,8 @@ +apiVersion: "v1" +kind: "ImageStream" +metadata: + name: "richie" + namespace: "{{ project_name }}" + labels: + app: "richie" + service: "richie" diff --git a/apps/richie/templates/app/job_collectstatic.yml.j2 b/apps/richie/templates/app/job_collectstatic.yml.j2 index e1542ba53..395c6549c 100644 --- a/apps/richie/templates/app/job_collectstatic.yml.j2 +++ b/apps/richie/templates/app/job_collectstatic.yml.j2 @@ -38,7 +38,9 @@ spec: envFrom: - secretRef: name: richie-{{ secret_id }} - image: "{{ richie_image_name }}:{{ richie_image_tag }}" + # We point to a local registry image build for this "live" image (see + # ImageStream and BuildConfig templates) + image: "{{ internal_docker_registry }}/{{ project_name }}/richie:{{ richie_image_tag }}-live" command: ["python", "manage.py", "collectstatic", "--noinput"] volumeMounts: - mountPath: /data/static diff --git a/apps/richie/templates/app/job_db_migrate.yml.j2 b/apps/richie/templates/app/job_db_migrate.yml.j2 index 747b0092b..6da67f29e 100644 --- a/apps/richie/templates/app/job_db_migrate.yml.j2 +++ b/apps/richie/templates/app/job_db_migrate.yml.j2 @@ -38,6 +38,8 @@ spec: envFrom: - secretRef: name: richie-{{ secret_id }} - image: "{{ richie_image_name }}:{{ richie_image_tag }}" + # We point to a local registry image build for this "live" image (see + # ImageStream and BuildConfig templates) + image: "{{ internal_docker_registry }}/{{ project_name }}/richie:{{ richie_image_tag }}-live" command: ["python", "manage.py", "migrate"] restartPolicy: Never diff --git a/apps/richie/templates/app/job_regenerate_indexes.yml.j2 b/apps/richie/templates/app/job_regenerate_indexes.yml.j2 index 08a615883..6138130e2 100644 --- a/apps/richie/templates/app/job_regenerate_indexes.yml.j2 +++ b/apps/richie/templates/app/job_regenerate_indexes.yml.j2 @@ -40,6 +40,8 @@ spec: envFrom: - secretRef: name: richie-{{ secret_id }} - image: "{{ richie_image_name }}:{{ richie_image_tag }}" + # We point to a local registry image build for this "live" image (see + # ImageStream and BuildConfig templates) + image: "{{ internal_docker_registry }}/{{ project_name }}/richie:{{ richie_image_tag }}-live" command: ["python", "manage.py", "regenerate_indexes"] restartPolicy: Never