Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb2bd86
add website to deployment spec
davemooreuws Jan 23, 2025
8ad5d16
add website resource type
davemooreuws Jan 23, 2025
5a5fc8b
wip aws
davemooreuws Jan 24, 2025
4ab1322
fix rewrite for nested sites
davemooreuws Jan 24, 2025
93c4d60
remove redundant code
davemooreuws Jan 24, 2025
9677b46
wip cache invalidation and output
davemooreuws Jan 29, 2025
25ad3b2
add new line
davemooreuws Jan 29, 2025
eb82ae7
apply invalidation of cache when files change
davemooreuws Jan 30, 2025
82148a5
handle 403 error responses
davemooreuws Jan 30, 2025
f6eace0
add tags and add to ssm index
davemooreuws Jan 30, 2025
33b70d3
update go mod aws
davemooreuws Feb 5, 2025
4e470c9
azure websites
davemooreuws Feb 7, 2025
172405a
add gcp not implemented
davemooreuws Feb 10, 2025
2281ee8
fix linting issues aws
davemooreuws Feb 10, 2025
7db3ea7
fix gosec issue aws
davemooreuws Feb 10, 2025
36a4bb7
add nosec g115
davemooreuws Feb 10, 2025
5a60358
aws websites prevent conflicts with other buckets
davemooreuws Feb 25, 2025
cfa8bda
add stack id to website endpoint
HomelessDinosaur Feb 25, 2025
5e733e5
add website buckets to ssm
davemooreuws Feb 25, 2025
51ce0a8
skip non regular files for upload
davemooreuws Feb 25, 2025
de59515
remove purge message
davemooreuws Feb 25, 2025
23d844c
add asset source to website proto
davemooreuws Feb 26, 2025
863106a
use s3 client head object to find existing etag
davemooreuws Feb 26, 2025
06a84a8
fmt
davemooreuws Feb 26, 2025
61d4709
update website proto to replace output directory
davemooreuws Feb 26, 2025
5b655c8
update go mod
davemooreuws Feb 27, 2025
ec10d1b
remove nested applyt in website aws
davemooreuws Feb 27, 2025
9c645b8
remove websites from resource index
davemooreuws Feb 27, 2025
bde8f98
refactor appyt nesting in azure websites
davemooreuws Feb 27, 2025
4db6342
feedback changes
davemooreuws Feb 27, 2025
21e1bcc
refactor to use loop determinism
davemooreuws Feb 28, 2025
2a33e77
feedback changes to remove unnecessary pulumi.all
davemooreuws Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cloud/aws/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
resourcespb "github.com/nitrictech/nitric/core/pkg/proto/resources/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/apigatewayv2"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/batch"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/cloudfront"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/dynamodb"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecr"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/iam"
Expand Down Expand Up @@ -66,6 +67,12 @@ type NitricAwsPulumiProvider struct {

SqlDatabases map[string]*RdsDatabase

websiteBucketName string
publicWebsiteBucket *s3.Bucket
websiteChangedFileOutputs pulumi.StringArray
websiteIndexDocument string
websiteErrorDocument string

DockerProvider *docker.Provider
RegistryArgs *docker.RegistryArgs
Vpc *ec2.Vpc
Expand All @@ -92,6 +99,7 @@ type NitricAwsPulumiProvider struct {
Secrets map[string]*secretsmanager.Secret
Buckets map[string]*s3.Bucket
BucketNotifications map[string]*s3.BucketNotification
Distribution *cloudfront.Distribution
Topics map[string]*topic
Queues map[string]*sqs.Queue
Websockets map[string]*apigatewayv2.Api
Expand Down Expand Up @@ -228,6 +236,20 @@ func (a *NitricAwsPulumiProvider) Pre(ctx *pulumi.Context, resources []*pulumix.
}
}

websites := lo.Filter(resources, func(item *pulumix.NitricPulumiResource[any], idx int) bool {
return item.Id.Type == resourcespb.ResourceType_Website
})

if len(websites) > 0 {
// ensure name is unique for no conflicting bucket names
a.websiteBucketName = fmt.Sprintf("website-bucket-%s", a.StackId)

err := a.createWebsiteBucket(ctx)
if err != nil {
return err
}
}

return err
}

Expand All @@ -237,6 +259,13 @@ func (a *NitricAwsPulumiProvider) Post(ctx *pulumi.Context) error {
return err
}

if a.publicWebsiteBucket != nil {
err = a.deployCloudfrontDistribution(ctx)
if err != nil {
return err
}
}

return a.resourcesStore(ctx)
}

Expand All @@ -260,6 +289,14 @@ func (a *NitricAwsPulumiProvider) Result(ctx *pulumi.Context) (pulumi.StringOutp
}
}

if a.Distribution != nil {
if len(outputs) > 0 {
outputs = append(outputs, "\n")
}
outputs = append(outputs, pulumi.Sprintf("CDN:\n──────────────"))
outputs = append(outputs, pulumi.Sprintf("https://%s", a.Distribution.DomainName))
}

// Add HTTP Proxy outputs
if len(a.HttpProxies) > 0 {
if len(outputs) > 0 {
Expand Down
7 changes: 7 additions & 0 deletions cloud/aws/deploy/embeds/api-url-rewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function handler(event) {
var request = event.request;
var uri = request.uri;
// Strip off the "/{api-type}/{name}" part of the path
request.uri = uri.replace(/^\/[^\/]+\/[^\/]+/, "");
return request;
}
35 changes: 35 additions & 0 deletions cloud/aws/deploy/embeds/cloudfront.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 Nitric Technologies Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package embeds

import (
_ "embed"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

//go:embed api-url-rewrite.js
var cloudfront_ApiUrlRewriteFunction string

//go:embed url-rewrite.js
var cloudfront_UrlRewriteFunctionName string

func GetApiUrlRewriteFunction() pulumi.StringInput {
return pulumi.String(cloudfront_ApiUrlRewriteFunction)
}

func GetUrlRewriteFunction() pulumi.StringInput {
return pulumi.String(cloudfront_UrlRewriteFunctionName)
}
15 changes: 15 additions & 0 deletions cloud/aws/deploy/embeds/url-rewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function handler(event) {
var request = event.request;
var uri = request.uri;

// If the URI has no extension and doesn't end with a trailing slash, append '/index.html'
if (!uri.includes(".") && !uri.endsWith("/")) {
request.uri = uri + "/index.html";
}
// If the URI ends with a trailing slash, replace it with '/index.html'
else if (uri.endsWith("/")) {
request.uri = uri.replace(/\/$/, "/index.html");
}

return request;
}
Loading
Loading