mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 16:28:11 +00:00
Merge branch 'main' into snyk-upgrade-5d7f8d449135ab93a65e39dda5bbc136
This commit is contained in:
@@ -3,35 +3,86 @@ name: Push to Docker Hub
|
|||||||
on: [workflow_dispatch]
|
on: [workflow_dispatch]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
|
||||||
|
backend-image:
|
||||||
|
name: Build backend image
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
-
|
||||||
|
name: ☁️ Checkout source
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
-
|
-
|
||||||
name: Set up QEMU
|
name: 🔧 Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: 🔧 Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
-
|
-
|
||||||
name: Login to Docker Hub
|
name: 🐋 Login to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push backend
|
name: 📦 Build backend and export to Docker
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
load: true
|
||||||
|
context: backend
|
||||||
|
tags: infisical/backend:test
|
||||||
|
-
|
||||||
|
name: 🧪 Test backend image
|
||||||
|
run: |
|
||||||
|
docker run --rm infisical/backend:test
|
||||||
|
-
|
||||||
|
name: 📦 Build backend and push
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: backend
|
context: backend
|
||||||
tags: infisical/backend:test
|
tags: infisical/backend:latest
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
|
||||||
|
|
||||||
|
frontend-image:
|
||||||
|
name: Build frontend image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: ☁️ Checkout source
|
||||||
|
uses: actions/checkout@v2
|
||||||
-
|
-
|
||||||
name: Build and push frontend
|
name: 🔧 Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
-
|
||||||
|
name: 🔧 Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
-
|
||||||
|
name: 🐋 Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: 📦 Build frontend and export to Docker
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
load: true
|
||||||
|
context: frontend
|
||||||
|
tags: infisical/frontend:test
|
||||||
|
build-args: |
|
||||||
|
POSTHOG_API_KEY=${{ secrets.PUBLIC_POSTHOG_API_KEY }}
|
||||||
|
-
|
||||||
|
name: 🧪 Test frontend image
|
||||||
|
run: |
|
||||||
|
docker run --rm infisical/frontend:test
|
||||||
|
-
|
||||||
|
name: 📦 Build frontend and push
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
file: frontend/Dockerfile.dev
|
|
||||||
context: frontend
|
context: frontend
|
||||||
tags: infisical/frontend:test
|
tags: infisical/frontend:latest
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ We are currently working hard to make Infisical more extensive. Need any integra
|
|||||||
|
|
||||||
Whether it's big or small, we love contributions ❤️ Check out our guide to see how to [get started](https://infisical.com/docs/contributing/overview).
|
Whether it's big or small, we love contributions ❤️ Check out our guide to see how to [get started](https://infisical.com/docs/contributing/overview).
|
||||||
|
|
||||||
Not sure where to get started? [Book a free, non-pressure pairing sessions with one of our teammates](mailto:[email protected]?subject=Pairing%20session&body=I'd%20like%20to%20do%20a%20pairing%20session!)!
|
Not sure where to get started? You can:
|
||||||
|
- [Book a free, non-pressure pairing sessions with one of our teammates](mailto:[email protected]?subject=Pairing%20session&body=I'd%20like%20to%20do%20a%20pairing%20session!)!
|
||||||
|
- Join our <a href="https://join.slack.com/t/infisical-users/shared_invite/zt-1kdbk07ro-RtoyEt_9E~fyzGo_xQYP6g">Slack</a>, and ask us any questions there.
|
||||||
|
|
||||||
## 💚 Community & Support
|
## 💚 Community & Support
|
||||||
|
|
||||||
|
|||||||
Generated
+85
-26
@@ -19,13 +19,13 @@
|
|||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"express-rate-limit": "^6.5.1",
|
"express-rate-limit": "^6.7.0",
|
||||||
"express-validator": "^6.14.2",
|
"express-validator": "^6.14.2",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"helmet": "^5.1.1",
|
"helmet": "^5.1.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"jsrp": "^0.2.4",
|
"jsrp": "^0.2.4",
|
||||||
"mongoose": "^6.7.1",
|
"mongoose": "^6.7.2",
|
||||||
"nodemailer": "^6.8.0",
|
"nodemailer": "^6.8.0",
|
||||||
"posthog-node": "^2.1.0",
|
"posthog-node": "^2.1.0",
|
||||||
"query-string": "^7.1.1",
|
"query-string": "^7.1.1",
|
||||||
@@ -2608,13 +2608,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sentry/node": {
|
"node_modules/@sentry/node": {
|
||||||
"version": "7.17.4",
|
"version": "7.19.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.17.4.tgz",
|
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.19.0.tgz",
|
||||||
"integrity": "sha512-cR+Gsir9c/tzFWxvk4zXkMQy6tNRHEYixHrb88XIjZVYDqDS9l2/bKs5nJusdmaUeLtmPp5Et2o7RJyS7gvKTQ==",
|
"integrity": "sha512-yG7Tx32WqOkEHVotFLrumCcT9qlaSDTkFNZ+yLSvZXx74ifsE781DzBA9W7K7bBdYO3op+p2YdsOKzf3nPpAyQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/core": "7.17.4",
|
"@sentry/core": "7.19.0",
|
||||||
"@sentry/types": "7.17.4",
|
"@sentry/types": "7.19.0",
|
||||||
"@sentry/utils": "7.17.4",
|
"@sentry/utils": "7.19.0",
|
||||||
"cookie": "^0.4.1",
|
"cookie": "^0.4.1",
|
||||||
"https-proxy-agent": "^5.0.0",
|
"https-proxy-agent": "^5.0.0",
|
||||||
"lru_map": "^0.3.3",
|
"lru_map": "^0.3.3",
|
||||||
@@ -2624,6 +2624,39 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@sentry/node/node_modules/@sentry/core": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-YF9cTBcAnO4R44092BJi5Wa2/EO02xn2ziCtmNgAVTN2LD31a/YVGxGBt/FDr4Y6yeuVehaqijVVvtpSmXrGJw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@sentry/types": "7.19.0",
|
||||||
|
"@sentry/utils": "7.19.0",
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@sentry/node/node_modules/@sentry/types": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-oGRAT6lfzoKrxO1mvxiSj0XHxWPd6Gd1wpPGuu6iJo03xgWDS+MIlD1h2unqL4N5fAzLjzmbC2D2lUw50Kn2pA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@sentry/node/node_modules/@sentry/utils": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-2L6lq+c9Ol2uiRxQDdcgoapmHJp24MhMN0gIkn2alSfMJ+ls6bGXzQHx6JAIdoOiwFQXRZHKL9ecfAc8O+vItA==",
|
||||||
|
"dependencies": {
|
||||||
|
"@sentry/types": "7.19.0",
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@sentry/tracing": {
|
"node_modules/@sentry/tracing": {
|
||||||
"version": "7.19.0",
|
"version": "7.19.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.19.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.19.0.tgz",
|
||||||
@@ -4550,9 +4583,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express-rate-limit": {
|
"node_modules/express-rate-limit": {
|
||||||
"version": "6.6.0",
|
"version": "6.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.7.0.tgz",
|
||||||
"integrity": "sha512-HFN2+4ZGdkQOS8Qli4z6knmJFnw6lZed67o6b7RGplWeb1Z0s8VXaj3dUgPIdm9hrhZXTRpCTHXA0/2Eqex0vA==",
|
"integrity": "sha512-vhwIdRoqcYB/72TK3tRZI+0ttS8Ytrk24GfmsxDXK9o9IhHNO5bXRiXQSExPQ4GbaE5tvIS7j1SGrxsuWs+sGA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 12.9.0"
|
"node": ">= 12.9.0"
|
||||||
},
|
},
|
||||||
@@ -6485,9 +6518,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongoose": {
|
"node_modules/mongoose": {
|
||||||
"version": "6.7.1",
|
"version": "6.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.7.2.tgz",
|
||||||
"integrity": "sha512-qbagtqSyvIhUz4EWzXC00EA0DJHFrQwlzTlNGX5DjiESoJiPKqkEga1k9hviFKRFgBna+OlW54mkdi+0+AqxCw==",
|
"integrity": "sha512-lrP2V5U1qhaf+z33fiIn7aYAZZ1fVDly+TkFRjTujNBF/FIHESATj2RbgAOSlWqv32fsZXkXejXzeVfjbv35Ow==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bson": "^4.7.0",
|
"bson": "^4.7.0",
|
||||||
"kareem": "2.4.1",
|
"kareem": "2.4.1",
|
||||||
@@ -13091,17 +13124,43 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@sentry/node": {
|
"@sentry/node": {
|
||||||
"version": "7.17.4",
|
"version": "7.19.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.17.4.tgz",
|
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.19.0.tgz",
|
||||||
"integrity": "sha512-cR+Gsir9c/tzFWxvk4zXkMQy6tNRHEYixHrb88XIjZVYDqDS9l2/bKs5nJusdmaUeLtmPp5Et2o7RJyS7gvKTQ==",
|
"integrity": "sha512-yG7Tx32WqOkEHVotFLrumCcT9qlaSDTkFNZ+yLSvZXx74ifsE781DzBA9W7K7bBdYO3op+p2YdsOKzf3nPpAyQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@sentry/core": "7.17.4",
|
"@sentry/core": "7.19.0",
|
||||||
"@sentry/types": "7.17.4",
|
"@sentry/types": "7.19.0",
|
||||||
"@sentry/utils": "7.17.4",
|
"@sentry/utils": "7.19.0",
|
||||||
"cookie": "^0.4.1",
|
"cookie": "^0.4.1",
|
||||||
"https-proxy-agent": "^5.0.0",
|
"https-proxy-agent": "^5.0.0",
|
||||||
"lru_map": "^0.3.3",
|
"lru_map": "^0.3.3",
|
||||||
"tslib": "^1.9.3"
|
"tslib": "^1.9.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@sentry/core": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-YF9cTBcAnO4R44092BJi5Wa2/EO02xn2ziCtmNgAVTN2LD31a/YVGxGBt/FDr4Y6yeuVehaqijVVvtpSmXrGJw==",
|
||||||
|
"requires": {
|
||||||
|
"@sentry/types": "7.19.0",
|
||||||
|
"@sentry/utils": "7.19.0",
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@sentry/types": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-oGRAT6lfzoKrxO1mvxiSj0XHxWPd6Gd1wpPGuu6iJo03xgWDS+MIlD1h2unqL4N5fAzLjzmbC2D2lUw50Kn2pA=="
|
||||||
|
},
|
||||||
|
"@sentry/utils": {
|
||||||
|
"version": "7.19.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.19.0.tgz",
|
||||||
|
"integrity": "sha512-2L6lq+c9Ol2uiRxQDdcgoapmHJp24MhMN0gIkn2alSfMJ+ls6bGXzQHx6JAIdoOiwFQXRZHKL9ecfAc8O+vItA==",
|
||||||
|
"requires": {
|
||||||
|
"@sentry/types": "7.19.0",
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@sentry/tracing": {
|
"@sentry/tracing": {
|
||||||
@@ -14582,9 +14641,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"express-rate-limit": {
|
"express-rate-limit": {
|
||||||
"version": "6.6.0",
|
"version": "6.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.7.0.tgz",
|
||||||
"integrity": "sha512-HFN2+4ZGdkQOS8Qli4z6knmJFnw6lZed67o6b7RGplWeb1Z0s8VXaj3dUgPIdm9hrhZXTRpCTHXA0/2Eqex0vA==",
|
"integrity": "sha512-vhwIdRoqcYB/72TK3tRZI+0ttS8Ytrk24GfmsxDXK9o9IhHNO5bXRiXQSExPQ4GbaE5tvIS7j1SGrxsuWs+sGA==",
|
||||||
"requires": {}
|
"requires": {}
|
||||||
},
|
},
|
||||||
"express-validator": {
|
"express-validator": {
|
||||||
@@ -16023,9 +16082,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongoose": {
|
"mongoose": {
|
||||||
"version": "6.7.1",
|
"version": "6.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.7.2.tgz",
|
||||||
"integrity": "sha512-qbagtqSyvIhUz4EWzXC00EA0DJHFrQwlzTlNGX5DjiESoJiPKqkEga1k9hviFKRFgBna+OlW54mkdi+0+AqxCw==",
|
"integrity": "sha512-lrP2V5U1qhaf+z33fiIn7aYAZZ1fVDly+TkFRjTujNBF/FIHESATj2RbgAOSlWqv32fsZXkXejXzeVfjbv35Ow==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bson": "^4.7.0",
|
"bson": "^4.7.0",
|
||||||
"kareem": "2.4.1",
|
"kareem": "2.4.1",
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"express-rate-limit": "^6.5.1",
|
"express-rate-limit": "^6.7.0",
|
||||||
"express-validator": "^6.14.2",
|
"express-validator": "^6.14.2",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"helmet": "^5.1.1",
|
"helmet": "^5.1.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"jsrp": "^0.2.4",
|
"jsrp": "^0.2.4",
|
||||||
"mongoose": "^6.7.1",
|
"mongoose": "^6.7.2",
|
||||||
"nodemailer": "^6.8.0",
|
"nodemailer": "^6.8.0",
|
||||||
"posthog-node": "^2.1.0",
|
"posthog-node": "^2.1.0",
|
||||||
"query-string": "^7.1.1",
|
"query-string": "^7.1.1",
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
FormatDotenv string = "dotenv"
|
||||||
|
FormatJson string = "json"
|
||||||
|
FormatCSV string = "csv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// exportCmd represents the export command
|
||||||
|
var exportCmd = &cobra.Command{
|
||||||
|
Use: "export",
|
||||||
|
Short: "Used to export environment variables to a file",
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
|
Example: "infisical export --env=prod --format=json > secrets.json",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
PreRun: toggleDebug,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
envName, err := cmd.Flags().GetString("env")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Unable to parse the environment flag")
|
||||||
|
log.Debugln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldExpandSecrets, err := cmd.Flags().GetBool("expand")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Unable to parse the substitute flag")
|
||||||
|
log.Debugln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
projectId, err := cmd.Flags().GetString("projectId")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Unable to parse the project id flag")
|
||||||
|
log.Debugln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
format, err := cmd.Flags().GetString("format")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Unable to parse the format flag")
|
||||||
|
log.Debugln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
envsFromApi, err := util.GetAllEnvironmentVariables(projectId, envName)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
|
||||||
|
log.Debugln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var output string
|
||||||
|
if shouldExpandSecrets {
|
||||||
|
substitutions := util.SubstituteSecrets(envsFromApi)
|
||||||
|
output, err = formatEnvs(substitutions, format)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
output, err = formatEnvs(envsFromApi, format)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print(output)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(exportCmd)
|
||||||
|
exportCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from")
|
||||||
|
exportCmd.Flags().String("projectId", "", "The project ID from which your secrets should be pulled from")
|
||||||
|
exportCmd.Flags().Bool("expand", true, "Parse shell parameter expansions in your secrets")
|
||||||
|
exportCmd.Flags().StringP("format", "f", "dotenv", "Set the format of the output file (dotenv, json, csv)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format according to the format flag
|
||||||
|
func formatEnvs(envs []models.SingleEnvironmentVariable, format string) (string, error) {
|
||||||
|
switch strings.ToLower(format) {
|
||||||
|
case FormatDotenv:
|
||||||
|
return formatAsDotEnv(envs), nil
|
||||||
|
case FormatJson:
|
||||||
|
return formatAsJson(envs), nil
|
||||||
|
case FormatCSV:
|
||||||
|
return formatAsCSV(envs), nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("invalid format flag: %s", format)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format environment variables as a CSV file
|
||||||
|
func formatAsCSV(envs []models.SingleEnvironmentVariable) string {
|
||||||
|
csvString := &strings.Builder{}
|
||||||
|
writer := csv.NewWriter(csvString)
|
||||||
|
writer.Write([]string{"Key", "Value"})
|
||||||
|
for _, env := range envs {
|
||||||
|
writer.Write([]string{env.Key, env.Value})
|
||||||
|
}
|
||||||
|
writer.Flush()
|
||||||
|
return csvString.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format environment variables as a dotenv file
|
||||||
|
func formatAsDotEnv(envs []models.SingleEnvironmentVariable) string {
|
||||||
|
var dotenv string
|
||||||
|
for _, env := range envs {
|
||||||
|
dotenv += fmt.Sprintf("%s='%s'\n", env.Key, env.Value)
|
||||||
|
}
|
||||||
|
return dotenv
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format environment variables as a JSON file
|
||||||
|
func formatAsJson(envs []models.SingleEnvironmentVariable) string {
|
||||||
|
// Dump as a json array
|
||||||
|
json, err := json.Marshal(envs)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Unable to marshal environment variables to JSON")
|
||||||
|
log.Debugln(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(json)
|
||||||
|
}
|
||||||
+5
-40
@@ -47,46 +47,11 @@ var runCmd = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var envsFromApi []models.SingleEnvironmentVariable
|
envsFromApi, err := util.GetAllEnvironmentVariables(projectId, envName)
|
||||||
infisicalToken := os.Getenv(util.INFISICAL_TOKEN_NAME)
|
if err != nil {
|
||||||
if infisicalToken == "" {
|
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
|
||||||
hasUserLoggedInbefore, loggedInUserEmail, err := util.IsUserLoggedIn()
|
log.Debugln(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Info("Unexpected issue occurred while checking login status. To see more details, add flag --debug")
|
|
||||||
log.Debugln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasUserLoggedInbefore {
|
|
||||||
log.Infoln("No logged in user. To login, please run command [infisical login]")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userCreds, err := util.GetUserCredsFromKeyRing(loggedInUserEmail)
|
|
||||||
if err != nil {
|
|
||||||
log.Infoln("Unable to get user creds from key ring")
|
|
||||||
log.Debug(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !util.WorkspaceConfigFileExists() {
|
|
||||||
log.Infoln("Your project is not connected to a project yet. Run command [infisical init]")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
envsFromApi, err = util.GetSecretsFromAPIUsingCurrentLoggedInUser(envName, userCreds)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorln("Something went wrong when pulling secrets using your logged in credentials. If the issue persists, double check your project id/try logging in again.")
|
|
||||||
log.Debugln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
envsFromApi, err = util.GetSecretsFromAPIUsingInfisicalToken(infisicalToken, envName, projectId)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
|
|
||||||
log.Debugln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldExpandSecrets {
|
if shouldExpandSecrets {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -184,6 +185,52 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string,
|
|||||||
return listOfEnv, nil
|
return listOfEnv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAllEnvironmentVariables(projectId string, envName string) ([]models.SingleEnvironmentVariable, error) {
|
||||||
|
var envsFromApi []models.SingleEnvironmentVariable
|
||||||
|
infisicalToken := os.Getenv(INFISICAL_TOKEN_NAME)
|
||||||
|
if infisicalToken == "" {
|
||||||
|
hasUserLoggedInbefore, loggedInUserEmail, err := IsUserLoggedIn()
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Unexpected issue occurred while checking login status. To see more details, add flag --debug")
|
||||||
|
log.Debugln(err)
|
||||||
|
return envsFromApi, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasUserLoggedInbefore {
|
||||||
|
log.Infoln("No logged in user. To login, please run command [infisical login]")
|
||||||
|
return envsFromApi, fmt.Errorf("user not logged in")
|
||||||
|
}
|
||||||
|
|
||||||
|
userCreds, err := GetUserCredsFromKeyRing(loggedInUserEmail)
|
||||||
|
if err != nil {
|
||||||
|
log.Infoln("Unable to get user creds from key ring")
|
||||||
|
log.Debug(err)
|
||||||
|
return envsFromApi, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !WorkspaceConfigFileExists() {
|
||||||
|
log.Infoln("Your project is not connected to a project yet. Run command [infisical init]")
|
||||||
|
return envsFromApi, fmt.Errorf("project not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
envsFromApi, err = GetSecretsFromAPIUsingCurrentLoggedInUser(envName, userCreds)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Something went wrong when pulling secrets using your logged in credentials. If the issue persists, double check your project id/try logging in again.")
|
||||||
|
log.Debugln(err)
|
||||||
|
return envsFromApi, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
envsFromApi, err := GetSecretsFromAPIUsingInfisicalToken(infisicalToken, envName, projectId)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
|
||||||
|
log.Debugln(err)
|
||||||
|
return envsFromApi, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return envsFromApi, nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models.Workspace, err error) {
|
func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models.Workspace, err error) {
|
||||||
// create http client
|
// create http client
|
||||||
httpClient := resty.New().
|
httpClient := resty.New().
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: infisical/backend
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend/src:/app/src
|
- ./backend/src:/app/src
|
||||||
- ./backend/nodemon.json:/app/nodemon.json
|
- ./backend/nodemon.json:/app/nodemon.json
|
||||||
@@ -43,7 +42,6 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile.dev
|
dockerfile: Dockerfile.dev
|
||||||
image: infisical/frontend
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./frontend/pages:/app/pages
|
- ./frontend/pages:/app/pages
|
||||||
- ./frontend/public:/app/public
|
- ./frontend/public:/app/public
|
||||||
@@ -52,12 +50,8 @@ services:
|
|||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_ENV=development
|
- NEXT_PUBLIC_ENV=development
|
||||||
- NEXT_PUBLIC_WEBSITE_URL=${SITE_URL}
|
|
||||||
- NEXT_PUBLIC_POSTHOG_HOST=${POSTHOG_HOST}
|
|
||||||
- NEXT_PUBLIC_POSTHOG_API_KEY=${POSTHOG_PROJECT_API_KEY}
|
|
||||||
- NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
|
- NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
|
||||||
- NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
|
- NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
|
||||||
- NEXT_PUBLIC_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
|
|
||||||
networks:
|
networks:
|
||||||
- infisical-dev
|
- infisical-dev
|
||||||
|
|
||||||
@@ -78,6 +72,8 @@ services:
|
|||||||
container_name: infisical-dev-mongo-express
|
container_name: infisical-dev-mongo-express
|
||||||
image: mongo-express
|
image: mongo-express
|
||||||
restart: always
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_USERNAME}
|
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_USERNAME}
|
||||||
@@ -93,4 +89,4 @@ volumes:
|
|||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
infisical-dev:
|
infisical-dev:
|
||||||
|
|||||||
+3
-14
@@ -17,14 +17,10 @@ services:
|
|||||||
- infisical
|
- infisical
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
platform: linux/amd64
|
|
||||||
container_name: infisical-backend
|
container_name: infisical-backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
- mongo
|
||||||
build:
|
|
||||||
context: ./backend
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: infisical/backend
|
image: infisical/backend
|
||||||
command: npm run start
|
command: npm run start
|
||||||
env_file: .env
|
env_file: .env
|
||||||
@@ -34,24 +30,17 @@ services:
|
|||||||
- infisical
|
- infisical
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
platform: linux/amd64
|
|
||||||
container_name: infisical-frontend
|
container_name: infisical-frontend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
build:
|
|
||||||
context: ./frontend
|
|
||||||
dockerfile: Dockerfile.prod
|
|
||||||
image: infisical/frontend
|
image: infisical/frontend
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_ENV=production
|
# - NEXT_PUBLIC_POSTHOG_API_KEY=${POSTHOG_PROJECT_API_KEY}
|
||||||
- NEXT_PUBLIC_WEBSITE_URL=${SITE_URL}
|
- INFISICAL_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
|
||||||
- NEXT_PUBLIC_POSTHOG_HOST=${POSTHOG_HOST}
|
|
||||||
- NEXT_PUBLIC_POSTHOG_API_KEY=${POSTHOG_PROJECT_API_KEY}
|
|
||||||
- NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
|
- NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
|
||||||
- NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
|
- NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
|
||||||
- NEXT_PUBLIC_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
|
|
||||||
networks:
|
networks:
|
||||||
- infisical
|
- infisical
|
||||||
|
|
||||||
@@ -73,4 +62,4 @@ volumes:
|
|||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
infisical:
|
infisical:
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
title: "infisical export"
|
||||||
|
---
|
||||||
|
|
||||||
|
```bash
|
||||||
|
infisical export [options]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Export environment variables from the platform into a file format.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
| Option | Description | Default value |
|
||||||
|
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
||||||
|
| `--env` | Used to set the environment that secrets are pulled from. Accepted values: `dev`, `staging`, `test`, `prod` | `dev` |
|
||||||
|
| `--projectId` | Used to determine from which infisical project your secrets will be exported from (only required if injecting via the service token method). | `None` |
|
||||||
|
| `--expand` | Parse shell parameter expansions in your secrets (e.g., `${DOMAIN}`) | `true` |
|
||||||
|
| `--format` | Format of the output file. Accepted values: `dotenv`, `csv` and `json` | `dotenv` |
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Export variables to a .env file
|
||||||
|
infisical export > .env
|
||||||
|
|
||||||
|
# Export variables to a CSV file
|
||||||
|
infisical export --format=csv > secrets.csv
|
||||||
|
|
||||||
|
# Export variables to a JSON file
|
||||||
|
infisical export --format=json > secrets.json
|
||||||
|
```
|
||||||
@@ -9,24 +9,24 @@ Configuring Infisical requires setting some environment variables. There is a fi
|
|||||||
|
|
||||||
| Variable | Description | Default Value |
|
| Variable | Description | Default Value |
|
||||||
| ---------------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------- |
|
| ---------------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------- |
|
||||||
| `PRIVATE_KEY` | ❗️ NaCl-generated server secret key | `None` |
|
| `PRIVATE_KEY` | ❗️ NaCl-generated server secret key | `None` |
|
||||||
| `PUBLIC_KEY` | ❗️ NaCl-generated server public key | `None` |
|
| `PUBLIC_KEY` | ❗️ NaCl-generated server public key | `None` |
|
||||||
| `ENCRYPTION_KEY` | ❗️ Strong hex encryption key | `None` |
|
| `ENCRYPTION_KEY` | ❗️ Strong hex encryption key | `None` |
|
||||||
| `JWT_SIGNUP_SECRET` | ❗️JWT token secret | `None` |
|
| `JWT_SIGNUP_SECRET` | ❗️ JWT token secret | `None` |
|
||||||
| `JWT_REFRESH_SECRET` | ❗️ JWT token secret | `None` |
|
| `JWT_REFRESH_SECRET` | ❗️ JWT token secret | `None` |
|
||||||
| `JWT_AUTH_SECRET` | ❗️ JWT token secret | `None` |
|
| `JWT_AUTH_SECRET` | ❗️ JWT token secret | `None` |
|
||||||
| `JWT_SIGNUP_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `15m` |
|
| `JWT_SIGNUP_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `15m` |
|
||||||
| `JWT_REFRESH_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `90d` |
|
| `JWT_REFRESH_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `90d` |
|
||||||
| `JWT_AUTH_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `10d` |
|
| `JWT_AUTH_LIFETIME` | JWT token lifetime expressed in seconds or a string describing a time span (e.g. 60, "2 days", "10h", "7d") | `10d` |
|
||||||
| `EMAIL_TOKEN_LIFETIME` | Email OTP/magic-link lifetime expressed in seconds | `86400` |
|
| `EMAIL_TOKEN_LIFETIME` | Email OTP/magic-link lifetime expressed in seconds | `86400` |
|
||||||
| `MONGO_URL` | ❗️ MongoDB instance connection string either to container instance or MongoDB Cloud | `None` |
|
| `MONGO_URL` | ❗️ MongoDB instance connection string either to container instance or MongoDB Cloud | `None` |
|
||||||
| `MONGO_USERNAME` | MongoDB username if using container | `None` |
|
| `MONGO_USERNAME` | MongoDB username if using container | `None` |
|
||||||
| `MONGO_PASSWORD` | MongoDB password if using container | `None` |
|
| `MONGO_PASSWORD` | MongoDB password if using container | `None` |
|
||||||
| `SITE_URL` | ❗️ Site URL - should be an absolute URL including the protocol (e.g. `https://app.infisical.com`) | `None` |
|
| `SITE_URL` | ❗️ Site URL - should be an absolute URL including the protocol (e.g. `https://app.infisical.com`) | `None` |
|
||||||
| `SMT_HOST` | Whether the user joined the community | `smtp.gmail.com` |
|
| `SMTP_HOST` | Hostname to connect to for establishing SMTP connections | `smtp.gmail.com` |
|
||||||
| `SMTP_NAME` | Hostname to connect to for establishing SMTP connections (e.g. `Team`) | `None` |
|
| `SMTP_NAME` | Name label to be used in From field (e.g. `Team`) | `None` |
|
||||||
| `SMTP_USERNAME` | ❗️ Credential to connect to host (e.g. `[email protected]`) | `None` |
|
| `SMTP_USERNAME` | ❗️ Credential to connect to host (e.g. `[email protected]`) | `None` |
|
||||||
| `SMTP_PASSWORD` | ❗️ Credential to connect to host | `None` |
|
| `SMTP_PASSWORD` | ❗️ Credential to connect to host | `None` |
|
||||||
| `TELEMETRY_ENABLED` | `true` or `false`. [More](../overview). | `true` |
|
| `TELEMETRY_ENABLED` | `true` or `false`. [More](../overview). | `true` |
|
||||||
| `OAUTH_CLIENT_SECRET_HEROKU` | OAuth client secret for Heroku integration | `None` |
|
| `OAUTH_CLIENT_SECRET_HEROKU` | OAuth client secret for Heroku integration | `None` |
|
||||||
| `OAUTH_TOKEN_URL_HEROKU` | OAuth token URL for Heroku integration | `None` |
|
| `OAUTH_TOKEN_URL_HEROKU` | OAuth token URL for Heroku integration | `None` |
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
ARG POSTHOG_HOST=https://app.posthog.com
|
||||||
|
ARG POSTHOG_API_KEY=posthog-api-key
|
||||||
|
|
||||||
|
FROM node:16-alpine AS deps
|
||||||
|
# Install dependencies only when needed. Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
|
# RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy over dependency files
|
||||||
|
COPY package.json package-lock.json next.config.js ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci --only-production
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM node:16-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy dependencies
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
# Copy all files
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENV NODE_ENV production
|
||||||
|
ENV NEXT_PUBLIC_ENV production
|
||||||
|
ARG POSTHOG_HOST
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_HOST $POSTHOG_HOST
|
||||||
|
ARG POSTHOG_API_KEY
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_API_KEY $POSTHOG_API_KEY
|
||||||
|
|
||||||
|
# Build
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
|
# Production image
|
||||||
|
FROM node:16-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
RUN mkdir -p /app/.next/cache/images && chown nextjs:nodejs /app/.next/cache/images
|
||||||
|
VOLUME /app/.next/cache/images
|
||||||
|
|
||||||
|
ARG POSTHOG_API_KEY
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY \
|
||||||
|
BAKED_NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY
|
||||||
|
|
||||||
|
COPY --chown=nextjs:nodejs --chmod=555 scripts ./scripts
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
RUN chown nextjs:nodejs ./public/data
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV PORT 3000
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["/app/scripts/start.sh"]
|
||||||
@@ -4,12 +4,11 @@ import {
|
|||||||
ENV,
|
ENV,
|
||||||
POSTHOG_API_KEY,
|
POSTHOG_API_KEY,
|
||||||
POSTHOG_HOST,
|
POSTHOG_HOST,
|
||||||
TELEMETRY_ENABLED,
|
|
||||||
} from "../utilities/config";
|
} from "../utilities/config";
|
||||||
|
|
||||||
export const initPostHog = () => {
|
export const initPostHog = () => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
if (ENV == "production" && TELEMETRY_ENABLED) {
|
if (ENV == "production" && TELEMETRY_CAPTURING_ENABLED) { // eslint-disable-line
|
||||||
posthog.init(POSTHOG_API_KEY, {
|
posthog.init(POSTHOG_API_KEY, {
|
||||||
api_host: POSTHOG_HOST,
|
api_host: POSTHOG_HOST,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import login2 from "~/pages/api/auth/Login2";
|
|||||||
import getOrganizations from "~/pages/api/organization/getOrgs";
|
import getOrganizations from "~/pages/api/organization/getOrgs";
|
||||||
import getOrganizationUserProjects from "~/pages/api/organization/GetOrgUserProjects";
|
import getOrganizationUserProjects from "~/pages/api/organization/GetOrgUserProjects";
|
||||||
|
|
||||||
import { initPostHog } from "../analytics/posthog";
|
|
||||||
import pushKeys from "./secrets/pushKeys";
|
import pushKeys from "./secrets/pushKeys";
|
||||||
import { ENV } from "./config";
|
|
||||||
import { saveTokenToLocalStorage } from "./saveTokenToLocalStorage";
|
import { saveTokenToLocalStorage } from "./saveTokenToLocalStorage";
|
||||||
import SecurityClient from "./SecurityClient";
|
import SecurityClient from "./SecurityClient";
|
||||||
|
import Telemetry from "./telemetry/Telemetry";
|
||||||
|
|
||||||
const nacl = require("tweetnacl");
|
const nacl = require("tweetnacl");
|
||||||
nacl.util = require("tweetnacl-util");
|
nacl.util = require("tweetnacl-util");
|
||||||
@@ -33,6 +32,8 @@ const attemptLogin = async (
|
|||||||
isLogin
|
isLogin
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
const telemetry = new Telemetry().getInstance();
|
||||||
|
|
||||||
client.init(
|
client.init(
|
||||||
{
|
{
|
||||||
username: email,
|
username: email,
|
||||||
@@ -125,16 +126,9 @@ const attemptLogin = async (
|
|||||||
env: "Development",
|
env: "Development",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
try {
|
if (email) {
|
||||||
if (email) {
|
telemetry.identify(email);
|
||||||
if (ENV == "production") {
|
telemetry.capture("User Logged In");
|
||||||
const posthog = initPostHog();
|
|
||||||
posthog.identify(email);
|
|
||||||
posthog.capture("User Logged In");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log("posthog", error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogin) {
|
if (isLogin) {
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const POSTHOG_HOST =
|
|||||||
process.env.NEXT_PUBLIC_POSTHOG_HOST! || "https://app.posthog.com";
|
process.env.NEXT_PUBLIC_POSTHOG_HOST! || "https://app.posthog.com";
|
||||||
const STRIPE_PRODUCT_PRO = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_PRO!;
|
const STRIPE_PRODUCT_PRO = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_PRO!;
|
||||||
const STRIPE_PRODUCT_STARTER = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER!;
|
const STRIPE_PRODUCT_STARTER = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER!;
|
||||||
const TELEMETRY_ENABLED =
|
|
||||||
process.env.NEXT_PUBLIC_TELEMETRY_ENABLED! !== "false";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ENV,
|
ENV,
|
||||||
@@ -13,5 +11,4 @@ export {
|
|||||||
POSTHOG_HOST,
|
POSTHOG_HOST,
|
||||||
STRIPE_PRODUCT_PRO,
|
STRIPE_PRODUCT_PRO,
|
||||||
STRIPE_PRODUCT_STARTER,
|
STRIPE_PRODUCT_STARTER,
|
||||||
TELEMETRY_ENABLED,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
import { initPostHog } from "~/components/analytics/posthog";
|
||||||
|
import { ENV } from "~/components/utilities/config";
|
||||||
|
|
||||||
|
class Capturer {
|
||||||
|
constructor() {
|
||||||
|
this.api = initPostHog();
|
||||||
|
}
|
||||||
|
|
||||||
|
capture(item) {
|
||||||
|
if (ENV == "production" && TELEMETRY_CAPTURING_ENABLED) {
|
||||||
|
try {
|
||||||
|
api.capture(item);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("PostHog", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identify(id) {
|
||||||
|
if (ENV == "production" && TELEMETRY_CAPTURING_ENABLED) {
|
||||||
|
try {
|
||||||
|
api.identify(id);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("PostHog", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Telemetry {
|
||||||
|
constructor() {
|
||||||
|
if (!Telemetry.instance) {
|
||||||
|
Telemetry.instance = new Capturer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getInstance() {
|
||||||
|
return Telemetry.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Telemetry;
|
||||||
@@ -2,12 +2,11 @@ import { useEffect } from "react";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { config } from "@fortawesome/fontawesome-svg-core";
|
import { config } from "@fortawesome/fontawesome-svg-core";
|
||||||
|
|
||||||
import { initPostHog } from "~/components/analytics/posthog";
|
|
||||||
import Layout from "~/components/basic/layout";
|
import Layout from "~/components/basic/layout";
|
||||||
import NotificationProvider from "~/components/context/Notifications/NotificationProvider";
|
import NotificationProvider from "~/components/context/Notifications/NotificationProvider";
|
||||||
import RouteGuard from "~/components/RouteGuard";
|
import RouteGuard from "~/components/RouteGuard";
|
||||||
import { publicPaths } from "~/const";
|
import { publicPaths } from "~/const";
|
||||||
import { ENV } from "~/utilities/config";
|
import Telemetry from "~/utilities/telemetry/Telemetry";
|
||||||
|
|
||||||
import "@fortawesome/fontawesome-svg-core/styles.css";
|
import "@fortawesome/fontawesome-svg-core/styles.css";
|
||||||
import "../styles/globals.css";
|
import "../styles/globals.css";
|
||||||
@@ -16,17 +15,14 @@ config.autoAddCss = false;
|
|||||||
|
|
||||||
const App = ({ Component, pageProps, ...appProps }) => {
|
const App = ({ Component, pageProps, ...appProps }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const posthog = initPostHog();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Init for auto capturing
|
// Init for auto capturing
|
||||||
const posthog = initPostHog();
|
const telemetry = new Telemetry().getInstance();
|
||||||
|
|
||||||
const handleRouteChange = () => {
|
const handleRouteChange = () => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
if (ENV == "production") {
|
telemetry.capture("$pageview");
|
||||||
posthog.capture("$pageview");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
ORIGINAL=$1
|
||||||
|
REPLACEMENT=$2
|
||||||
|
|
||||||
|
if [ "${ORIGINAL}" = "${REPLACEMENT}" ]; then
|
||||||
|
echo "Environment variable replacement is the same, skipping.."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Replacing pre-baked value.."
|
||||||
|
|
||||||
|
find /app/public /app/.next -type f -name "*.js" |
|
||||||
|
while read file; do
|
||||||
|
sed -i "s|$ORIGINAL|$REPLACEMENT|g" "$file"
|
||||||
|
done
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
VALUE=$1
|
||||||
|
|
||||||
|
find /app/public /app/.next -type f -name "*.js" |
|
||||||
|
while read file; do
|
||||||
|
sed -i "s|TELEMETRY_CAPTURING_ENABLED|$VALUE|g" "$file"
|
||||||
|
done
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
scripts/replace-variable.sh "$BAKED_NEXT_PUBLIC_POSTHOG_API_KEY" "$NEXT_PUBLIC_POSTHOG_API_KEY"
|
||||||
|
|
||||||
|
if [ "$INFISICAL_TELEMETRY_ENABLED" != "false" ]; then
|
||||||
|
echo "Telemetry is enabled"
|
||||||
|
scripts/set-telemetry.sh true
|
||||||
|
else
|
||||||
|
echo "Client opted out of telemetry"
|
||||||
|
scripts/set-telemetry.sh false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
node server.js
|
||||||
Reference in New Issue
Block a user