Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ab1aa5c1 authored by Thierry Martinez's avatar Thierry Martinez
Browse files

Fix #2: Unique state and runner for a given pipeline

This commit makes state filename unique for a given pipeline (and
remove this state in the cleaning phase), and adds a unique tag to the
runners created for the pipeline for jobs not to be run in runners
from other pipelines that run in parallel.
parent 8807efe8
No related branches found
No related tags found
No related merge requests found
Pipeline #756722 canceled
variables: variables:
CI_TEMPLATE_REGISTRY_HOST: registry.gitlab.inria.fr CI_TEMPLATE_REGISTRY_HOST: registry.gitlab.inria.fr
TF_STATE_NAME: default TF_STATE_NAME: pipeline-$CI_PIPELINE_IID
TF_VAR_CI_PIPELINE_IID: $CI_PIPELINE_IID
workflow:
rules:
- if: $CLOUDSTACK_API_KEY
include: include:
- template: Terraform/Base.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml - template: Terraform/Base.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml
...@@ -32,20 +37,23 @@ deploy: ...@@ -32,20 +37,23 @@ deploy:
- small - small
script: script:
- cp $SSH_PRIVATE_KEY id_rsa - cp $SSH_PRIVATE_KEY id_rsa
- gitlab-terraform plan -var runner_count=0 - gitlab-terraform plan
- gitlab-terraform apply
- gitlab-terraform plan -var runner_count=3
- gitlab-terraform apply - gitlab-terraform apply
# Variable interpolation on job tags do not expand $CI_PIPELINE_IID
execute: execute:
stage: execute stage: execute
image: alpine image: alpine
parallel: parallel:
matrix: matrix:
- index: [0, 1, 2] - index: [0, 1, 2]
variables:
PIPELINE_ID: $CI_PIPELINE_IID
tags: tags:
- terraform - terraform
- docker - docker
- pipeline-$PIPELINE_ID
- runner-$index - runner-$index
script: script:
- echo Greetings from runner $index! - echo Greetings from runner $index!
...@@ -58,6 +66,6 @@ cleanup: ...@@ -58,6 +66,6 @@ cleanup:
script: script:
- cd "${TF_ROOT}" - cd "${TF_ROOT}"
- cp $SSH_PRIVATE_KEY id_rsa - cp $SSH_PRIVATE_KEY id_rsa
- gitlab-terraform plan -var runner_count=0 - gitlab-terraform destroy
- gitlab-terraform apply - 'curl --user "gitlab-ci-token:$CI_JOB_TOKEN" --request DELETE "$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$TF_STATE_NAME"'
when: always when: always
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# We install docker.io to be able to register a docker executor # We install docker.io to be able to register a docker executor
apt-get install --yes gitlab-runner docker.io apt-get install --yes gitlab-runner docker.io
gitlab-runner register --non-interactive \ gitlab-runner register --non-interactive \
--tag-list terraform,docker,runner-${index} \ --tag-list terraform,docker,pipeline-${CI_PIPELINE_IID},runner-${index} \
--executor docker --docker-image alpine --url https://gitlab.inria.fr \ --executor docker --docker-image alpine --url https://gitlab.inria.fr \
--registration-token ${REGISTRATION_TOKEN} --registration-token ${REGISTRATION_TOKEN}
) >>/root/log.txt 2>&1 ) >>/root/log.txt 2>&1
...@@ -24,13 +24,13 @@ variable "SSH_PUBLIC_KEY" { ...@@ -24,13 +24,13 @@ variable "SSH_PUBLIC_KEY" {
type = string type = string
} }
variable "runner_count" { variable "CI_PIPELINE_IID" {
type = number type = number
} }
resource "cloudstack_instance" "runner" { resource "cloudstack_instance" "runner" {
count = var.runner_count count = 3
name = "gitlabcigallery-terraform-runner-${count.index}" name = "gitlabcigallery-terraform-pipeline-${var.CI_PIPELINE_IID}-${count.index}"
service_offering = "Custom" service_offering = "Custom"
template = "ubuntu-20.04-lts" template = "ubuntu-20.04-lts"
zone = "zone-ci" zone = "zone-ci"
...@@ -43,6 +43,7 @@ resource "cloudstack_instance" "runner" { ...@@ -43,6 +43,7 @@ resource "cloudstack_instance" "runner" {
index = count.index index = count.index
REGISTRATION_TOKEN = var.REGISTRATION_TOKEN REGISTRATION_TOKEN = var.REGISTRATION_TOKEN
SSH_PUBLIC_KEY = var.SSH_PUBLIC_KEY SSH_PUBLIC_KEY = var.SSH_PUBLIC_KEY
CI_PIPELINE_IID = var.CI_PIPELINE_IID
}) })
connection { connection {
type = "ssh" type = "ssh"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment