Skip to content

Commit

Permalink
Add docs for PM2 integration, update Docker/Docker-Compose integratio…
Browse files Browse the repository at this point in the history
…n docs
  • Loading branch information
dangtony98 committed Feb 3, 2023
1 parent a94cd8c commit 76d0127
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/integrations/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Missing an integration? Throw in a [request](https://github.com/Infisical/infisi
| [Docker](/integrations/platforms/docker) | Platform | Available |
| [Docker-Compose](/integrations/platforms/docker-compose) | Platform | Available |
| [Kubernetes](/integrations/platforms/kubernetes) | Platform | Available |
| [PM2](/integrations/platforms/pm2) | Platform | Available |
| [Heroku](/integrations/cloud/heroku) | Cloud | Available |
| [Vercel](/integrations/cloud/vercel) | Cloud | Available |
| [Netlify](/integrations/cloud/netlify) | Cloud | Available |
Expand Down
31 changes: 12 additions & 19 deletions docs/integrations/platforms/docker-compose.mdx
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
---
title: "Docker Compose"
description: "How to use Infisical to inject environment variables into container defined in your Docker Compose file."
description: "How to use Infisical to inject environment variables into services defined in your Docker Compose file."
---

The Docker Compose integration enables you to inject environment variables from Infisical into the containers defined in your compose file.
Prerequisites:

## Add the CLI to your Dockerfile(s) start command
- Set up and add envars to [Infisical Cloud](https://app.infisical.com)

Follow the [guide to configure Infisical CLI](./docker) in your your Dockerfile first.
## Configure the Infisical CLI for each service

## Generate Infisical Token
Follow this [guide](./docker) to configure the Infisical CLI for each service that you wish to inject environment variables into; you'll have to update the Dockerfile of each service.

In order for Infisical CLI to authenticate and retrieve your project's secrets without exposing your login credentials, you must generate a Infisical Token.
To learn how, visit [Infisical Token](../../getting-started/dashboard/token). Once you have generated the token, keep it handy.
## Generate Infisical Tokens

<Info>
If you have multiple services and they do not use the same secrets, you will
have to generate a Infisical Token for each service.
</Info>
Generate a unique [Infisical Token](https://infisical.com/docs/getting-started/dashboard/token) for each service.

## Tell Docker Compose your Infisical Token
## Add Infisical Tokens to your Docker Compose file

For each service you want to inject secrets into, set an environment variable called `INFISICAL_TOKEN` equal to a helpful identifier variable.
This will ensure that you can set Infisical Tokens for multiple services.
For each service you want to inject secrets into, set an environment variable called `INFISICAL_TOKEN` equal to a unique identifier variable.

For the example below, we have set `INFISICAL_TOKEN_FOR_WEB` and `INFISICAL_TOKEN_FOR_API` as the `INFISICAL_TOKEN` for the corresponding service.
In the example below, we set `INFISICAL_TOKEN_FOR_WEB` and `INFISICAL_TOKEN_FOR_API` as the `INFISICAL_TOKEN` for the services.

```yaml
# Example Docker Compose file
services:
web:
build: .
image: auledge-frontend
container_name: auledge-frontend
image: example-service-1
environment:
- INFISICAL_TOKEN=${INFISICAL_TOKEN_FOR_WEB}

api:
build: .
image: auledge-backend
container_name: auledge-backend
image: example-service-2
environment:
- INFISICAL_TOKEN=${INFISICAL_TOKEN_FOR_API}
```
Expand Down
36 changes: 19 additions & 17 deletions docs/integrations/platforms/docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ title: "Docker"
description: "How to use Infisical to inject environment variables into a Docker container."
---

Infisical can be used in a Dockerfile to inject environment variables into a Docker container.
Prerequisites:

## Add the CLI to your Dockerfile
- Set up and add envars to [Infisical Cloud](https://app.infisical.com)

## Add the Infisical CLI to your Dockerfile

<Tabs>
<Tab title="Alpine">
Expand All @@ -32,32 +34,32 @@ Infisical can be used in a Dockerfile to inject environment variables into a Doc
</Tab>
</Tabs>

## Modify your Dockerfile start command
## Modify the start command in your Dockerfile

Starting your service with the Infisical CLI pulls your secrets from Infisical and injects them into your service.

To make your Docker container consume Infisical secrets, you can start your application with Infisical.
This will automatically pull the necessary secrets and make them available to your application as if they were natively exposed within the container.
```dockerfile
CMD ["infisical", "run", "---", "[your service start command]"]

```dockerfile
CMD ["infisical", "run", "---", "[your application start command]"]
# example with single single command
CMD ["infisical", "run", "---", "npm run start"]

# example with single single command
CMD ["infisical", "run", "---", "npm run start"]
# example with multiple commands
CMD ["infisical", "run", "--command", "npm run start && ..."]
```

# example with multiple commands
CMD ["infisical", "run", "--command", "npm run start && ..."]
```
## Generate an Infisical Token

View more options for the `run` command [here](../../cli/commands/run)
Head to your project settings in Infisical Cloud to generate an [Infisical Token](https://infisical.com/docs/getting-started/dashboard/token).

## Feed Docker your Infisical Token

The CLI looks out for an environment variable called `INFISICAL_TOKEN`. If the token is detected, the CLI will authenticate, retrieve, and inject the environment variables which the token is authorized for.

```bash
docker run --env INFISICAL_TOKEN=[token]...
```

## Generate an Infisical Token
<Info>

[Generate an Infisical Token](../../getting-started/dashboard/token) and keep it handy.
The Infisical CLI uses the detected `INFISICAL_TOKEN` environment variable to authenticate, retrieve, and inject the environment variables which the token is authorized for.

</Info>
52 changes: 52 additions & 0 deletions docs/integrations/platforms/pm2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "PM2"
description: "How to use Infisical to inject environment variables and secrets with PM2 into a Node.js app"
---

Prerequisites:

- Set up and add envars to [Infisical Cloud](https://app.infisical.com)
- [Install the CLI](/cli/overview)

## Initialize Infisical for your Node.js app

```bash
# navigate to the root of your of your project
cd /path/to/project

# then initialize infisical
infisical init
```

## Create a bash or js script

<CodeGroup>

```bash infisical-run.sh
infisical run -- npm start
```

```js infisical-run.js
const spawn = require("child_process").spawn;

const infisical = spawn("infisical", ["run", "--", "npm", "start"]);

infisical.stdout.on("data", (data) => console.log(`${data}`));
infisical.stderr.on("data", (data) => console.error(`${data}`));
```

</CodeGroup>

## Start your application as usual but with the script

<CodeGroup>

```bash infisical-run.sh
pm2 start infisical-run.sh
```

```bash infisical-run.js
pm2 start infisical-run.js
```

</CodeGroup>
3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@
"pages": [
"integrations/platforms/docker",
"integrations/platforms/docker-compose",
"integrations/platforms/kubernetes"
"integrations/platforms/kubernetes",
"integrations/platforms/pm2"
]
},
{
Expand Down

0 comments on commit 76d0127

Please sign in to comment.