vtex-apps / store-discussion

VTEX IO store builders' community
80 stars 5 forks source link

CI/CD for VTEX IO #672

Open FabricioJuliatto-DBC opened 2 years ago

FabricioJuliatto-DBC commented 2 years ago

What are you trying to accomplish? Please describe.
I am trying to setup a CI/CD pipeline for a new VTEX store. For example, I would like to be able to automatically release a new version of an app after a merge to main. However, I am not aware of any way of making releases other than using Toolbelt and I don't know how to use it in an automated environment. The main issue is the login: the OAuth dialog requires a human to interact with it. Is there any supported way of using Toolbelt in CI/CD or is there another supported way of publishing and deprecating apps that would allow me to do it without human intervention? Thanks!

ganobrega commented 2 years ago

Hey @FabricioJuliatto-DBC !

I'm also excited to create this kind of thing.

One of the things I was thinking to solve this kind of problem is to send ApiKey and ApiToken to retrieve a OAuth Token and put in ~/.vtex/session/tokens.json or ~/.vtex/session/session.json.

Just create a script that sends the follow curl:

curl --request POST \
     --url http://{{account}}.vtexcommercestable.com.br/authorization/token \
     --header 'Accept: application/json; charset=utf-8' \
     --header 'Content-Type: application/json'
     --header 'X-VTEX-API-AppKey: XXX' \
     --header 'X-VTEX-API-AppToken: YYY'

And the response should look like this:

{
  "applicationId": "vtex",
  "token": "358a5bea-07d0-4122-888a-54ab70b5f02f"
}

I'll test and then come back to post if it worked.

ganobrega commented 2 years ago

Hey @FabricioJuliatto-DBC !

I'm also excited to create this kind of thing.

One of the things I was thinking to solve this kind of problem is to send ApiKey and ApiToken to retrieve a OAuth Token and put in ~/.vtex/session/tokens.json or ~/.vtex/session/session.json.

Just create a script that sends the follow curl:

curl --request POST \
     --url http://{{account}}.vtexcommercestable.com.br/authorization/token \
     --header 'Accept: application/json; charset=utf-8' \
     --header 'Content-Type: application/json'
     --header 'X-VTEX-API-AppKey: XXX' \
     --header 'X-VTEX-API-AppToken: YYY'

And the response should look like this:

{
  "applicationId": "vtex",
  "token": "358a5bea-07d0-4122-888a-54ab70b5f02f"
}

I'll test and then come back to post if it worked.

I'm taking a look at the VTEX ID documentations, I think it's the way, as the segment I mentioned above doesn't generate a token for authentication (JWT).

  1. https://github.com/vtex/toolbelt/blob/master/src/api/clients/IOClients/external/VTEXID.ts
  2. https://developers.vtex.com/vtex-rest-api/docs/login-integration-guide-webstore-oauth2#configuring-your-identity-provider-for-user-login-in-vtex-stores
  3. https://help.vtex.com/en/tutorial/crear-autenticacion-oauth2--21LbTSTgag4MsuisQsyIm6
ganobrega commented 2 years ago

Hey!

Maybe I found the solution!

I've spent a few hours since then. I've tried to rewrite toolbelt login method. Then studying about VTEX providers I found one they didn't list. The provider key is called apptoken.

Captura de Tela 2022-02-03 às 01 59 40

Some searches on github VTEX's repositories related to /vtexid/apptoken found the following file: https://github.com/vtex/search-tests/blob/3ee5c1454f088cca83089296bd360f3793095ab0/ci/createSession.js

Look at this code snippet:

const payload = {
    appkey: '<your-vtex-app-key>',
    apptoken: '<your-vtex-app-token>',
  }

  return fetch(
      `http://api.vtexcommercestable.com.br/api/vtexid/apptoken/login?an=${ACCOUNT}`,
      {
        method: 'POST',
        body: JSON.stringify(payload),
        headers: { 'Content-Type': 'application/json' },
      }
    )
      .then((res) => res.json())
      .then((res) => res.token)

I changed the base to: https://vtexid.vtex.com.br/api/vtexid/apptoken/login?an=${ACCOUNT} and successfully returned the token and expiration date. I haven't tested the Token yet to see if it works, but just by passing a valid appKey and appToken it already gave me a token. Passing invalid keys, returns WrongCredentials.

That's it Bro! If the solution was good, give a reaction!

PS: This file that i've found do exactly what you need. Because it's saves the token to session.json and tokens.json files

borjahs commented 2 years ago

Hi, I'm trying to do this same thing with no success. I tried https://vtexid.vtex.com.br/api/vtexid/apptoken/login?an=${ACCOUNT} with postman + appkey & apptoken but didn't get any response back. Also tried the url from createSession.js and same result. Could it be that it no longer works? Coudn't even try the part of modifying session.json beacuse I never got the token.

rgangarde commented 2 years ago

hi all,

I am also trying to setup CICD for my application. I am able to login to vtex as a part of CI. Main problem now is, when I run any of below commnds

  1. vtex link
  2. vtex install
  3. vtex publish
  4. vtex deploy

It prompts to enter "Y/N" options, which needs to be avoided in CI/CD. And also, it does not prompt always.

There is --yes flag which can be passed but it is not available for some of the above commands.

Any idea how to resolve this?

MatiasRN commented 2 years ago

Hi , how could to solve the login on the CI?

You can pass and argument in the shell to answer Y or N:

echo Y | vtex link echo Y | vtex install etc

ericklb84 commented 1 year ago

@MatiasRN

right way is: yes | yes [Quantity necessary] | vtex ...

Sebaavt95 commented 1 year ago

Hi @rgangarde, how could to solve the login on the CI?

HugoLaguna commented 1 year ago

I'm using with GitHub actions this pipeline and works good! https://github.com/marketplace/actions/vtex-toolbelt-action

Sebaavt95 commented 1 year ago

Hi @ericklb84, where should I write the bash commands to automatically respond to prompts? And when should I run them?

mintuguptha commented 8 months ago

Hy Team, can i get the details of whole ci for vtex deployment. Generally we loign using vtex login acc_name then it pops for authentication , now how can i do in jenkins