@kirschbaum-development/sst-laravel 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -137,6 +137,8 @@ There are multiple ways to configure environment variables. If you want SST Lara
137
137
 
138
138
  The below configuration would copy a file named `.env.$STAGE` (e.g. `.env.production`) into the deployment containers as your `.env` file.
139
139
 
140
+ ### Environment File
141
+
140
142
  ```js
141
143
  const app = new LaravelService('MyLaravelApp', {
142
144
  // ...
@@ -161,6 +163,21 @@ const app = new LaravelService('MyLaravelApp', {
161
163
  });
162
164
  ```
163
165
 
166
+ ### SST Secrets
167
+
168
+ You can also use SST Secrets to store your environment variables. This is a more secure way to store your environment variables.
169
+
170
+ ```js
171
+ const APP_KEY = new sst.Secret("APP_KEY");
172
+ const DB_PASSWORD = new sst.Secret("DB_PASSWORD");
173
+
174
+ const app = new LaravelService('MyLaravelApp', {
175
+ link: [APP_KEY, DB_PASSWORD],
176
+ });
177
+ ```
178
+
179
+ This will automatically inject the environment variables into the `.env` file of your Laravel application. Read more about SST Secrets [here](https://sst.dev/docs/component/secret/).
180
+
164
181
  ### Resources
165
182
 
166
183
  In SST, you can [link resources](https://sst.dev/docs/linking). If you link resources to your Laravel component, SST Laravel will automatically inject and configure environment variables using sensible defaults for all the linked resources.
@@ -345,11 +362,20 @@ In case you get the following error when running SST commands, run `npx sst-lara
345
362
  - node_modules/@kirschbaum-development/sst-laravel/laravel-sst.ts:6:26 Could not resolve "../../../.sst/platform/src/components/component.js"
346
363
  ```
347
364
 
365
+ **CD: AWS credentials are not configured**
366
+
367
+ If you are getting the following error when deploying (usually via CI/CD), the issue is usually that you have a `.env` or `.env.{stage}` that contains the `AWS_ACCESS_KEY_ID` and
368
+ `AWS_SECRET_ACCESS_KEY` keys. They should be removed from the environment file and you should be relying on the IAM role to give your app permissions to access AWS resources (which is more secure anyway).
369
+
370
+ ```
371
+ ✕ AWS credentials are not configured. Try configuring your profile in `~/.aws/config` and setting the `AWS_PROFILE` environment variable or specifying `providers.aws.profile` in your sst.config.ts
372
+ aws: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, failed to get API token, operation error ec2imds: getToken, http response error StatusCode: 400, request to EC2 IMDS failed
373
+ ```
374
+
348
375
  ***
349
376
 
350
377
  ### Roadmap
351
378
 
352
- * Support for [SST Secrets](https://sst.dev/docs/component/secret/);
353
379
  * Extend base Docker images;
354
380
  * Add support for Inertia SSR;
355
381
  * Add support for Octane with FrankedPHP;
package/laravel-sst.ts CHANGED
@@ -9,7 +9,7 @@ import { Input } from "../../../.sst/platform/src/components/input.js";
9
9
  import { ClusterArgs } from "../../../.sst/platform/src/components/aws/cluster.js";
10
10
  import { ServiceArgs } from "../../../.sst/platform/src/components/aws/service.js";
11
11
  import { Dns } from "../../../.sst/platform/src/components/dns.js";
12
- import { applyLinkedResourcesEnv, EnvCallback, EnvCallbacks } from "./src/laravel-env";
12
+ import { applyLinkedResourcesEnv, EnvCallback, EnvCallbacks, extractSecrets } from "./src/laravel-env";
13
13
 
14
14
  // duplicate from cluster.ts
15
15
  type Port = `${number}/${"http" | "https" | "tcp" | "udp" | "tcp_udp" | "tls"}`;
@@ -516,6 +516,13 @@ export class LaravelService extends Component {
516
516
  fs.appendFileSync(envFilePath, '\n' + envContent);
517
517
  }
518
518
  });
519
+
520
+ const secrets = extractSecrets(resources);
521
+ secrets.forEach(secret => {
522
+ all([secret.name, secret.value]).apply(([name, value]) => {
523
+ fs.appendFileSync(envFilePath, `\n${name}=${value}`);
524
+ });
525
+ });
519
526
  };
520
527
 
521
528
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirschbaum-development/sst-laravel",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "An unofficial extension of SST to deploy containerized Laravel applications to AWS Fargate.",
6
6
  "main": "laravel-sst.ts",
@@ -7,10 +7,11 @@ import * as pulumiAws from "@pulumi/aws";
7
7
  import { Queue } from "../../../../.sst/platform/src/components/aws/queue.js";
8
8
  import { Aurora } from "../../../../.sst/platform/src/components/aws/aurora.js";
9
9
  import { Bucket } from "../../../../.sst/platform/src/components/aws/bucket.js";
10
+ import { Secret } from "../../../../.sst/platform/src/components/secret.js";
10
11
 
11
12
  type EnvType = Record<string, string | Output<string>>|Record<string, string | Output<string | undefined> | undefined>;
12
13
  type Database = Postgres | Mysql | Aurora | pulumiAws.rds.Instance;
13
- type LinkSupportedTypes = Database | Email | Queue | Redis | Bucket;
14
+ type LinkSupportedTypes = Database | Email | Queue | Redis | Bucket | Secret;
14
15
 
15
16
  export type EnvCallback = (resource: any) => EnvType;
16
17
  export type EnvCallbacks = {
@@ -73,11 +74,16 @@ export function applyLinkedResourcesEnv(links: LinkSupportedTypes[], callbacks?:
73
74
  ...defaultEnv,
74
75
  };
75
76
  }
77
+
76
78
  });
77
79
 
78
80
  return environment;
79
81
  }
80
82
 
83
+ export function extractSecrets(links: LinkSupportedTypes[]): Secret[] {
84
+ return links.filter((link): link is Secret => link instanceof Secret);
85
+ }
86
+
81
87
  function applyDatabaseEnv(database: Database, callbacks?: EnvCallbacks): EnvType {
82
88
  let port: number | undefined;
83
89
  database.port.apply(value => port = value);