Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As a dev, I need to create function to generate Github CI/CD workflow #8

Open
Dr0p42 opened this issue May 23, 2023 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@Dr0p42
Copy link
Contributor

Dr0p42 commented May 23, 2023

Implement Github CI/CD Workflow for Naas space

This issue aims to implement a Github CI/CD workflow generator for a Naas space. The workflow will be triggered when a new release/tag is created and managed by the semantic-release process.

Specifications

  • Implement the function naas.space.generate_ci(space_name, registry_name, dockerfile_path, docker_context, ci_type) in Python.
  • The CI/CD workflow should:
    1. Checkout the code
    2. Use a CI/CD variable/secret to authenticate on auth.naas.ai
    3. Ask for temporary credentials on space.naas.ai/registry/registry_name/credentials to be able to login and push the built container
    4. Docker login against the container registry
    5. Get the url of the space by calling space.naas.ai/registry/registry_name
    6. Build the container
    7. Tag the container
    8. Push the container
    9. Update the space version by calling PUT space.naas.ai/space/space_name

GPT4 - Helpers

Creating a Github CI/CD workflow that will be triggered on new tags

To create a Github CI/CD workflow that is triggered on new tags, include the following in your workflow YAML file:

on:
  push:
    tags:
      - '*'

This will ensure the workflow is only triggered on new tags, and not on every push to the repository.

Using Jinja2 with Python to template a file

Jinja2 is a popular templating engine for Python. To use Jinja2 to template a file, follow these steps:

  1. Install Jinja2: pip install jinja2
  2. Create a template file (e.g., template.j2) with placeholders for variable values, using the double curly brace syntax: {{ variable_name }}
  3. In your Python script, import Jinja2 and load the template file:
from jinja2 import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('template.j2')
  1. Render the template with the desired variable values:
rendered_template = template.render(variable_name=value)
  1. Save the rendered template to a new file:
with open('output_file.yaml', 'w') as output_file:
    output_file.write(rendered_template)

Replace output_file.yaml with the desired output file name, and ensure the variable names in the template match the variables passed to the render() function.

Estimate: 1
Priority: Medium

@Dr0p42 Dr0p42 added the enhancement New feature or request label May 23, 2023
@Dr0p42 Dr0p42 moved this from 📋 Backlog to 🔖 Ready in ⚡️ Product Roadmap May 25, 2023
@Dr0p42
Copy link
Contributor Author

Dr0p42 commented Jul 6, 2023

I will detailed this one a bit more @viniciusdc

@FlorentLvr FlorentLvr moved this from 🔖 Ready to 📋 Backlog in ⚡️ Product Roadmap May 23, 2024
@jravenel jravenel changed the title Create function to generate Github CI/CD workflow As a dev, I need to create function to generate Github CI/CD workflow Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

2 participants