@kirschbaum-development/sst-laravel 0.2.12 → 0.2.14

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/laravel-sst.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  Output,
11
11
  all,
12
12
  output,
13
+ runtime,
13
14
  } from '@pulumi/pulumi';
14
15
  import { Input } from '../../../.sst/platform/src/components/input.js';
15
16
  import { ClusterArgs } from '../../../.sst/platform/src/components/aws/cluster.js';
@@ -304,6 +305,20 @@ export class LaravelService extends Component {
304
305
  const environmentFileDependency = prepareEnvironmentFile();
305
306
  prepareDeploymentScript();
306
307
 
308
+ const addEnvironmentFileImageDependency = (
309
+ _args: unknown,
310
+ opts: $util.CustomResourceOptions,
311
+ _name: string,
312
+ ) => {
313
+ if (!environmentFileDependency) {
314
+ return undefined;
315
+ }
316
+
317
+ opts.dependsOn = [environmentFileDependency];
318
+
319
+ return undefined;
320
+ };
321
+
307
322
  const cluster = new sst.aws.Cluster(`${name}-Cluster`, {
308
323
  vpc: normalizeClusterVpc(args.vpc),
309
324
  });
@@ -338,6 +353,7 @@ export class LaravelService extends Component {
338
353
  },
339
354
 
340
355
  transform: {
356
+ image: addEnvironmentFileImageDependency,
341
357
  taskDefinition: (args) => {
342
358
  args.containerDefinitions = (
343
359
  args.containerDefinitions as $util.Output<string>
@@ -451,6 +467,7 @@ export class LaravelService extends Component {
451
467
  },
452
468
 
453
469
  transform: {
470
+ image: addEnvironmentFileImageDependency,
454
471
  taskDefinition: (args) => {
455
472
  args.containerDefinitions = (
456
473
  args.containerDefinitions as $util.Output<string>
@@ -564,33 +581,33 @@ export class LaravelService extends Component {
564
581
  let filePath = path.join(context, `${dockerfile}.dockerignore`);
565
582
  if (fs.existsSync(filePath)) return filePath;
566
583
 
567
- filePath = path.join(context, '.dockerignore');
568
- if (fs.existsSync(filePath)) return filePath;
584
+ return path.join(context, '.dockerignore');
569
585
  })();
570
586
 
571
- const content = dockerIgnore
587
+ const content = fs.existsSync(dockerIgnore)
572
588
  ? fs.readFileSync(dockerIgnore).toString()
573
589
  : '';
574
590
 
575
591
  const lines = content.split('\n');
576
592
 
577
- // SST adds it later, so we need to add it here to ensure .sst/laravel is after it and is not ignored
578
- if (dockerIgnore) {
579
- if (!lines.find((line) => line === '.sst')) {
580
- fs.writeFileSync(
581
- dockerIgnore,
582
- [...lines, '', '# sst', '!.sst/laravel'].join('\n'),
583
- );
584
- }
585
-
586
- if (!lines.find((line) => line === '!.sst/laravel')) {
587
- fs.writeFileSync(
588
- dockerIgnore,
589
- [...lines, '', '# sst-laravel', '!.sst/laravel'].join(
590
- '\n',
591
- ),
592
- );
593
- }
593
+ const normalizedLines = [
594
+ ...lines.filter(
595
+ (line) =>
596
+ line !== '.sst' &&
597
+ line !== '!.sst/laravel' &&
598
+ line !== '# sst' &&
599
+ line !== '# sst-laravel',
600
+ ),
601
+ '',
602
+ '# sst',
603
+ '.sst',
604
+ '',
605
+ '# sst-laravel',
606
+ '!.sst/laravel',
607
+ ];
608
+
609
+ if (normalizedLines.join('\n') !== lines.join('\n')) {
610
+ fs.writeFileSync(dockerIgnore, normalizedLines.join('\n'));
594
611
  }
595
612
 
596
613
  return img;
@@ -747,14 +764,12 @@ export class LaravelService extends Component {
747
764
  }
748
765
 
749
766
  function prepareRemoteEnvironmentFile(secrets: RemoteEnvVault) {
750
- fs.writeFileSync(
751
- envFilePath,
752
- '# WARNING: RemoteEnvVault secrets are loaded during deployment. Preview uses a placeholder file.\n',
753
- );
754
- fs.chmodSync(envFilePath, 0o755);
755
-
756
- if ($cli.command !== 'deploy') {
757
- return;
767
+ if (runtime.isDryRun() && !fs.existsSync(envFilePath)) {
768
+ fs.writeFileSync(
769
+ envFilePath,
770
+ '# WARNING: RemoteEnvVault secrets are loaded during deployment. Preview uses a placeholder file.\n',
771
+ );
772
+ fs.chmodSync(envFilePath, 0o755);
758
773
  }
759
774
 
760
775
  const { linkedEnvironment, linkedSecrets } =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirschbaum-development/sst-laravel",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
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",
@@ -40,7 +40,9 @@ const provider: dynamic.ResourceProvider<ResolvedRemoteEnvFileInputs, ResolvedRe
40
40
 
41
41
  async diff(_, olds, news) {
42
42
  return {
43
- changes: stableStringify(olds) !== stableStringify(news),
43
+ changes:
44
+ stableStringify(olds) !== stableStringify(news) ||
45
+ !(await matchesEnvironmentFile(news)),
44
46
  };
45
47
  },
46
48
 
@@ -83,6 +85,25 @@ async function writeRemoteEnvironmentFile(inputs: ResolvedRemoteEnvFileInputs) {
83
85
  };
84
86
  }
85
87
 
88
+ async function matchesEnvironmentFile(inputs: ResolvedRemoteEnvFileInputs) {
89
+ const fs = await import('node:fs');
90
+
91
+ if (!fs.existsSync(inputs.envFilePath)) {
92
+ return false;
93
+ }
94
+
95
+ const secrets = await pullSecretsFromAws(inputs.secretPath);
96
+
97
+ if (!secrets) {
98
+ return false;
99
+ }
100
+
101
+ const expected = buildEnvFileContent(secrets, inputs) + '\n';
102
+ const actual = fs.readFileSync(inputs.envFilePath, 'utf8');
103
+
104
+ return actual === expected;
105
+ }
106
+
86
107
  async function pullSecretsFromAws(secretPath: string): Promise<Record<string, string> | null> {
87
108
  const secretValue = await getSecretValue(secretPath);
88
109