From 27fcb8b6ec716ae51e45b68de39d89671c6b397a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 3 Nov 2022 21:49:56 +0100 Subject: [PATCH 01/14] create template env for build image --- inventory/group_vars/local | 8 ++++++-- inventory/group_vars/local_vault | 24 ++++++++++++++---------- inventory/hosts | 1 + scaleway-k8s/templates/env-build.j2 | 7 +++++++ scaleway-k8s/templates/main.tf.j2 | 4 ++-- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/inventory/group_vars/local b/inventory/group_vars/local index 9e72108..e0943cc 100644 --- a/inventory/group_vars/local +++ b/inventory/group_vars/local @@ -1,4 +1,8 @@ project_terraform: "/home/valentin/terraform" region_k8s: "fr-par" -project_name: "terraform-test" -quarkus_project: "covas-quarkus" \ No newline at end of file +project_name_tf: "terraform-test" +quarkus_project: "covas-quarkus" + +mailer_host: "smtp.gmail.com" +mailer_from: "valczebackup@gmail.com" +mailer_port: "587" \ No newline at end of file diff --git a/inventory/group_vars/local_vault b/inventory/group_vars/local_vault index c9ed39a..e330945 100644 --- a/inventory/group_vars/local_vault +++ b/inventory/group_vars/local_vault @@ -1,11 +1,15 @@ $ANSIBLE_VAULT;1.1;AES256 -30366237393836333338316164656633656435383866666462663830643463633064356261396431 -3066613335326464373833346430373663333736353537630a653934316366383165346238663134 -30376439373634323636613566373534353138653964613236326464653662306136653964313861 -6135623361346639650a646533383761393435303833336138346164633161613739323765323664 -65623039633039343039303931626138316132613433666136633336326433653561343761316363 -66666230343165383130353939303633623264663161663030336533663437363630383565353064 -35376633323564623361613663356230663664323261383564653433656638306432343132343631 -32386232316234643464326533303065653535633064393438663931336334373965313064386532 -66306664303937356636366564623830623764386136663830636634326438373963666134613430 -6530323937303637393934376466396565343133613736663166 +65363666393931336562303562336163356633643832646633383864346538386436613363316661 +3766663332623564646630633232393830326262626231330a363035363237653930656362633561 +65666133376131643366393234623861613862646466383038656536656466343134666135363333 +3733313835383034380a643063373765356637373332636264653539363963326366646664336431 +66613265623364383933326165383162366464633037323366303931636136623835313334623131 +31666161623238346631316236643735653134306536663538646437343066323930383261646161 +62616361303630333230346263343937633461396362613963626433623264333039306530396136 +65623163383965326161383238366564393632323830333336623839636564623535643463356666 +61326634663834636336313233306535646366363437346262323939613937333831646466326264 +65363534303037376166663363306433303633383662316235343634343035323838663931613733 +33326563323332353765666639643462353935303064626266643339623238316233383837396631 +65376264346139353939396538313837636333643239623532333636653364646137356439323833 +35363730643336376361656366666136313431613337363533643539373865663766653161366530 +6339316532613964626139336236346635643638633439376662 diff --git a/inventory/hosts b/inventory/hosts index 093d215..5c5d87d 100644 --- a/inventory/hosts +++ b/inventory/hosts @@ -5,6 +5,7 @@ localhost ansible_host=127.0.0.1 [db] vps +localhost [db_vault:children] db diff --git a/scaleway-k8s/templates/env-build.j2 b/scaleway-k8s/templates/env-build.j2 index 6851bde..c6b9915 100644 --- a/scaleway-k8s/templates/env-build.j2 +++ b/scaleway-k8s/templates/env-build.j2 @@ -5,3 +5,10 @@ POSTGRES_URL={{ postgres_url }} POSTGRES_PORT={{ postgres_port }} REDIS_URL={{ redis_url }} REDIS_PORT={{ redis_port }} + + +MAILER_FROM={{ mailer_from }} +MAILER_HOST={{ mailer_host }} +MAILER_PORT={{ mailer_port }} +MAILER_USERNAME={{ mailer_username }} +MAILER_PASSWORD={{ mailer_password }} \ No newline at end of file diff --git a/scaleway-k8s/templates/main.tf.j2 b/scaleway-k8s/templates/main.tf.j2 index 0453bae..20bea91 100644 --- a/scaleway-k8s/templates/main.tf.j2 +++ b/scaleway-k8s/templates/main.tf.j2 @@ -8,8 +8,8 @@ terraform { } - resource "scaleway_k8s_cluster" "{{ project_name }}" { - name = "{{ project_name }}" + resource "scaleway_k8s_cluster" "{{ project_name_tf }}" { + name = "{{ project_name_tf }}" version = "1.24.3" cni = "cilium" project_id = "{{ project_id }}" From 371ee06a41e70a8cd551115c1bafbd703718ecaf Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 3 Nov 2022 21:53:42 +0100 Subject: [PATCH 02/14] ajout pause dans le task create-build --- scaleway-k8s/tasks/create-build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scaleway-k8s/tasks/create-build.yml b/scaleway-k8s/tasks/create-build.yml index 7773caa..864e689 100644 --- a/scaleway-k8s/tasks/create-build.yml +++ b/scaleway-k8s/tasks/create-build.yml @@ -27,4 +27,8 @@ - name: Template env file template: src: "env-build.j2" - dest: "{{ home_dir }}/{{ quarkus_project }}/.env" \ No newline at end of file + dest: "{{ home_dir }}/{{ quarkus_project }}/.env" + +- name: Pause for build image + pause: + prompt: aller au dossier {{ home_dir }}/{{ quarkus_project }}, et exécuter le script build-image.sh \ No newline at end of file From 398adda9309ad6c363de1dd9920e609b6d4e91f3 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 6 Nov 2022 18:13:59 +0100 Subject: [PATCH 03/14] add tag and push image --- scaleway-k8s/tasks/create-build.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scaleway-k8s/tasks/create-build.yml b/scaleway-k8s/tasks/create-build.yml index 864e689..ad4905f 100644 --- a/scaleway-k8s/tasks/create-build.yml +++ b/scaleway-k8s/tasks/create-build.yml @@ -31,4 +31,22 @@ - name: Pause for build image pause: - prompt: aller au dossier {{ home_dir }}/{{ quarkus_project }}, et exécuter le script build-image.sh \ No newline at end of file + prompt: aller au dossier {{ home_dir }}/{{ quarkus_project }}, et exécuter le script build-image.sh + +- name: Get quarkus image + docker_image_info: + name: quarkus-native + register: result + +- name: Check quarkus image + assert: + that: + - result.images | length == 1 + +- name: Tag and push to custom registry + docker_image: + name: quarkus-native + repository: registry.valczeryba.ovh:5000/quarkus-native + tag: latest + push: yes + source: local From 097d0621d61bb735e34bd997460b7899ee0c9d6c Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 6 Nov 2022 18:31:35 +0100 Subject: [PATCH 04/14] fix hosts --- inventory/hosts | 9 ++++++--- playbook.yml | 2 +- server/tasks/remove.yml | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/inventory/hosts b/inventory/hosts index 5c5d87d..ade87f2 100644 --- a/inventory/hosts +++ b/inventory/hosts @@ -1,11 +1,14 @@ -vps ansible_connection=ssh ansible_host=51.222.107.37 ansible_port=2424 ansible_user=valentin +vps-host ansible_connection=ssh ansible_host=51.222.107.37 ansible_port=2424 ansible_user=valentin valentin-nas ansible_connection=ssh ansible_host=151.80.37.38 ansible_port=2424 ansible_user=valentin drone-host ansible_connection=ssh ansible_host=151.80.37.38 ansible_port=2424 ansible_user=valentin localhost ansible_host=127.0.0.1 -[db] +[vps] +vps-host + +[db:children] +local vps -localhost [db_vault:children] db diff --git a/playbook.yml b/playbook.yml index ab57557..c598e5a 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,5 +1,5 @@ --- -- hosts: registry db drone +- hosts: registry vps remote_user: valentin roles: - server diff --git a/server/tasks/remove.yml b/server/tasks/remove.yml index 9c6e9f3..e8a6b83 100644 --- a/server/tasks/remove.yml +++ b/server/tasks/remove.yml @@ -15,4 +15,8 @@ - name: Remove project file: path: "{{ project_src }}" - state: absent \ No newline at end of file + state: absent + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" \ No newline at end of file From 005127a37be207342f49fab204e4f350800a8506 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 7 Nov 2022 23:07:06 +0100 Subject: [PATCH 05/14] fix variable --- scaleway-k8s/tasks/kubeconfig.yml | 2 +- scaleway-k8s/templates/main.tf.j2 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scaleway-k8s/tasks/kubeconfig.yml b/scaleway-k8s/tasks/kubeconfig.yml index f3cabab..310f3c4 100644 --- a/scaleway-k8s/tasks/kubeconfig.yml +++ b/scaleway-k8s/tasks/kubeconfig.yml @@ -16,6 +16,6 @@ method: GET headers: X-Auth-Token: "{{ scw_secret_key }}" - when: item.name == "{{ project_name }}" + when: item.name == "{{ project_name_tf }}" with_items: "{{ (output.content |from_json).clusters }}" \ No newline at end of file diff --git a/scaleway-k8s/templates/main.tf.j2 b/scaleway-k8s/templates/main.tf.j2 index 20bea91..c5fe332 100644 --- a/scaleway-k8s/templates/main.tf.j2 +++ b/scaleway-k8s/templates/main.tf.j2 @@ -17,7 +17,7 @@ terraform { } resource "scaleway_k8s_pool" "john" { - cluster_id = scaleway_k8s_cluster.{{ project_name }}.id + cluster_id = scaleway_k8s_cluster.{{ project_name_tf }}.id name = "john" node_type = "DEV1-M" size = 1 @@ -26,9 +26,9 @@ terraform { resource "null_resource" "kubeconfig" { depends_on = [scaleway_k8s_pool.john] # at least one pool here triggers = { - host = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].host - token = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].token - cluster_ca_certificate = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].cluster_ca_certificate + host = scaleway_k8s_cluster.{{ project_name_tf }}.kubeconfig[0].host + token = scaleway_k8s_cluster.{{ project_name_tf }}.kubeconfig[0].token + cluster_ca_certificate = scaleway_k8s_cluster.{{ project_name_tf }}.kubeconfig[0].cluster_ca_certificate } } From 572be625bd2210ef9c400551832f5052c6a86b8e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 26 Nov 2022 18:37:05 +0100 Subject: [PATCH 06/14] push to scaleway registry --- inventory/group_vars/local_vault | 31 ++++++++++++++++------------- scaleway-k8s/tasks/create-build.yml | 10 +++++++++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/inventory/group_vars/local_vault b/inventory/group_vars/local_vault index e330945..db58efe 100644 --- a/inventory/group_vars/local_vault +++ b/inventory/group_vars/local_vault @@ -1,15 +1,18 @@ $ANSIBLE_VAULT;1.1;AES256 -65363666393931336562303562336163356633643832646633383864346538386436613363316661 -3766663332623564646630633232393830326262626231330a363035363237653930656362633561 -65666133376131643366393234623861613862646466383038656536656466343134666135363333 -3733313835383034380a643063373765356637373332636264653539363963326366646664336431 -66613265623364383933326165383162366464633037323366303931636136623835313334623131 -31666161623238346631316236643735653134306536663538646437343066323930383261646161 -62616361303630333230346263343937633461396362613963626433623264333039306530396136 -65623163383965326161383238366564393632323830333336623839636564623535643463356666 -61326634663834636336313233306535646366363437346262323939613937333831646466326264 -65363534303037376166663363306433303633383662316235343634343035323838663931613733 -33326563323332353765666639643462353935303064626266643339623238316233383837396631 -65376264346139353939396538313837636333643239623532333636653364646137356439323833 -35363730643336376361656366666136313431613337363533643539373865663766653161366530 -6339316532613964626139336236346635643638633439376662 +62303334613131393231383663303736313438613735343864663138326464326434396561613630 +6134343565363064663931313335613936333039386138360a616333313562386566313563666139 +64376131393634346664376465663965396236626663613831306433313735303338393061313663 +3738343164626266640a626636356332303961366566363838306161303530613964393531353761 +64366265633037363862366334396333323865653963326335356334616234306437333334343538 +31666530613337376432323561353036383530653737373434633431616233653962656134393766 +31656461373337626531313161346664346139653933613632346162313565623436663430323266 +32646464373737323230323736376665326437396363343233646235623638363537393339313437 +33353962633365353466643635656464383238636139353436326633633430623261656633336266 +63633766633836336662363063306330393463326138616336623365323535313264383161623434 +32626237643238396336616533636564646464376232333864396663666563393839643863316338 +63616632613230323663353430653430663362626331653230393934313339396432343361383266 +33333861636265663863313931343463363034376462363466306339373134363535333164646663 +35386533646333656164663065353336333563396430626636326639306330313066326662623663 +31666433333135373462306335666662366130363634386564353065626332643432626632303932 +39393131643037333765653964376663336164313732336134616466353163653036336639336466 +34333738353830336165303333646161386533663033343838316162656638306131 diff --git a/scaleway-k8s/tasks/create-build.yml b/scaleway-k8s/tasks/create-build.yml index ad4905f..20b479b 100644 --- a/scaleway-k8s/tasks/create-build.yml +++ b/scaleway-k8s/tasks/create-build.yml @@ -43,10 +43,18 @@ that: - result.images | length == 1 +- name: Login to scaleway registry + docker_login: + registry_url: rg.fr-par.scw.cloud/covas + username: nologin + password: "{{ token_scaleway }}" + reauthorize: true + + - name: Tag and push to custom registry docker_image: name: quarkus-native - repository: registry.valczeryba.ovh:5000/quarkus-native + repository: rg.fr-par.scw.cloud/covas/quarkus-native tag: latest push: yes source: local From 8008b025d051fbbd2325911696b78bf7d975966e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 15:14:00 +0100 Subject: [PATCH 07/14] variabilisation kubernetes --- inventory/group_vars/local | 5 +- inventory/group_vars/local_vault | 55 +++++++---- .../templates/backend-deployment.yaml.j2 | 97 +++++++++++++++++++ .../templates/backend-service.yaml.j2 | 20 ++++ scaleway-k8s/templates/env-configmap.yaml.j2 | 20 ++++ scaleway-k8s/templates/secret.yaml.j2 | 11 +++ 6 files changed, 190 insertions(+), 18 deletions(-) create mode 100644 scaleway-k8s/templates/backend-deployment.yaml.j2 create mode 100644 scaleway-k8s/templates/backend-service.yaml.j2 create mode 100644 scaleway-k8s/templates/env-configmap.yaml.j2 create mode 100644 scaleway-k8s/templates/secret.yaml.j2 diff --git a/inventory/group_vars/local b/inventory/group_vars/local index e0943cc..7b06ac1 100644 --- a/inventory/group_vars/local +++ b/inventory/group_vars/local @@ -5,4 +5,7 @@ quarkus_project: "covas-quarkus" mailer_host: "smtp.gmail.com" mailer_from: "valczebackup@gmail.com" -mailer_port: "587" \ No newline at end of file +mailer_port: "587" + +port: 8083 +targetPort: 8080 \ No newline at end of file diff --git a/inventory/group_vars/local_vault b/inventory/group_vars/local_vault index db58efe..1887b86 100644 --- a/inventory/group_vars/local_vault +++ b/inventory/group_vars/local_vault @@ -1,18 +1,39 @@ $ANSIBLE_VAULT;1.1;AES256 -62303334613131393231383663303736313438613735343864663138326464326434396561613630 -6134343565363064663931313335613936333039386138360a616333313562386566313563666139 -64376131393634346664376465663965396236626663613831306433313735303338393061313663 -3738343164626266640a626636356332303961366566363838306161303530613964393531353761 -64366265633037363862366334396333323865653963326335356334616234306437333334343538 -31666530613337376432323561353036383530653737373434633431616233653962656134393766 -31656461373337626531313161346664346139653933613632346162313565623436663430323266 -32646464373737323230323736376665326437396363343233646235623638363537393339313437 -33353962633365353466643635656464383238636139353436326633633430623261656633336266 -63633766633836336662363063306330393463326138616336623365323535313264383161623434 -32626237643238396336616533636564646464376232333864396663666563393839643863316338 -63616632613230323663353430653430663362626331653230393934313339396432343361383266 -33333861636265663863313931343463363034376462363466306339373134363535333164646663 -35386533646333656164663065353336333563396430626636326639306330313066326662623663 -31666433333135373462306335666662366130363634386564353065626332643432626632303932 -39393131643037333765653964376663336164313732336134616466353163653036336639336466 -34333738353830336165303333646161386533663033343838316162656638306131 +64323034306466353139343765626366333236376138306561336430316565616134356565373865 +3330336538643132373635646435646637643735633030660a643538356333356232663664316630 +62326138353933333565626363376135393266666162643936643138303438393565383435333737 +3239363964386630350a653736393435643239373732646637646433623332623336643338663839 +38303433303634613238393233343230386636366137616231623131323861316537623035396630 +32366666393633326665643063306132616631383966353737646439643162336435316538346265 +66356539643530646338363862633963306634613136363337613738653162333163643130613035 +31643330303437616431316165323365376364306664623936356334656362663165623239333231 +66616662643539383164613234343733663236613733313633353961303038666266633739323830 +64633165633832343130316338376638353631326362336663386431636631396334646430336562 +34363666643035643439666362396363663936333763363263393734353438653931363735313032 +35356132383131353538653338386566353032356635653233396264333139303632623939323664 +64363833393230636666323531323630346361346336393239316661636537313030636532653733 +61343338623861626336636636323162343666366238653730386464353736633338313034323633 +31366133643561333464653830343465303836366537633866636335373536613430343339366436 +64656162316437383264666264346633646238633535386165303936633139356436646162396135 +62346163383834343332646437326439343238663334313730656462343530373063386236616135 +35333862376466306637623063323631373530383631316561366365326162663466663338616238 +36376363646466356565303963393562653534663736343730613536643936663836613732373161 +30616232373134376366616263663866313233666437613235643263306332653130383730383937 +64613330653735303734656235376262643432383736613939363963643438373239366137336336 +61353761376332643961363330643364633230383339383234636234633766363037383565336630 +66643431333634646365353233336166626665386339383864303634323335306334666536306339 +65396238623236646464346531333736336538336463376632323663373634666464363737623661 +35616236363634313130316639386333343264316533353131643431363766393632346531323133 +32366132313737326462373635626461666365653339623630623966646663383261663664646338 +63346537366463323361616530333834663238353461306133323464643563616335343762663735 +34316435386362663564316536613134336337346135616434356433643066303831336533343432 +39353938656461376234636561353061303339373039643831643466613861396562376162353161 +31616432326136343238613734356432663539393039363530323030613436376536393734333035 +33653262316639323935646165333337313466303963306132613730366530346532663833393537 +33323839333431373437663039353063343133623831343465303338303437633331396132363634 +61656231653133653866663135643436343639326431616432326235643131356136333266653333 +62643232313231633234343937383365636431316437313463396432393265376164343836356265 +38623335343961616339623961393164366439373439643566393931616237316437613735396634 +64656363326465323466396466623734306639613063323437646431343833346337363937363334 +33646339636132333735353464646431626564633862366139626636663161653931336634373430 +6464626131353032393730623766393631366433636137393165 diff --git a/scaleway-k8s/templates/backend-deployment.yaml.j2 b/scaleway-k8s/templates/backend-deployment.yaml.j2 new file mode 100644 index 0000000..050bc99 --- /dev/null +++ b/scaleway-k8s/templates/backend-deployment.yaml.j2 @@ -0,0 +1,97 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + kompose.cmd: kompose convert -f ../docker-compose.yml + kompose.version: 1.26.0 (40646f47) + creationTimestamp: null + labels: + io.kompose.service: backend + name: backend +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: backend + strategy: {} + template: + metadata: + annotations: + kompose.cmd: kompose convert -f ../docker-compose.yml + kompose.version: 1.26.0 (40646f47) + creationTimestamp: null + labels: + io.kompose.service: backend + spec: + imagePullSecrets: + - name: regcred + containers: + - env: + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + key: POSTGRES_DB + name: env + - name: POSTGRES_PASSWORD + valueFrom: + configMapKeyRef: + key: POSTGRES_PASSWORD + name: env + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + key: POSTGRES_PORT + name: env + - name: POSTGRES_URL + valueFrom: + configMapKeyRef: + key: POSTGRES_URL + name: env + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + key: POSTGRES_USER + name: env + - name: REDIS_PORT + valueFrom: + configMapKeyRef: + key: REDIS_PORT + name: env + - name: REDIS_URL + valueFrom: + configMapKeyRef: + key: REDIS_URL + name: env + - name: MAILER_FROM + valueFrom: + configMapKeyRef: + key: MAILER_FROM + name: env + - name: MAILER_HOST + valueFrom: + configMapKeyRef: + key: MAILER_HOST + name: env + - name: MAILER_PORT + valueFrom: + configMapKeyRef: + key: MAILER_PORT + name: env + - name: MAILER_USERNAME + valueFrom: + configMapKeyRef: + key: MAILER_USERNAME + name: env + - name: MAILER_PASSWORD + valueFrom: + configMapKeyRef: + key: MAILER_PASSWORD + name: env + image: rg.fr-par.scw.cloud/covas/quarkus-native + name: backend + + ports: + - containerPort: 8080 + resources: {} + restartPolicy: Always +status: {} diff --git a/scaleway-k8s/templates/backend-service.yaml.j2 b/scaleway-k8s/templates/backend-service.yaml.j2 new file mode 100644 index 0000000..20a0172 --- /dev/null +++ b/scaleway-k8s/templates/backend-service.yaml.j2 @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + kompose.cmd: kompose convert -f ../docker-compose.yml + kompose.version: 1.26.0 (40646f47) + creationTimestamp: null + labels: + io.kompose.service: backend + name: backend +spec: + ports: + - name: "{{ port }}" + port: {{ port }} + targetPort: {{ targetPort }} + type: LoadBalancer + selector: + io.kompose.service: backend +status: + loadBalancer: {} diff --git a/scaleway-k8s/templates/env-configmap.yaml.j2 b/scaleway-k8s/templates/env-configmap.yaml.j2 new file mode 100644 index 0000000..12afb27 --- /dev/null +++ b/scaleway-k8s/templates/env-configmap.yaml.j2 @@ -0,0 +1,20 @@ +apiVersion: v1 +data: + POSTGRES_DB: {{ postgres_db }} + POSTGRES_PASSWORD: {{ postgres_password }} + POSTGRES_PORT: "{{ postgres_port }}" + POSTGRES_URL: {{ postgres_url }} + POSTGRES_USER: {{ postgres_user }} + REDIS_PORT: "{{ redis_port }}" + REDIS_URL: {{ redis_url }} + MAILER_FROM: {{ mailer_from }} + MAILER_HOST: {{ mailer_host }} + MAILER_PORT: "{{ mailer_port }}" + MAILER_USERNAME: {{ mailer_username }} + MAILER_PASSWORD: {{ mailer_password }} +kind: ConfigMap +metadata: + creationTimestamp: null + labels: + io.kompose.service: backend-env + name: env diff --git a/scaleway-k8s/templates/secret.yaml.j2 b/scaleway-k8s/templates/secret.yaml.j2 new file mode 100644 index 0000000..f0ff086 --- /dev/null +++ b/scaleway-k8s/templates/secret.yaml.j2 @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + .dockerconfigjson: {{ dockerconfigjson }} +kind: Secret +metadata: + creationTimestamp: "2022-11-26T19:19:41Z" + name: regcred + namespace: default + resourceVersion: "17345802593" + uid: {{ uid_secret }} +type: kubernetes.io/dockerconfigjson From 4eee20f63f59a8a6f6a6e8d851efdfd50b6d89ef Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 15:24:35 +0100 Subject: [PATCH 08/14] list item and copy template --- inventory/group_vars/local | 10 +++++++++- scaleway-k8s/tasks/deploy-backend.yml | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 scaleway-k8s/tasks/deploy-backend.yml diff --git a/inventory/group_vars/local b/inventory/group_vars/local index 7b06ac1..a2e1a52 100644 --- a/inventory/group_vars/local +++ b/inventory/group_vars/local @@ -1,4 +1,5 @@ project_terraform: "/home/valentin/terraform" +project_backend: "/home/valentin/k8s_backend" region_k8s: "fr-par" project_name_tf: "terraform-test" quarkus_project: "covas-quarkus" @@ -8,4 +9,11 @@ mailer_from: "valczebackup@gmail.com" mailer_port: "587" port: 8083 -targetPort: 8080 \ No newline at end of file +targetPort: 8080 + + +backend_yaml: + - backend-deployment + - backend-service + - env-configmap + - secret \ No newline at end of file diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml new file mode 100644 index 0000000..54d87aa --- /dev/null +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -0,0 +1,15 @@ +--- +# tasks file for create cluster k8s via terraform + +- name: Create directory {{ project_terraform }} + file: + path: "{{ project_backend }}" + state: directory + +- name: Copy backend k8s yaml + template: + src: "{{ item }}.tf.j2" + dest: "{{ project_backend }}/{{ item }}.yaml" + with_items: "{{ backend_yaml }}" + + From 11d0273ac102ac5efe49f00dd25708970db42146 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 20:14:13 +0100 Subject: [PATCH 09/14] fix copy kubeconfig files --- scaleway-k8s/tasks/deploy-backend.yml | 2 +- scaleway-k8s/tasks/main.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml index 54d87aa..418723a 100644 --- a/scaleway-k8s/tasks/deploy-backend.yml +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -8,7 +8,7 @@ - name: Copy backend k8s yaml template: - src: "{{ item }}.tf.j2" + src: "{{ item }}.yaml.j2" dest: "{{ project_backend }}/{{ item }}.yaml" with_items: "{{ backend_yaml }}" diff --git a/scaleway-k8s/tasks/main.yml b/scaleway-k8s/tasks/main.yml index 80fb2c6..22e162a 100644 --- a/scaleway-k8s/tasks/main.yml +++ b/scaleway-k8s/tasks/main.yml @@ -10,6 +10,10 @@ import_tasks: kubeconfig.yml tags: ["create-cluster", "kubeconfig"] +- name: Deploy a API backend + import_tasks: deploy-backend.yml + tags: ["deploy-api"] + - name: Destroy cluster k8s scaleway via terraform import_tasks: destroy-cluster.yml tags: ["destroy-cluster"] From 369aed9ea1c189e0b150e172e7922c6af44d1532 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 20:30:25 +0100 Subject: [PATCH 10/14] copy kubeconfig --- inventory/group_vars/local | 1 + scaleway-k8s/tasks/kubeconfig.yml | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/inventory/group_vars/local b/inventory/group_vars/local index a2e1a52..0bd4efb 100644 --- a/inventory/group_vars/local +++ b/inventory/group_vars/local @@ -1,5 +1,6 @@ project_terraform: "/home/valentin/terraform" project_backend: "/home/valentin/k8s_backend" +project_kubeconfig: "/home/valentin/.kube/config" region_k8s: "fr-par" project_name_tf: "terraform-test" quarkus_project: "covas-quarkus" diff --git a/scaleway-k8s/tasks/kubeconfig.yml b/scaleway-k8s/tasks/kubeconfig.yml index 310f3c4..77561a3 100644 --- a/scaleway-k8s/tasks/kubeconfig.yml +++ b/scaleway-k8s/tasks/kubeconfig.yml @@ -18,4 +18,8 @@ X-Auth-Token: "{{ scw_secret_key }}" when: item.name == "{{ project_name_tf }}" with_items: "{{ (output.content |from_json).clusters }}" - \ No newline at end of file + +- name: Copy kubeconfig + copy: + src: "{{ project_terraform }}/kubeconfig" + dest: "{{ project_kubeconfig }}" \ No newline at end of file From 3a16d3e72337c987412a2621a2e5db6a7fcac048 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 22:10:13 +0100 Subject: [PATCH 11/14] deploy api --- inventory/hosts | 4 +-- scaleway-k8s/tasks/deploy-backend.yml | 33 +++++++++++++++++++ .../templates/backend-deployment.yaml.j2 | 1 + .../templates/backend-service.yaml.j2 | 1 + scaleway-k8s/templates/env-configmap.yaml.j2 | 2 ++ scaleway-k8s/templates/secret.yaml.j2 | 3 +- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/inventory/hosts b/inventory/hosts index ade87f2..d2cab72 100644 --- a/inventory/hosts +++ b/inventory/hosts @@ -1,7 +1,7 @@ -vps-host ansible_connection=ssh ansible_host=51.222.107.37 ansible_port=2424 ansible_user=valentin +vps-host ansible_connection=ssh ansible_host=51.222.107.37 ansible_port=2424 ansible_user=valentin valentin-nas ansible_connection=ssh ansible_host=151.80.37.38 ansible_port=2424 ansible_user=valentin drone-host ansible_connection=ssh ansible_host=151.80.37.38 ansible_port=2424 ansible_user=valentin -localhost ansible_host=127.0.0.1 +localhost ansible_host=127.0.0.1 ansible_python_interpreter=/usr/bin/python3.10 [vps] vps-host diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml index 418723a..034fe6d 100644 --- a/scaleway-k8s/tasks/deploy-backend.yml +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -12,4 +12,37 @@ dest: "{{ project_backend }}/{{ item }}.yaml" with_items: "{{ backend_yaml }}" +- name: Create a k8s namespace + kubernetes.core.k8s: + name: testing + api_version: v1 + kind: Namespace + state: present + + +- name: Apply deployment + kubernetes.core.k8s: + src: "{{ project_backend }}/backend-deployment.yaml" + state: present + +- name: Apply services + kubernetes.core.k8s: + src: "{{ project_backend }}/backend-service.yaml" + state: present + +- name: Apply configmap + kubernetes.core.k8s: + src: "{{ project_backend }}/env-configmap.yaml" + state: present + + +- name: Apply secret + kubernetes.core.k8s: + src: "{{ project_backend }}/secret.yaml" + state: present + + + + + diff --git a/scaleway-k8s/templates/backend-deployment.yaml.j2 b/scaleway-k8s/templates/backend-deployment.yaml.j2 index 050bc99..b01033e 100644 --- a/scaleway-k8s/templates/backend-deployment.yaml.j2 +++ b/scaleway-k8s/templates/backend-deployment.yaml.j2 @@ -8,6 +8,7 @@ metadata: labels: io.kompose.service: backend name: backend + namespace: testing spec: replicas: 1 selector: diff --git a/scaleway-k8s/templates/backend-service.yaml.j2 b/scaleway-k8s/templates/backend-service.yaml.j2 index 20a0172..79ee8f5 100644 --- a/scaleway-k8s/templates/backend-service.yaml.j2 +++ b/scaleway-k8s/templates/backend-service.yaml.j2 @@ -8,6 +8,7 @@ metadata: labels: io.kompose.service: backend name: backend + namespace: testing spec: ports: - name: "{{ port }}" diff --git a/scaleway-k8s/templates/env-configmap.yaml.j2 b/scaleway-k8s/templates/env-configmap.yaml.j2 index 12afb27..ee8c114 100644 --- a/scaleway-k8s/templates/env-configmap.yaml.j2 +++ b/scaleway-k8s/templates/env-configmap.yaml.j2 @@ -18,3 +18,5 @@ metadata: labels: io.kompose.service: backend-env name: env + namespace: testing + diff --git a/scaleway-k8s/templates/secret.yaml.j2 b/scaleway-k8s/templates/secret.yaml.j2 index f0ff086..686913e 100644 --- a/scaleway-k8s/templates/secret.yaml.j2 +++ b/scaleway-k8s/templates/secret.yaml.j2 @@ -5,7 +5,6 @@ kind: Secret metadata: creationTimestamp: "2022-11-26T19:19:41Z" name: regcred - namespace: default - resourceVersion: "17345802593" + namespace: testing uid: {{ uid_secret }} type: kubernetes.io/dockerconfigjson From 452a650b1691c01ad6808739637e886fe70f68b9 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Dec 2022 23:05:52 +0100 Subject: [PATCH 12/14] deploy backend api --- scaleway-k8s/tasks/deploy-backend.yml | 24 +++++++++++++-- scaleway-k8s/tasks/destroy-backend.yml | 42 ++++++++++++++++++++++++++ scaleway-k8s/tasks/main.yml | 8 ++++- 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 scaleway-k8s/tasks/destroy-backend.yml diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml index 034fe6d..18cee8f 100644 --- a/scaleway-k8s/tasks/deploy-backend.yml +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -41,8 +41,26 @@ src: "{{ project_backend }}/secret.yaml" state: present - - - +- name: Pause for 2 minutes to build app cache + ansible.builtin.pause: + minutes: 2 + +- name: Fetch services + set_fact: + service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing', label_selector='io.kompose.service=backend') }}" + register: result + tags: [ "services"] + +- name: debug services + debug: + msg: "{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}" + tags: [ "services"] + +- name: Test API Backend + ansible.builtin.uri: + url: "http://{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}:{{ port }}/api/hello" + status_code: 200 + method: GET + tags: [ "services" ] diff --git a/scaleway-k8s/tasks/destroy-backend.yml b/scaleway-k8s/tasks/destroy-backend.yml new file mode 100644 index 0000000..9cdd82d --- /dev/null +++ b/scaleway-k8s/tasks/destroy-backend.yml @@ -0,0 +1,42 @@ +--- +# tasks file for create cluster k8s via terraform + +- name: Apply deployment + kubernetes.core.k8s: + src: "{{ project_backend }}/backend-deployment.yaml" + state: absent + +- name: Apply services + kubernetes.core.k8s: + src: "{{ project_backend }}/backend-service.yaml" + state: absent + +- name: Apply configmap + kubernetes.core.k8s: + src: "{{ project_backend }}/env-configmap.yaml" + state: absent + + +- name: Apply secret + kubernetes.core.k8s: + src: "{{ project_backend }}/secret.yaml" + state: absent + + +- name: Create a k8s namespace + kubernetes.core.k8s: + name: testing + api_version: v1 + kind: Namespace + state: absent + + +- name: Create directory {{ project_terraform }} + file: + path: "{{ project_backend }}" + state: absent + + + + + diff --git a/scaleway-k8s/tasks/main.yml b/scaleway-k8s/tasks/main.yml index 22e162a..8065e9f 100644 --- a/scaleway-k8s/tasks/main.yml +++ b/scaleway-k8s/tasks/main.yml @@ -12,7 +12,13 @@ - name: Deploy a API backend import_tasks: deploy-backend.yml - tags: ["deploy-api"] + tags: ["deploy-api"] + + +- name: Deploy a API backend + import_tasks: destroy-backend.yml + tags: ["destroy-api"] + - name: Destroy cluster k8s scaleway via terraform import_tasks: destroy-cluster.yml From 2a63aed0e32b18ee4e2bfde0f686ab53b360ae62 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 11 Dec 2022 11:45:40 +0100 Subject: [PATCH 13/14] add API curl --- scaleway-k8s/tasks/deploy-backend.yml | 4 ++-- scaleway-k8s/tasks/main.yml | 5 ++--- server/tasks/main.yml | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml index 18cee8f..ae14526 100644 --- a/scaleway-k8s/tasks/deploy-backend.yml +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -41,13 +41,13 @@ src: "{{ project_backend }}/secret.yaml" state: present -- name: Pause for 2 minutes to build app cache +- name: En attente d'une adresse IP publique du cluster ansible.builtin.pause: minutes: 2 - name: Fetch services set_fact: - service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing', label_selector='io.kompose.service=backend') }}" + service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing') }}" register: result tags: [ "services"] diff --git a/scaleway-k8s/tasks/main.yml b/scaleway-k8s/tasks/main.yml index 8065e9f..4a16e49 100644 --- a/scaleway-k8s/tasks/main.yml +++ b/scaleway-k8s/tasks/main.yml @@ -12,12 +12,11 @@ - name: Deploy a API backend import_tasks: deploy-backend.yml - tags: ["deploy-api"] - + tags: ["deploy"] - name: Deploy a API backend import_tasks: destroy-backend.yml - tags: ["destroy-api"] + tags: ["destroy"] - name: Destroy cluster k8s scaleway via terraform diff --git a/server/tasks/main.yml b/server/tasks/main.yml index 13efea6..362c108 100644 --- a/server/tasks/main.yml +++ b/server/tasks/main.yml @@ -8,17 +8,17 @@ - name: Deploy services import_tasks: deploy.yml - tags: ["deploy", "create"] + tags: ["configure", "create"] - name: Start services import_tasks: start.yml - tags: ["deploy", "start"] + tags: ["configure", "start"] - name: stop services import_tasks: stop.yml - tags: ["destroy", "stop"] + tags: ["deconfigure", "stop"] - name: Remove services import_tasks: remove.yml - tags: ["destroy"] + tags: ["deconfigure"] From 67c2a0ed3ee426451a799b6f20d910c1caa95017 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 18 Dec 2022 18:42:14 +0100 Subject: [PATCH 14/14] add or update dns with API OVH --- inventory/group_vars/local_vault | 83 +++++++++++---------- scaleway-k8s/files/requierements.txt | 1 + scaleway-k8s/tasks/deploy-backend.yml | 64 ++++++++++++---- scaleway-k8s/templates/dns_add_update.py.j2 | 49 ++++++++++++ 4 files changed, 143 insertions(+), 54 deletions(-) create mode 100644 scaleway-k8s/files/requierements.txt create mode 100644 scaleway-k8s/templates/dns_add_update.py.j2 diff --git a/inventory/group_vars/local_vault b/inventory/group_vars/local_vault index 1887b86..e6c23c7 100644 --- a/inventory/group_vars/local_vault +++ b/inventory/group_vars/local_vault @@ -1,39 +1,46 @@ $ANSIBLE_VAULT;1.1;AES256 -64323034306466353139343765626366333236376138306561336430316565616134356565373865 -3330336538643132373635646435646637643735633030660a643538356333356232663664316630 -62326138353933333565626363376135393266666162643936643138303438393565383435333737 -3239363964386630350a653736393435643239373732646637646433623332623336643338663839 -38303433303634613238393233343230386636366137616231623131323861316537623035396630 -32366666393633326665643063306132616631383966353737646439643162336435316538346265 -66356539643530646338363862633963306634613136363337613738653162333163643130613035 -31643330303437616431316165323365376364306664623936356334656362663165623239333231 -66616662643539383164613234343733663236613733313633353961303038666266633739323830 -64633165633832343130316338376638353631326362336663386431636631396334646430336562 -34363666643035643439666362396363663936333763363263393734353438653931363735313032 -35356132383131353538653338386566353032356635653233396264333139303632623939323664 -64363833393230636666323531323630346361346336393239316661636537313030636532653733 -61343338623861626336636636323162343666366238653730386464353736633338313034323633 -31366133643561333464653830343465303836366537633866636335373536613430343339366436 -64656162316437383264666264346633646238633535386165303936633139356436646162396135 -62346163383834343332646437326439343238663334313730656462343530373063386236616135 -35333862376466306637623063323631373530383631316561366365326162663466663338616238 -36376363646466356565303963393562653534663736343730613536643936663836613732373161 -30616232373134376366616263663866313233666437613235643263306332653130383730383937 -64613330653735303734656235376262643432383736613939363963643438373239366137336336 -61353761376332643961363330643364633230383339383234636234633766363037383565336630 -66643431333634646365353233336166626665386339383864303634323335306334666536306339 -65396238623236646464346531333736336538336463376632323663373634666464363737623661 -35616236363634313130316639386333343264316533353131643431363766393632346531323133 -32366132313737326462373635626461666365653339623630623966646663383261663664646338 -63346537366463323361616530333834663238353461306133323464643563616335343762663735 -34316435386362663564316536613134336337346135616434356433643066303831336533343432 -39353938656461376234636561353061303339373039643831643466613861396562376162353161 -31616432326136343238613734356432663539393039363530323030613436376536393734333035 -33653262316639323935646165333337313466303963306132613730366530346532663833393537 -33323839333431373437663039353063343133623831343465303338303437633331396132363634 -61656231653133653866663135643436343639326431616432326235643131356136333266653333 -62643232313231633234343937383365636431316437313463396432393265376164343836356265 -38623335343961616339623961393164366439373439643566393931616237316437613735396634 -64656363326465323466396466623734306639613063323437646431343833346337363937363334 -33646339636132333735353464646431626564633862366139626636663161653931336634373430 -6464626131353032393730623766393631366433636137393165 +30356465363432393266326366393162306331353564346565663139336538613832396135306537 +6262336438613736636266623766333233336631656661640a663838373936613666373133383632 +32613962623330303964333161373165363164646266396461633233346136336630646631306564 +3939363432643961610a313338306136303132666461393637643235623361393830653534643137 +38623038613364396538353533336631633863343834333030653164303231346263316435356231 +61383966663834333662393138303035613330366533663037326532356332633839363763356466 +63396536323864383933346434363231396164613838316162656333626634373936643738386565 +32326532346334343666383632306264636132613266333863626462366530306439613130333564 +38623461613739343461386564323865316332653530623862313163396566616230653030653266 +61613836303231363534393531373233363332316639316137653132336638356161333764373562 +34363034353935633437353466303364653039626137383534633239316563373663623030646330 +38383639326563643266346530616666646337373765643336326536303864613363663536643465 +34343663373131323437666462303763366439356362306337356131383932353731393935343931 +32613333373439343864653864636438646431306637613038313061663961653033643465643864 +31333366663037373835326330316535326134393761333662326665333464666164623336666439 +35313066303830343737343063396335383461653338303734353461643736343163346565323864 +65356437376663386535646437653566326532346462313932346435393730366530646164323537 +35363633333065356162653762623239343836356230303734316130383234313536623339626531 +36643434336233626234333235636566313566353939616433373465666362316663353336653162 +32346534333665353934653738343335356137643539376639323164393837383065323436363064 +35643762656365313261373030336339616266333765613735346565623138366533626335633033 +38373732626337353535656230636235373535363332376535343162666266393931303236653631 +33653432633337306230396434316230663438363630313038386538663732393863633837313638 +31663763303462343063613638663361626462623035336465383661646433643833636361346236 +32386263326664363338633861643264383462313863666662623033323761613132666130353235 +34633261303761623033633964323862666137333035306333323932346334356365333563316630 +34313263306561303538353134613233313337323636623230616532383133613561333439663337 +64376230363038306238656236653366353738633436623330383239373062313831393066313838 +38653532356632383765613530373034396639633064383336393934353061656266633463336333 +66356538616233313936376565386432303134306363343734333563333266643062666231303532 +37363664396165653333656661376334333432376566666237316232643234386332323936346630 +63303563363162356666643732366131393066333838363935613336353062633862353838613761 +64333939663733643132366334653835633733623539393735313961613131303934363731663231 +64313434613934336630306165343665376261353562656634356365613137346232633431343734 +63363532313765646434346132313434373366656332353133383530306639633062633365613932 +65383865643262666666383933363534623838653661376531303763623261323937626335373635 +32623262343130383462316462643338363433653133353737633562353330313533303835666634 +65386336616466316663356236316466353164353139326333316362303737343335353731366531 +36653062323764316332353136343738616338313465333261363664663934393038343237313135 +64363036636634646137616365366538613338343761646137623432396539363035663031313464 +66646663373838316161643161613838343139346165663331373334383334316562353235633461 +65316666616334653034393165616434306664633336613639636433663761363932396663396630 +64383961623136623639306435663965303632663039653538646463663235653333306434313931 +32636536643536636561663534346633663464333830646139383939626665393964353739616435 +35663834393738646130316564633966653765303033356132393961653831646362 diff --git a/scaleway-k8s/files/requierements.txt b/scaleway-k8s/files/requierements.txt new file mode 100644 index 0000000..759a68d --- /dev/null +++ b/scaleway-k8s/files/requierements.txt @@ -0,0 +1 @@ +ovh \ No newline at end of file diff --git a/scaleway-k8s/tasks/deploy-backend.yml b/scaleway-k8s/tasks/deploy-backend.yml index ae14526..0a09c15 100644 --- a/scaleway-k8s/tasks/deploy-backend.yml +++ b/scaleway-k8s/tasks/deploy-backend.yml @@ -45,22 +45,54 @@ ansible.builtin.pause: minutes: 2 -- name: Fetch services - set_fact: - service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing') }}" - register: result - tags: [ "services"] +- name: Get IP Cluster + block: + - name: Fetch services + set_fact: + service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing') }}" + register: result -- name: debug services - debug: - msg: "{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}" - tags: [ "services"] - -- name: Test API Backend - ansible.builtin.uri: - url: "http://{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}:{{ port }}/api/hello" - status_code: 200 - method: GET - tags: [ "services" ] + - name: debug services + debug: + msg: "{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}" + - name: Test API Backend + ansible.builtin.uri: + url: "http://{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}:{{ port }}/api/hello" + status_code: 200 + method: GET + tags: ["services", "dns"] +- name: Add DNS for IP Cluster + block: + - name: Copy script add or update DNS + template: + src: "dns_add_update.py.j2" + dest: "{{ project_backend }}/dns_add_update.py" + + - name: Copy requierements python + copy: + src: "requierements.txt" + dest: "{{ project_backend }}" + + - name: Pip install requierements + shell: "pip3.10 install -r {{ project_backend }}/requierements.txt" + + - name: En attente de l'installation des packages + ansible.builtin.pause: + minutes: 2 + + - name: Add or update DNS + shell: "python3.10 {{ project_backend }}/dns_add_update.py --ip {{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}" + register: result + + - name: Display result script + debug: + msg: "{{ result }}" + + - name: Test API Backend with DNS + ansible.builtin.uri: + url: "http://api.valczeryba.ovh:{{ port }}/api/hello" + status_code: 200 + method: GET + tags: [ "dns" ] \ No newline at end of file diff --git a/scaleway-k8s/templates/dns_add_update.py.j2 b/scaleway-k8s/templates/dns_add_update.py.j2 new file mode 100644 index 0000000..c9ade17 --- /dev/null +++ b/scaleway-k8s/templates/dns_add_update.py.j2 @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +''' +First, install the latest release of Python wrapper: $ pip install ovh +''' +import json +import ovh +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument('--ip', help='foo help') +args = parser.parse_args() + +# Instanciate an OVH Client. +# You can generate new credentials with full access to your account on +# the token creation page +client = ovh.Client( + endpoint='ovh-eu', # Endpoint of API OVH Europe (List of available endpoints) + application_key='{{ application_key }}', # Application Key + application_secret='{{ application_secret }}', # Application Secret + consumer_key='{{ consumer_key }}', # Consumer Key +) + +result = client.get('/domain/zone/valczeryba.ovh/record', + fieldType='A', + subDomain='api', +) + +# Pretty print + +if len(result) > 0: + for idDns in result: + result = client.get('/domain/zone/valczeryba.ovh/record/{0}'.format(idDns)) + if result["target"] != args.ip: + result = client.put('/domain/zone/valczeryba.ovh/record/{0}'.format(idDns), + subDomain='api', + target=args.ip, + ) + print(result) + + + +else: + result = client.post('/domain/zone/valczeryba.ovh/record', + fieldType='A', + subDomain='api', + target=args.ip, + ttl=None, + ) + print(result) \ No newline at end of file