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

refactor(Function): use cloud function 2gen #107

Merged
merged 23 commits into from
Jun 22, 2022

Conversation

wisley7l
Copy link
Member

@wisley7l wisley7l commented Jun 17, 2022

Referente ao issue [#106]

@wisley7l wisley7l requested a review from leomp12 June 17, 2022 20:39
Copy link
Member

@leomp12 leomp12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pra formalizar o que comentamos, a princípio mantemos a função na v1 e duplicamos criando outra na v2, deve ficar algo como:

exports[functionName] = functions.https.onRequest(server)
exports[`${functionName}v2`] = functionsV2.https.onRequest(server)

Aí pegamos o URL da nova função e substituímos em uma segunda PR, antes disso onde faz referência ao ...cloudfunctions.net/... segue como tá (no workflow de deploy, env...)

}

client.functions.config.set(config, { project })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uai mas por que parou de enviar o config no deploy da função?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não funciona mais? Não mudou só sintaxe?

@@ -36,12 +36,13 @@
"homepage": "https://github.com/ecomplus/application-starter#readme",
"dependencies": {
"dotenv": "^10.0.0",
"firebase-tools": "^8.20.0",
"firebase-admin": "^10.3.0",
"firebase-tools": "^11.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por que firebase-admin aqui?
O package da function tá na pasta functions, lá que precisa (e sempre teve) do firebase-admin nas dependências...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nesse packages.json no root são só dev deps pra deploy, lint, etc...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@leomp12 leomp12 Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E inclusive isso aqui tá gerando um conflito na PR no package-lock.json (aka não tem como dar merge 🙃 )

Comment on lines 36 to 37
const envDir = path.resolve(__dirname, '../functions')
fs.writeFileSync(`${envDir}/.env`, env.join('\n'), 'utf-8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse negócio ficou meio gambs né 🙃


const documentRef = admin.firestore().doc(`running/${storeId}`)
documentRef.get()
const documentRef = admin.firestore().doc(`running/${storeId}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa collection running era um workaround pra esse problema da (falta de) concorrência mesmo, ideal é até remover esse troço agora...

Comment on lines 15 to 16
const bodyParser = require('body-parser')
const bodyParser = express
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ué 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entendi essa mudança aqui não viu, acho que vai dar pau aí tentar parsear JSON ...

@wisley7l wisley7l requested a review from leomp12 June 20, 2022 21:30
Comment on lines 2 to 18
const { pkg, server } = require('firebase-functions').config()
const functionName = server.functionName || 'app'

require('dotenv').config()

const pkg = {
name: process.env.NAME,
version: process.env.VERSION,
}

const server = {
operator_token: process.env.SERVER_OPERATOR_TOKEN,
}

if(process.env.FUNCTION_NAME){
server.functionName = process.env.FUNCTION_NAME
}

const functionName = server && server.functionName ? server.functionName : 'app'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#107 (comment)
Então , ainda tô nessa aí 😬
Por que trocar o config nativo por .env?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://firebase.google.com/docs/functions/beta/config-env

Aqui fala que o functions.config() foi removido no firebase 2gen e que ele foi substituído por variáveis de ambiente.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certo, mas nesse caso (já que .env passou a ter suporte nativo) não precisamos do require('dotenv').config(), precisamos? Pela doc aí parece não precisar, parece que o próprio Firebase já faz isso runtime...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fato. Realmente não precisar.

@@ -36,12 +36,13 @@
"homepage": "https://github.com/ecomplus/application-starter#readme",
"dependencies": {
"dotenv": "^10.0.0",
"firebase-tools": "^8.20.0",
"firebase-admin": "^10.3.0",
"firebase-tools": "^11.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -36,12 +36,13 @@
"homepage": "https://github.com/ecomplus/application-starter#readme",
"dependencies": {
"dotenv": "^10.0.0",
"firebase-tools": "^8.20.0",
"firebase-admin": "^10.3.0",
"firebase-tools": "^11.0.1",
Copy link
Member

@leomp12 leomp12 Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E inclusive isso aqui tá gerando um conflito na PR no package-lock.json (aka não tem como dar merge 🙃 )

@wisley7l wisley7l requested a review from leomp12 June 21, 2022 13:27
Copy link
Member

@leomp12 leomp12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fora a diferença config/env, as alterações no webhook também deveriam ser aplicadas só no server na function v2, certo? Não é melhor a gente duplicar os arquivos necessários e editar, mantendo os originais pra function em produção?

Outra opção é você fazer um outro deploy do app (em outro app do Firebase), com o source proposto já pra v2, faz o deploy dele normalmente e testamos primeiro em uma loja teste, depois damos merge aqui ainda mantendo a function v1, pegamos o URL da v2 e depois removemos a v1 em produção...

functions/__env.js Outdated Show resolved Hide resolved
.github/workflows/deploy.yml Outdated Show resolved Hide resolved
.github/workflows/deploy.yml Outdated Show resolved Hide resolved
.github/workflows/deploy.yml Outdated Show resolved Hide resolved
.github/workflows/deploy.yml Outdated Show resolved Hide resolved
.github/workflows/deploy.yml Outdated Show resolved Hide resolved
Copy link
Member

@leomp12 leomp12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pelo menos por enquanto (especialmente sem mexer no script de deploy) é bom tentar manter o suporte pra ambos (config e env), não?

functions/__env.js Outdated Show resolved Hide resolved
functions/__env.js Outdated Show resolved Hide resolved
@leomp12 leomp12 merged commit eff3357 into master Jun 22, 2022
@leomp12 leomp12 deleted the refactor/cloud-function-2gen branch June 23, 2022 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants