Commit 842b7f7b authored by Thomas Boni's avatar Thomas Boni
Browse files

Merge branch '60-provide-a-tool-to-create-the-job-template-in-1-click' into 'latest'

Resolve "Provide a tool to create the job template in 1 click"

Closes #60

See merge request r2devops/hub!232
parents 091edcae bccbaead
Loading
Loading
Loading
Loading

cookiecutter.config.js

0 → 100644
+47 −0
Original line number Diff line number Diff line
module.exports = [
    {
      name: "Job folder creation",
      templatePath: "tools/job_template/r2_jobname/",
      outputPath: "jobs/",
      fields: [
        {
          templateVariable: "r2_jobname",
          question: "What is the name of your job?"
        },
        {
          templateVariable: "r2_jobdescription",
          question: "Give a short description of your job"
        },
        {
          templateVariable: "r2_stage",
          question: "What is the default stage of your job?",
          choices: ["static_tests", "build", "dynamic_tests", "provision", "review", "release", "deploy", "others"]
        },
        {
          templateVariable: "r2_maintainer",
          question: "What is your Gitlab username?"
        },
        {
          templateVariable: "r2_license",
          question: "What license do you want to use?",
          choices: ["MIT", "Apache-2.0"]
        },
        {
          templateVariable: "r2_imagename",
          question: "What is the Docker image that you will use? (just the name, Without version)"
        },
        {
          templateVariable: "r2_imagetag",
          question: "What is the tag of this image?",
          errorMessage: "Must be a specific tag",
          isValid(val) {
            return val !== "latest";
          }
        },
        {
          templateVariable: "r2_icon",
          question: "Finally, paste an emoji that represents your job"
        }
      ]
    }
  ];
 No newline at end of file
+18 −7
Original line number Diff line number Diff line
@@ -38,12 +38,23 @@ able to work on it before merging your update in the real project.
    If you alter it, we will not be able to merge your job in `r2devops/hub`
    repository (yes, what a shame, after all your hard work...). 😕

1. Create a new directory dedicated to your job in `jobs/` folder if you want to add a new job. You can use the [job
   template](https://gitlab.com/r2devops/hub/-/tree/latest/tools/job_template/job_name)
   as starting point. If you want to modify an existing job, you don't have to create a new directory.
2. Be sure to respect the rules we describe in this guide.
3. Do not update the CI/CD configuration file `.gitlab-ci.yml`.
4. Test your job and ensure it works!
1. If you want to create a new job:
      1. Make sure that you have NPM installed, more about that [here](https://nodejs.org/en/download/){:target=blank}
      1. Install the package `Cookicutter` by executing this command:
        ```shell
         $ npm install -g cookiecutter
        ```
      1. In the `hub` folder, run this command and input the necessary information:
        ```shell
         $ npx cookiecutter
        ```

    !!! info
        Alternatively, you can do the last steps manually by creating a new directory dedicated to your job in `jobs/` folder if you want to add a new job. You can use the [job template](https://gitlab.com/r2devops/hub/-/tree/latest/tools/job_template/r2_jobname) as a starting point. If you want to modify an existing job, you don't have to create a new directory.

1. Be sure to respect the rules we describe in this guide.
1. Do not update the CI/CD configuration file `.gitlab-ci.yml`.
1. Test your job and ensure it works!

### 🚀 Step 3: Merge request

+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ labels_list = ["GitLab", "Build", "Container", "Docker", "PHP", "Testing", "Util
               "Quality", "SAST", "Linter", "Helm", "DAST", "Kubernetes",
               "NPM"]
# A list of paths where the file / directory is considered as not mandatory
optional_paths=["job_name/screenshots", "job_name/screenshots/.gitkeep"]
optional_paths=["r2_jobname/screenshots", "r2_jobname/screenshots/.gitkeep"]
set_labels_list = set(labels_list)


@@ -126,9 +126,9 @@ def check_directory_structure(template_structure, job):
        If at least a file/directory is missing
    """

    # Change "job_name" in template for the actual job name for comparison
    # Change "r2_jobname" in template for the actual job name for comparison
    template_structure_tmp = set(template_structure).symmetric_difference(optional_paths)
    template_structure_tmp = [obj.replace("job_name", f"{job}") for obj in template_structure_tmp]
    template_structure_tmp = [obj.replace("r2_jobname", f"{job}") for obj in template_structure_tmp]

    job_structure = [os.path.join(parent, name) for (parent, subdirs, files)
                     in os.walk(f"{utils.JOBS_DIR}/{job}")
+0 −10
Original line number Diff line number Diff line
name: "{{ job_name }}"
description: "{{ description }}"
default_stage: "{{ stage }}"
icon: "{{ icon }}"
maintainer: "{{ maintainer }}"
license: "{{ license name }}"
images:
  "{{ image_name }}": "{{ image_tag }}"
tools:
  "{{ tool_name }}": "{{ tool_version }}"
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
## Objective

{{ description }}
r2_jobdescription

## How to use it

1. <Your steps>
1. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/<job_name>.yml'
      - remote: 'https://jobs.r2devops.io/latest/r2_jobname.yml'
    ```
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
@@ -15,14 +15,14 @@

## Job details

* Job name: `{{ job_name }}`
* Job name: `r2_jobname`
* Docker image:
[`{{ image }}`](https://hub.docker.com/r/_/{{ image }})
* Default stage: `{{ stage }}`
[`r2_imagename:r2_imagetag`](https://hub.docker.com/r/_/r2_imagename)
* Default stage: `r2_stage`
* When: `always`

### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `VARIABLE` <img width=100/> | A general variable for this job <img width=175/>| `{{ variable }}` <img width=100/>|
| `VARIABLE` <img width=100/> | A general variable for this job <img width=175/>| `Hello R2` <img width=100/>|
Loading