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

How to prevent an API from being promoted across environments #435

Closed
fabienmazieres opened this issue Dec 5, 2023 · 15 comments
Closed
Labels
question Further information is requested

Comments

@fabienmazieres
Copy link
Contributor

Please describe the feature.

Our developers have some API they are using in Dev that should not progress to other environments and I am wondering what will be the best method to prevent (or at least make unusable) the deployment of specific API.

I was thinking to have the API being deployed but the configuration file for prod is sending the traffic to a dummy URL (i.e. https://apimblock.mycompany.com/):

configuration.prod.yaml:

apis:
  - name: api-for-dev-only
    properties:
      serviceUrl: "https://apimblock.mycompany.com"

but that feels hacky and I wish there could be a flag to specifically prevent an API to be deployed, such as:
configuration.prod.yaml:

apis:
  - name: api-for-dev-only
    do-not-deploy: true

Any other way this can be achieved without a new flag in the config?

Copy link

github-actions bot commented Dec 5, 2023

  Thank you for opening this issue! Please be patient while we will look into it and get back to you as this is an open source project. In the meantime make sure you take a look at the [closed issues](https://github.com/Azure/apiops/issues?q=is%3Aissue+is%3Aclosed) in case your question has already been answered. Don't forget to provide any additional information if needed (e.g. scrubbed logs, detailed feature requests,etc.).
  Whenever it's feasible, please don't hesitate to send a Pull Request (PR) our way. We'd greatly appreciate it, and we'll gladly assess and incorporate your changes.

@waelkdouh
Copy link
Contributor

Please take a look at this .

Please make sure you read the docs and the wiki.

@waelkdouh waelkdouh changed the title [FEATURE REQ] Prevent an API to be deployed in specific environments How to prevent an API from being promoted across environments Dec 5, 2023
@waelkdouh waelkdouh added the question Further information is requested label Dec 5, 2023
@fabienmazieres
Copy link
Contributor Author

fabienmazieres commented Dec 5, 2023

Thank you @waelkdouh for the quick response.
We are using a mono repo and we have a configuration for each of our environments however I am not really sure how the document answer my question.
One part relevant to the extractor may be of use for me:

A apiNames section which includes a bogus name (e.g. ignore) in configuration (apiNames:[ignore]) means no apis will be extracted.

So does that means that if I make a bogus API entry details it will prevent the API to be deployed?

@waelkdouh
Copy link
Contributor

First of all you would have to use a repository for each team. Then within each repository you would specify which apis you want to extract using the configuration.extractor.yaml. This way when you get to the publishing part the publisher will publish only what you have extracted. By using multiple repositories you can allow each team to have their own configuration files for each environment. Remember our tools embraces git so any tricks that git allows (e.g. gitignore) can be used here as well.

@fabienmazieres
Copy link
Contributor Author

@waelkdouh ,

We do not want to use multiple repo, the goal of using APIOps was to move to a centralized repo for all APIM config to enhance security and make it easier to maintain our APIMs.

Could it be something easily implemented as a new feature or is it quite complex due to dependencies (i.e. if the API is not deployed but is part of a product configuration, then the product will fail to deploy)?

@waelkdouh
Copy link
Contributor

Thank you @waelkdouh for the quick response. We are using a mono repo and we have a configuration for each of our environments however I am not really sure how the document answer my question. One part relevant to the extractor may be of use for me:

A apiNames section which includes a bogus name (e.g. ignore) in configuration (apiNames:[ignore]) means no apis will be extracted.

So does that means that if I make a bogus API entry details it will prevent the API to be deployed?

If you don't enter anything in the apis section in the extractor then it will extract everything. If you specify an api/s then it will only extract the specified ones.

@fabienmazieres
Copy link
Contributor Author

@waelkdouh,

We are not intending to work with the extractor at this point:
Teams update the spec files directly into the repo and this will push the config to dev and other environment.
Could the publisher be configured to behave the same way as the extracror, if the API is not defined it will be skipped?

@waelkdouh
Copy link
Contributor

waelkdouh commented Jan 28, 2024

The publisher utilizes git to capture the differences between commits. You can always use the git ignore file to help you with what you're trying to achieve here.

@anish2808
Copy link

@waelkdouh ,

We do not want to use multiple repo, the goal of using APIOps was to move to a centralized repo for all APIM config to enhance security and make it easier to maintain our APIMs.

Could it be something easily implemented as a new feature or is it quite complex due to dependencies (i.e. if the API is not deployed but is part of a product configuration, then the product will fail to deploy)?

Hi @fabienmazieres - I'm in the process of implementing a mono-repo approach for ApiOps as well. Multi-team with multiple environments (Dev,QA,Prod). I would like to understand:

  1. The branching strategy you're employing
  2. If you're using Releases in Azure Pipelines for publishing or just using the Publisher pipeline with environments to handle this

Any inputs would be highly appreciated.

@fabienmazieres
Copy link
Contributor Author

fabienmazieres commented Jan 31, 2024 via email

@zcarroll4
Copy link
Contributor

zcarroll4 commented Apr 19, 2024

@fabienmazieres if you're still looking for a solution and I understand your question correctly. All you would have to do when you run the publisher command is to include a publisher config .yaml file for each region. And as you can see the differences below. These would be three separate files (publisher.dev.yaml, publisher.qa.yaml & publisher.prod.yaml)

image

@ics-development
Copy link

Guys, does this work for revisions, so I only want to publish the latest revisions for example. The reason being, I cant get the publisher to work when I have multiple revisions:

info: Publisher[0]
Processing modified files in commit ID...
info: Publisher[0]
Putting API ipoint-shifts...
info: Publisher[0]
Putting API ipoint-shifts;rev=1...
crit: Publisher[0]
System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/rg-apim-staging/providers/Microsoft.ApiManagement/service/apim-acacium-staging/apis/ipoint-shifts?api-version=2022-04-01-preview&asyncId=663162474634610610534ed4&asyncCode=201 failed with status code 409. Content is '{"error":{"code":"IdentifierAlreadyInUse","message":"Resource already exists.","details":null}}'.

@zcarroll4
Copy link
Contributor

I had no issues when running the publisher a few days ago with multiple revisions, I however at the time was not using a config yaml file but just publishing everything located in my artifacts folder. If you;re using a config file, what does that look like?

@fabienmazieres
Copy link
Contributor Author

The trick with the config file does not seem to work.

I do have a config file for the different environment (configuration.d1.yaml, configuration.s1.yaml and configuration.p1.yaml) and as an example, an API called cl-as has all the required files into the apis folder, but is not declared into any of the configuration files.
This API was deployed in all APIM environments.
We are mainly doing publishing with last commit in d1 and s1, p1 is published via all artifacts when we need to release to prod. s1 and d1 are sometimes published with full artifact when things have gone wrong and need catchup.

@zcarroll4
Copy link
Contributor

You may want to look at the parameter PUBLISH_CONFIGURATION_ARTIFACTS. I know it used to exist in previous versions. But from my understanding, if that was set to true - then it would only deploy artifacts that are defined in the config file. Whereas if that value was false, it would deploy everything within the artifacts folder. @waelkdouh or @guythetechie may have more insight to what is the best approach now with that variable being deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants